pyomo

How to save (pickle) a model instance in pyomo

纵饮孤独 提交于 2019-11-30 06:09:44
问题 I want to create a model instance and then save it so I can load and solve at a later time (the initialization takes quite long compared to the solving). When I tried this it gave me the following error. with open('model.pickle', 'w') as f: pickle.dump(instance, f) AttributeError: Can't pickle local object 'Euphemia. init ..obj_expression The objective function is this: def obj_expression(model): curve = sum(model.x[area, hour, Type, index] * model.Q[area, hour, Type, index] * ( model.P1[area

How to save (pickle) a model instance in pyomo

爱⌒轻易说出口 提交于 2019-11-29 17:01:26
I want to create a model instance and then save it so I can load and solve at a later time (the initialization takes quite long compared to the solving). When I tried this it gave me the following error. with open('model.pickle', 'w') as f: pickle.dump(instance, f) AttributeError: Can't pickle local object 'Euphemia. init ..obj_expression The objective function is this: def obj_expression(model): curve = sum(model.x[area, hour, Type, index] * model.Q[area, hour, Type, index] * ( model.P1[area, hour, Type, index] + model.P0[area, hour, Type, index] ) / 2 for (area, hour, Type, index) in model

Pyomo: Access Solution From Python Code

折月煮酒 提交于 2019-11-29 15:52:29
问题 I have a linear integer programme I want to solve. I installed solver glpk (thanks to this answer) and pyomo. I wrote code like this: from pyomo.environ import * from pyomo.opt import SolverFactory a = 370 b = 420 c = 2 model = ConcreteModel() model.x = Var([1,2], domain=NonNegativeIntegers) model.Objective = Objective(expr = a * model.x[1] + b * model.x[2], sense=minimize) model.Constraint1 = Constraint(expr = model.x[1] + model.x[2] == c) # ... more constraints opt = SolverFactory('glpk')

Finding out reason of Pyomo model infeasibility

泪湿孤枕 提交于 2019-11-29 12:56:20
I got a pyomo concrete model with lots of variables and constraints. Somehow, one of the variable inside my model violates one constraint, which makes my model infeasible: WARNING: Loading a SolverResults object with a warning status into model=xxxx; message from solver=Model was proven to be infeasible. Is there a way to ask the solver, the reason of the infeasibility? So for example, lets assume I got a variable called x , and if I define following 2 constraints, model will be ofc. infeasible. const1: x >= 10 const2: x <= 5 And what I want to achieve that pointing out the constraints and

In pyomo how can one extract the second derivative from the objective function

Deadly 提交于 2019-11-28 14:28:44
I'm working with pyomo and already have a model defined, with an objective function to go with it. After the model is solved, the objective function has certain parameters attached to it. So if i had a multi index variable [x1, x2, x3] , my quadratic objective function would suppose look something like this: (x1^2 + 13*x2^2 + 10*x3^2) + (2*x1 +......) . My question is: given that i can actually access this expression in string format from the objective, is there any way to obtain the second derivative of this function with respect to all the variables? There are two ways to get derivative

Finding out reason of Pyomo model infeasibility

谁说我不能喝 提交于 2019-11-28 06:46:30
问题 I got a pyomo concrete model with lots of variables and constraints. Somehow, one of the variable inside my model violates one constraint, which makes my model infeasible: WARNING: Loading a SolverResults object with a warning status into model=xxxx; message from solver=Model was proven to be infeasible. Is there a way to ask the solver, the reason of the infeasibility? So for example, lets assume I got a variable called x , and if I define following 2 constraints, model will be ofc.

In pyomo how can one extract the second derivative from the objective function

独自空忆成欢 提交于 2019-11-27 08:25:44
问题 I'm working with pyomo and already have a model defined, with an objective function to go with it. After the model is solved, the objective function has certain parameters attached to it. So if i had a multi index variable [x1, x2, x3] , my quadratic objective function would suppose look something like this: (x1^2 + 13*x2^2 + 10*x3^2) + (2*x1 +......) . My question is: given that i can actually access this expression in string format from the objective, is there any way to obtain the second