pyomo

AbstractModel VS ConcreteModel of pyomo? how does “opt.options[”tol“]” make the difference in finding optimal solution?

不羁岁月 提交于 2019-12-11 15:26:23
问题 I have an AbstractModel and a ConcreteModel solving the same problem, but they are performing differently. It is mainly about initial value of a variable and tolerance of ipopt. When I initialize my variable model.x as 10 and opt.options["tol"] = 1E-64: ConcreteModel can find optimal solution, while abstract model "Solved To Acceptable Level". (But the solutions they find are actually the same) When I initialize my variable model.x as 100 and opt.options["tol"] = 1E-64: ConcreteModel can find

Pyomo and conditional objective function

╄→гoц情女王★ 提交于 2019-12-11 08:08:05
问题 Is it possible (and if so how) to use an objective function that has a conditional expression? Changing the example from the docs, I would like an expression like: def objective_function(model): return model.x[0] if model.x[1] < const else model.x[2] model.Obj = Objective(rule=objective_function, sense=maximize) Can this be modelled directly like this or do I have to consider some sort of transformation (and if so how would this look like)? Just executing the above gives an error message like

Pyomo summation of a product of a matrix by a vector

安稳与你 提交于 2019-12-11 06:07:55
问题 I edit my code including all the parameters and variables involved: (D is a numpy matrix imported from Python) import pyomo from pyomo.environ import * from array import * import numpy as np import scipy as sp from diff_matrix import D ##N=10???? print(D) m =ConcreteModel() ... m.n = Param(initialize = 10, within = Integers) m.Ns = Set(initialize = range(0,value(m.n))) m.x1 = Var(m.N, domain = Reals) m.D = Param(m.N, m.N, initialize=D) m.f_x1 = Var(m.N) def f_x1_definition(model,i): return m

Using GAMS/CPLEX from Python PYOMO

心已入冬 提交于 2019-12-11 02:58:37
问题 I noticed that Pyomo 5.3 offers a GAMS solver plugin. https://github.com/Pyomo/pyomo/blob/master/pyomo/solvers/plugins/solvers/GAMS.py This is very exciting, as we have a GAMS/CPLEX license where we can use CPLEX as solver, but only via GAMS. With the new Pyomo-Gams interface, it should from my understanding be possible to formulate a problem in Pyomo, and have it translated to GAMS and solved by CPLEX. However, when I test this with the shell integration, it is very slow (40s for 30 solves

How to set Pyomo solver timeout?

戏子无情 提交于 2019-12-10 10:13:30
问题 How to set the timeout for Pyomo solve() method ? More specifically, to tell pyomo, after x seconds, return the optimal solution currently found ? 回答1: So I was able to find the answer via pyomo documentation and I thought it would be helpful to share. To set the timeout for Pyomo solve() method: solver.solve(model, timelimit=5) However this will throw pyutilib.common._exceptions.ApplicationError: "Solver (%s) did not exit normally" % self.name ) if the solver is not terminated. What I really

Finding Pyomo provided math functions

偶尔善良 提交于 2019-12-08 11:54:25
问题 In Pyomo I want to solve the following minimization problem, which matches the playback rate and timing of two audio files: import pyomo from pyomo.environ import * from pyomo.opt import SolverFactory import soundfile as sf import math import numpy #Create Model: model = ConcreteModel() #Declare Variables: model.P = Var(initialize = 1, within=PositiveReals, bounds = (0.5,2)) model.T = Var(initialize = 0, within=Reals, bounds = (-500,500)) #Objective function: def shift(data,rate,t,point): Y

Constraint that calls for the previous set member

时间秒杀一切 提交于 2019-12-08 11:33:38
问题 I have the following type of constraint: def C_rule(model,t-1): return x[t]<=y[t-1] model.C=Constraint(model.t,rule=C_rule) But set model.t elements are string type so i cannot access the previous element this way. Is there a way to do that ? 回答1: If you declare your Set to be ordered then you can do something like this: m.s = Set(initialize=['A','B','C'], ordered=True) m.v = Var(m.s) def _c_rule(m, i): if i == 'A': return Constraint.Skip return m.v[i] <= m.v[m.s.prev(i)] m.c = Constraint(m.s

pyomo seems very slow to write models

人走茶凉 提交于 2019-12-08 08:40:31
I have a pretty big model (around 5 million variables and constraints). The building time is a few minutes and the solving time is a few minutes too (with gurobi) But it takes very long to write the model (about 2 hours) This is the time if I use model.write('model.lp', io_options={'symbolic_solver_labels': True}) to be able to record it It's about the same time if I use SolverFactory and solve directly the model from pyomo here is a little sample, I understand that this model is trivial for gurobi, so I'm not comparing the solving time with the building time here, but I don't understand why

Pyomo: Save results to CSV files

若如初见. 提交于 2019-12-06 16:39:22
问题 Seeking for ways to save my Pyomo results took my 2 hours :( I need to save my optimal variable values and dual variable values after successfully solving a problem. Let's start from the optimal variables. I have three variables in my model, 120 'P' variables with 3 indices, 120 'I' variables with 3 indices and 576 'F' variables with 3 indices. Their indices are different. The following is my solve statements: solver = pyomo.opt.SolverFactory('gurobi') results = solver.solve(m, tee=True,