-2

Question: I am working on a linear programming problem using pulp in Python to model power generation constraints for multiple generators. I need to ensure the solution meets the following criteria:

  1. Demand Satisfaction: The total power generated at each time step should meet or exceed the demand.
  2. Ramp-Up and Ramp-Down Constraints: The rate of change in power generation for each generator should adhere to specified ramp-up and ramp-down limits.
  3. Absolute Difference Constraints: The absolute difference between power generation at consecutive time steps should be within specified limits.
  4. Capacity Constraints: The power generated by each generator at any time should be within its minimum and maximum capacity.

code:

def add_constraints(prob, generators, power_vars, demand):
    
    abs_diff_vars = {}
    for gen in generators:
        name = gen["name"]
        for t in range(1, len(demand)):
            abs_diff_vars[(name, t)] = pulp.LpVariable(f"abs_diff_{name}_{t}", lowBound=0)

    # Demand Satisfaction Constraints
    for t in range(len(demand)):
        prob += pulp.lpSum([power_vars[(gen["name"], t)] for gen in generators]) >= demand[t], f"Demand_Satisfaction_{t}"

    # Ramp-Up and Ramp-Down Constraints
    for t in range(1, len(demand)):
        for gen in generators:
            name = gen["name"]
            rampup = gen["rampup"]
            rampdown = gen["rampdown"]

            # Ramp-up constraint
            prob += power_vars[(name, t)] - power_vars[(name, t-1)] <= rampup, f"Ramp_Up_Constraint_{name}_{t}"

            # Ramp-down constraint
            prob += power_vars[(name, t-1)] - power_vars[(name, t)] <= rampdown, f"Ramp_Down_Constraint_{name}_{t}"
        
            # Absolute Difference Constraints
            prob += abs_diff_vars[(name, t)] >= (power_vars[(name, t)] - power_vars[(name, t-1)]), f"Abs_Diff_Upper_{name}_{t}"
            prob += abs_diff_vars[(name, t)] >= (power_vars[(name, t-1)] - power_vars[(name, t)]), f"Abs_Diff_Lower_{name}_{t}"

    # Capacity Constraints
    for t in range(len(demand)):
        for gen in generators:
            name = gen["name"]
            max_power = gen["max"][t]
            min_power = gen["tech_min"][t]
            
            # Max Power Constraint
            prob += power_vars[(name, t)] <= max_power, f"Max_Power_{name}_{t}"

            # Min Power Constraint
            prob += power_vars[(name, t)] >= min_power, f"Min_Power_{name}_{t}"
Inputs:
Demand - 
[
  17116.3, 16940.71, 16948.98, 16839.5, 16808.51, 16800.25,
16782.69, 16768.23, 16762.03, 16559.6, 16566.83, 16583.35,
16357.16, 16340.63, 16342.7, 16121.67, 16250.77, 16479.03,
16721.75, 17053.29, 17425.12, 17859.95, 18199.75, 18375.34,
18425.95, 18440.4, 18453.83, 18461.06, 18764.72, 18746.13,
18648.01, 18786.41, 18678.99, 18636.65, 18827.72, 18818.43,
19127.25, 19337.95, 19317.29, 19294.57, 19243.96, 19224.33,
19229.5, 19254.29, 19225.37, 19146.87, 19002.27, 18857.67,
18675.89, 18712.04, 18732.7, 18582.94, 18465.19, 18114.03,
18125.39, 18194.59, 18249.33, 18276.18, 18274.12, 18015.91,
18042.76, 18089.24, 18456.93, 18492.05, 18510.64, 18197.69,
18192.52, 18191.49, 18193.56, 18255.53, 18317.5, 18548.85,
18781.24, 19061.14, 19222.27, 19378.23, 19523.86, 19711.84,
19824.42, 19614.75, 19239.83, 18839.08, 18714.11, 18619.09,
18526.13, 18373.27, 18215.24, 18119.19, 18089.24, 18076.84,
18007.64, 17849.62, 17693.66, 17604.83, 17572.82, 17579.01]

Generator - 
[
{
        "cn_unit_source": "INTER",
        "cn_dispatch_type": "MERIT",
        "variable_charges": 1.6921,
        "rampup": 40.0,
        "rampdown": 40.0,
        "tech_min": [0.0,0.0,0.0,0.0,0.0,0.0,
                     0.0,0.0,0.0,0.0,0.0,0.0,
                     0.0,0.0,0.0,0.0,0.0,0.0,
                     0.0,0.0,0.0,0.0,0.0,0.0,
                     0.0,0.0,0.0,0.0,0.0,0.0,
                     0.0,0.0,0.0,0.0,0.0,0.0,
                     0.0,0.0,0.0,0.0,0.0,0.0,
                     0.0,0.0,0.0,0.0,0.0,0.0,
                     0.0,0.0,0.0,0.0,0.0,0.0,
                     0.0,0.0,0.0,0.0,0.0,0.0,
                     0.0,0.0,0.0,0.0,0.0,0.0,
                     0.0,0.0,0.0,0.0,0.0,0.0,
                     0.0,0.0,0.0,0.0,0.0,0.0,
                     0.0,0.0,0.0,0.0,0.0,0.0,
                     0.0,0.0,0.0,0.0,0.0,0.0,
                     0.0,0.0,0.0,0.0,0.0,0.0,],
        "name": "KSTPS7_22799688",
        "max": [0.0,0.0,0.0,0.0,0.0,0.0,
                0.0,0.0,0.0,0.0,0.0,0.0,
                0.0,0.0,0.0,0.0,0.0,0.0,
                0.0,0.0,0.0,0.0,0.0,0.0,
                0.0,0.0,0.0,0.0,0.0,0.0,
                0.0,0.0,0.0,0.0,0.0,0.0,
                0.0,0.0,0.0,0.0,0.0,0.0,
                0.0,0.0,0.0,0.0,0.0,0.0,
                0.0,0.0,0.0,0.0,0.0,0.0,
                0.0,0.0,0.0,0.0,0.0,0.0,
                0.0,0.0,0.0,0.0,0.0,0.0,
                0.0,0.0,0.0,0.0,0.0,0.0,
                0.0,0.0,0.0,0.0,0.0,0.0,
                0.0,0.0,0.0,0.0,0.0,0.0,
                0.0,0.0,0.0,0.0,0.0,0.0,
                0.0,0.0,0.0,0.0,0.0,0.0]
    }, ]
3
  • This is unreadable. Commented Jul 31, 2024 at 6:54
  • So, what is the question? Commented Aug 2, 2024 at 14:24
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. Commented Aug 4, 2024 at 6:36

1 Answer 1

0

The constraints seem to be well implemented. However, in the data you provided, max=min=0, so the generation would naturally be 0 and the demand would not be fulfilled.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.