pyomo

Performance of pyomo to generate a model with a huge number of constraints

限于喜欢 提交于 2020-01-13 09:38:09
问题 I am interested in the performance of Pyomo to generate an OR model with a huge number of constraints and variables (about 10e6). I am currently using GAMS to launch the optimizations but I would like to use the different python features and therefore use Pyomo to generate the model. I made some tests and apparently when I write a model, the python methods used to define the constraints are called each time the constraint is instanciated. Before going further in my implementation, I would

Create a variable with sparse index in pyomo

空扰寡人 提交于 2020-01-06 08:50:00
问题 I need help to create a variable with sparse indices. I have something like this: model.K = Set() model.P = Set() model.KP = Param(model.K, model.P, default=0) I will load a CSV file for model.KP with value KP==1 for the combinations of K & P. model.X = Var(model.K, model.P) I want to create this variable only for the combinations of K and P in the model.KP because when I create the variable with all the combinations of K and P, it is producing 37 million indices with the sets I give and this

Pyomo: When using python script, are there any quick ways to show the Objective value after solving the ILP?

寵の児 提交于 2020-01-04 07:09:58
问题 I finished an ILP before and it works properly. opt = SolverFactory('glpk') model = AbstractModel() model.obj = Objective(...) # variables, constraints ... instance = model.create_instance() results = opt.solve(instance) since I want to get the value of each variable but also the objective function solved, I try to access the Objective function by the way similar as what I did to the variable but all I can get is an expression. I use the following code: print(instance.obj.value) But only got

Retrieving Pyomo solution without using for loop

亡梦爱人 提交于 2020-01-04 00:10:12
问题 I am struggling to find an efficient way of retrieving the solution to an optimization problem. The solution consists of around 200K variables that I would like in a pandas DataFrame. After searching online the only approaches I found for accessing the variables was through a for loop which looks something like this: instance = M.create_instance('input.dat') # reading in a datafile results = opt.solve(instance, tee=True) results.write() instance.solutions.load_from(results) for v in instance

Pyomo: constraint with if statements

孤人 提交于 2020-01-01 19:10:09
问题 I am currently trying to solve this problem. I need to maximize the profit of this company. That s the code I currently have: from pyomo.environ import * from pyomo.opt import * opt = solvers.SolverFactory("ipopt") model = ConcreteModel() model.x1 = Var(within=NonNegativeIntegers) model.x2 = Var(within=NonNegativeIntegers) model.y1 = Var(within=NonNegativeIntegers) model.y2 = Var(within=NonNegativeIntegers) model.b1 = Var(within=Boolean) model.b2 = Var(within=Boolean) model.c1 = Constraint

Importing a matrix from Python to Pyomo

好久不见. 提交于 2019-12-25 07:48:27
问题 I have a matrix defined in Python: (name of the document matrix.py) N = 4 l = N k = N D = np.zeros((l,k)) for i in range(0,l): for j in range(0,k): if (i==j): D[i,j] = 2 else: D[i,j] = 0 D[0,0] = (2*N**2+1)/6 D[-1,-1] = -(2*N**2+1)/6 print(D) I want to use it in Pyomo, and i did: import matrix . . . m.f_x1 = Var(m.N) def f_x1_definition(model,i): for j in m.N: return m.f_x1[j] ==sum(D[i,j]*m.x1[j] for j in range(value(m.n))) m.f_x1_const = Constraint(m.N, rule = f_x1_definition) But I get the

Pyomo sum inside sum with various index

孤人 提交于 2019-12-25 03:14:48
问题 I would like to do this: but I don't know exacly how, this is what I've tried: def R2(model, da, gr, cu): return sum(sum(model.Dap[asi, pe] for asi in model.A[asi, gr, cu]) for pe in model.Pd[pe, da]) <= 1 model.R2 = Constraint(model.DA, model.GR, model.CU, rule=R2) 回答1: I am not 100% I understand your mathematical formulation. Based on the way you write the constraint, it seems you have multiple Indexed Sets (i.e. sets which are themselves indexed over other sets), which is often a symptom

ERROR: Constructing component 'objective' from data=None failed: TypeError: 'float' object is not subscriptable

不问归期 提交于 2019-12-25 01:45:28
问题 Team Pyomo, I kindly need help with the above-stated error. I have done everything I could, but still can't get my model to work. Below is the formulation of my 'Objective Function', and screenshots of the errors message. Thank you. Screenshot of the error from the running code at the command prompt: 回答1: Assuming model.x and model.d are declared correctly with 2-D indices, the problem is that you are using double square brackets. The correct way to access a particular index is model.x[i,j] .

What is the best way to deal with this kind of key error in pyomo?

折月煮酒 提交于 2019-12-24 23:29:57
问题 I am working on a LP model with pyomo,but when I create constraint, it shows a key error of 'can not find a certain combination'. I know list all the combinations can solve this problem. But the real data has many combinations. Is there any easy way to deal with this knid of problem? thanks!Here is a simple example: This is a similar question for reference: Is there an easier way to avoid this kind of index key error of pyomo? from pyomo.environ import * import pandas as pd data = [['tom','A'

Is there an easier way to avoid this kind of index key error of pyomo?

筅森魡賤 提交于 2019-12-24 21:14:02
问题 I am working on a LP model with pyomo,but when I create constraint, it shows a key error of 'can not find a certain combination'. I know list all the combinations can solve this problem. But the real data has many combinations. Is there any easy way to deal with this knid of problem? thanks!Here is a simple example: from pyomo.environ import * import pandas as pd data = [['tom','A', 10], ['nick','A', 15], ['juli','B',14]] df = pd.DataFrame(data, columns = ['Name','Type', 'Age']) #set A = set