pyomo

Pyomo: Struggling to get a constraint to work

一笑奈何 提交于 2021-02-11 14:34:05
问题 I am trying to model an Electric Vehicle scheduling to minimise the electricity bill. Of course, the EV will only be able to charge every time that is plugged into a charging station (i.e. it cannnot charge when the vehicle is driving). Basically, it is a stationary battery that can be disconnected and connected again. I already managed to model a stationary battery scheduling before and is working good as I expected, however I am having a hard time setting up a constraint to connect and

How to solve for multiple solutions to linear program in Python?

笑着哭i 提交于 2021-02-10 14:25:52
问题 I have some Pyomo code (see below) which produces one possible solution to the linear equation: 3a + 2b + 2c = 15 Where: -20 <= a <= 0 0 <= b <= 20 20 <= c <= 50 a, b, c are real numbers How could I rewrite the program to produce a random solution every time it is run? I am open to using Pulp as well. My Code: # Coefficients coeffs = [3,2,2] y_target = 15 # Define model and variables model = ConcreteModel() model.a = Var(bounds=(-20,0)) model.b = Var(bounds=(0,20)) model.c = Var(bounds=(20,50

Performance of creating Pyomo constraints

只愿长相守 提交于 2021-02-10 14:13:35
问题 I am setting up a biggish energy optimization problem with pyomo. The setup took unreasonably long as mentioned in other questions, however I managed to speed up most of the problematic lines, except the energy flow constraints. Opposed to all other constraints the flow includes a sum over all elements. So I decided to rewrite the way the flow variables are created so they include an index over all elements, hoping this would improve the situation. My code now looks like this: def flows(model

Performance of creating Pyomo constraints

点点圈 提交于 2021-02-10 14:10:23
问题 I am setting up a biggish energy optimization problem with pyomo. The setup took unreasonably long as mentioned in other questions, however I managed to speed up most of the problematic lines, except the energy flow constraints. Opposed to all other constraints the flow includes a sum over all elements. So I decided to rewrite the way the flow variables are created so they include an index over all elements, hoping this would improve the situation. My code now looks like this: def flows(model

Pyomo Cannot index a component with an indexed set

空扰寡人 提交于 2021-02-10 05:14:42
问题 I have a Pyomo model that has a sparse set of values but I get the error Cannot index a component with an indexed set when I try to index a binary variable according to this sparse set. For a simplified example: model = ConcreteModel() model.S = Set([1, 4, 6]) model.V = Var(model.S, within=Binary) 回答1: The line model.S = Set([1, 4, 6]) creates an Indexed Set: that is a Set of 3 Sets, each one of which is empty (Pyomo treats positional arguments as indexing sets - just like in your comment

Pyomo Cannot index a component with an indexed set

ぐ巨炮叔叔 提交于 2021-02-10 05:14:33
问题 I have a Pyomo model that has a sparse set of values but I get the error Cannot index a component with an indexed set when I try to index a binary variable according to this sparse set. For a simplified example: model = ConcreteModel() model.S = Set([1, 4, 6]) model.V = Var(model.S, within=Binary) 回答1: The line model.S = Set([1, 4, 6]) creates an Indexed Set: that is a Set of 3 Sets, each one of which is empty (Pyomo treats positional arguments as indexing sets - just like in your comment

Pyomo Cannot index a component with an indexed set

房东的猫 提交于 2021-02-10 05:13:25
问题 I have a Pyomo model that has a sparse set of values but I get the error Cannot index a component with an indexed set when I try to index a binary variable according to this sparse set. For a simplified example: model = ConcreteModel() model.S = Set([1, 4, 6]) model.V = Var(model.S, within=Binary) 回答1: The line model.S = Set([1, 4, 6]) creates an Indexed Set: that is a Set of 3 Sets, each one of which is empty (Pyomo treats positional arguments as indexing sets - just like in your comment

Dual Variable Returns Nothing in Pyomo

拜拜、爱过 提交于 2021-01-29 10:31:41
问题 I have a question regarding to pyomo dual variable retrieval. I'm trying to retrieve the dual variable from the constraint "model.market_clearing_const". However, after running these codes folowing, the error I got is: "Component with id '2886755528520': market_clearing_const[0]" So basically if I look into the dual component under model, I see suffix=0. So this means there's no dual variables are stored in suffix despite the fact that I already declare it. And my solution is feasible. Any

Why Does Pyomo Behavior Change When Passing parameters to constraint function?

独自空忆成欢 提交于 2021-01-29 08:25:33
问题 This code works correctly. def m(model, i): return model.fd_amt[i] <= getattr(model, 'br_sa_ind')[i] * global_m setattr(model, ind+"_m",Constraint(model.br_standalone_I, rule=m)) But this def m(model, i, ind_name): return model.fd_amt[i] <= getattr(model, ind_name)[i] * global_m setattr(model, ind+"_m",Constraint(rule=m(model,model.model.br_standalone_I, 'br_sa_ind') )) results in this error: ERROR: evaluating expression: No value for uninitialized NumericValue object fd_amt[br_standalone_I]

Minimize cost based on purchased volume Pyomo

≯℡__Kan透↙ 提交于 2021-01-07 03:00:30
问题 I'd like to find the optimal solution for buying goods from suppliers where the shipping cost is dependent on the cost of goods bought from given supplier. I'm using Pyomo. My code so far is: model = ConcreteModel(name="(MN_2)") # products N = ['prod1', 'prod2', 'prod3'] # suppliers M = ['A', 'B'] # price p = {('prod1', 'A'): 10, ('prod2', 'A'): 9, ('prod3', 'A'): 50, ('prod1', 'B'): 16, ('prod2', 'B'): 20, ('prod3', 'B'): 35} # user quantity contraint q_u = {('prod1', 'A'): 2, ('prod2', 'A')