Questions tagged [pyomo]
Pyomo is a Python-based open-source software package that supports a diverse set of optimization capabilities for formulating, solving, and analyzing optimization models.
1,530
questions
-1
votes
0
answers
16
views
ValueError: Invalid constraint expression. The constraint expression resolved to a trivial Boolean (True) instead of a Pyomo object
I am using pyomo with glpk and/or gurobi to solve an optimization problem. However there is this constraint that is not always working properly. If a change the dataset it does not work anymore. I am ...
0
votes
0
answers
10
views
Pyomo: change index of variable
after a couple of months, I built up an optimization approach of a bigger energy system.
Within this, I try to change the index of pyomo variables in order to recalculate the model within a loop.
With ...
0
votes
0
answers
14
views
Unwated consistency of solver results with pyomo over several runs
I'm using pyomo 6.6.4 and several solvers (Ipopt, Bonmin, Cbc,...) to solve different relatively complicated models (MINLP in general). Since my models have known infeasibility points I am solving ...
0
votes
1
answer
23
views
How can I ensure that a variable in Pyomo either remains between boundaries or is equal to zero?
I want to solve an optimization problem using Pyomo and ensure that the decision variables are either between specified limits or equal to zero.
As a minimal example, I would like to show the ...
0
votes
0
answers
31
views
PermissionError: [Errno 13] Permission denied when trying to open an .exe file
I am trying to open an .exe file from my drive to access the executable path to solve my optimization problem but I get the [Errno 13] PermissionError: [Errno 13] Permission denied: '/content/drive/...
0
votes
1
answer
41
views
PAO.Pyomo model sets two variables x and y to be unique
The background is I am trying to implement a bilevel optimization program using Python-based package for Adversarial Optimization (PAO), which is based on Pyomo. I am new to Pyomo, though I have used ...
0
votes
0
answers
11
views
SCIP in pyomo google colab how to use it
I tried to solve a problem with ipopt in google colab, but ipopt is performing poorly and struggles a lot to find an optimal solution.
For using ipopt the code lines are simple as:
#IPOPT solver (NLP):...
0
votes
0
answers
43
views
Incorrect values of the optimal solution
I'm trying to solve a linear optimization
problem
In my case, K is 2 and p1, p2 are all 0.5, n=8 and m=5.
Specifically, the full formula of the problem is
this one
with the constraints
For simplicity, ...
0
votes
0
answers
27
views
Ipopt in pyomo with anaconda
I tried to run a simple code using ipopt in my anaconda after succesfully installation of Coopr, pyomo, glpk and ipopt in my new environment with two different versions of python, 3.9 and 3.11:
#...
0
votes
1
answer
58
views
Trying to understand why my formulation is non-convex? (gurobipy.GurobiError: Q matrix is not positive semi-definite (PSD))
I am trying to implement a SOCP that I believe to be convex, but when I run it on a small instance I get the error:
gurobipy.GurobiError: Q matrix is not positive semi-definite (PSD). Set NonConvex ...
1
vote
0
answers
33
views
Ipopt in pyomo google colab
I tried to use the following code to use ipopt in google colab, but it gave an error.
#solver:ipopt
!apt install coinor-libipopt-dev
!pip install ipopt
SolverFactory('ipopt').solve(model).write()
...
0
votes
0
answers
19
views
Understanding the behavior of getting `ipopt_zL_out` and `ipopt_zU_out` for fixed variables
I am trying to understand how ipopt_zL_out and ipopt_zU_out are assigned particularly for fixed variable (i.e., the variable with the same lower and upper bounds). I found that the Suffixes values (...
0
votes
0
answers
12
views
Choose acceptable sets for binary solution of MILP problem in Pyomo
I have a simple MILP problem and would like to input a set of acceptable binary solutions. That is, the solver should ignore any other solutions even if they have a lower cost.
I put below a simple ...
1
vote
2
answers
46
views
Is there a difference between a double-indexed or multiple single-indexed variables in Pyomo?
I am currently working on a problem in which I want to optimize several objects over a period of time (specifically: the charging profile of several electric vehicles over a certain period of time).
...
0
votes
0
answers
15
views
Pyomo - how to initialize an expression for t=0 within a constraint function
While creating constraint for time-indexed model, is there a way to initialize a constraint expression for t=0 instead of using if-else?
My current code: def soc_constraint(model, t): if t==1: return ...
0
votes
0
answers
9
views
Creating decision variables with conditions in pyomo
I want to create decision variables only if they satisfy certain conditions about their index. Say I have a decision variable inventory(t,d) on index t and d. I want to create inventory only if the d ...
0
votes
0
answers
24
views
How can I add an expression or objective to an existing pyomo model?
I have defined a model that we can call using make_base_model(demands, earliest_arrivals, travel_times). The model has one expression (which I can use as the objective) and several constraints. Now I ...
0
votes
0
answers
20
views
Pyomo constraint function: Which is more expensive, embedding if-else within the function or create a new binary parameter in the expression?
While creating a constraint definition for pyomo model with time-series (8760-step) indices, some parts of expression needs to be left out, conditional to a user-defined input (True/False)
(a) def ...
0
votes
0
answers
19
views
How does Expr_if is reformulated in pyomo fo solver?
I came across Expr_if in pyomo that can do logical if-then-else with variables. Here is dummy example.
model = ConcreteModel()
# Define variables
model.x = Var(within=NonNegativeReals)
model.y = Var(...
0
votes
0
answers
13
views
Unreachable code after .load_vars() method call
when I call the method load_vars() on my SolutionLoaderBase object, the following code (any code) becomes unreachable. Is that intended or is it some kind of bug?
For example using CPLEX (but it doesn'...
0
votes
0
answers
22
views
How to get the GAP of a pyomo model running with Gurobi solver?
I usually use: 'results.Solver()['Gap']' for CBC, SCIP... but I'm not being able to get the gap value solving my pyomo model with Gurobi, using last pyomo version 6.6.2.
I found there is a gap item by ...
0
votes
1
answer
56
views
Write a constraint in Pyomo with max and min
I have to write the Pavg and H_ad constraints in pyomo from the following picture with 4 constraints,
# 1. Average Pressure
def Avg_pressure(model, I, J, T, S, r):
return model.Pavg[I, J, T, S] =...
0
votes
1
answer
33
views
Index error in a non anticipativity constraint in multi stage stochastic optimization
My model sets are defined as,
graph = { 1 : [2],
2 : [3, 4],
3 : [4, 5, 6],
4 : [7, 8, 9],
5 : [],
6 : [],
7 : [],
...
0
votes
1
answer
60
views
How to operate on a multi-index object in pyomo accessing only one of its indexes?
I would like to know how to operate over pyomo multiple index objects just by employing one of the index.
This question may be a bit stupid, but I have not found a possible solution. In my model, the ...
0
votes
1
answer
71
views
IPOPT in Pyomo returns non-zero return code
I am working on a complex non-linear model for power grid analysis I cannot post here. As decision variables it is supposed to set the storage power for all time steps of a time series. The model is ...
1
vote
0
answers
64
views
How to model a contiuous discharge rate for a storage in a pyomo optimization?
I am attempting to optimize a multi-stage industrial process. The objective function is the minimization of production costs. In the initial step, a liquid product is produced and added to a container....
0
votes
0
answers
63
views
How to use appsi_highs solver in Pyomo with pyenv and poetry
I have troubles making the appsi_highs solver work in Pyomo inside a Poetry virtual env using a pyenv python 3.10.
I used the command inside my virtual env:
pyomo build-extensions
Which ...
0
votes
1
answer
36
views
How to run this simple optimization program with Pyomo?
I am trying to run a 'simple' optimation programm without any constraints to get the programming running. After getting the program running I am planning on adding constraints and other input ...
0
votes
0
answers
22
views
Pyomo optimization RuntimeError
I'm trying to implement an optimization problem on gurobi unsuccessfully. I have this script below in which I cut out the upper part because it would be huge.
\##CONCRETE MODEL
ONR = ConcreteModel(...
0
votes
1
answer
28
views
Implementing a Complex Constraint in Pyomo
I'm trying to implement a rather complex constraint in Pyomo and running into errors. The problem is formulated as follows:
The decision variables are in a C by A matrix that are contained in the ...
0
votes
0
answers
44
views
Setting Solver Options for the Scip Solver in pyomo for MINLP Problem
I am sorry if this question has been handled before but I have a problem implementing solver options for the Scip solver.
I am modelling a MINLP problem using the Scip solver for the MI part and ipopt ...
0
votes
0
answers
31
views
Improve pyomo constraint with nested loops
I have a series of constraint that look like this:
def r7_encadenamiento_inicial(modelo,b, s, ss, l):
condicion1 = modelo.s_index[s] < modelo.s_index[ss]
if not condicion1:
return ...
0
votes
2
answers
33
views
Installing IPOPT in Linux (to be used with Pyomo)
I am trying to install ipopt in a Linux machine but without success...
I have followed the steps in https://coin-or.github.io/Ipopt/INSTALL.html.
I am able to sucesfully compile it but in the end it ...
0
votes
0
answers
39
views
How can I include this constraint in a Python implementation of the Travelling Salesman Problem?
I'm creating a version of the TSP and have followed an article about it to create a version that very nearly matches my desired parameters. I want to add a line like the one currently commented out ...
0
votes
0
answers
147
views
I don't have the right outcome in pyomo model
Oxbridge University maintains a powerful mainframe computer for research use by its faculty, Ph.D. students, and research associates. During all working hours, an operator must be available to operate ...
0
votes
0
answers
41
views
Pyomo Abstract model for Machine learning model output constraints in optimization
I am working on an optimization problem using the Abstract model in Pyomo. The objective function is a linear function of decision variables whose coefficients come from the ‘values.dat’ file. The ...
1
vote
1
answer
62
views
I don't have the right outcome in my pyomo model
Task:
Larry Edison is the director of the Computer Center for Buckly College. He now needs to schedule the staffing of the center. It is open from 8 AM until midnight. Larry has monitored the usage of ...
1
vote
1
answer
90
views
Optimizing a batch process in pyomo Python - How to set a constant operational power for each batch?
I want to optimize an industrial batch process using pyomo in Python. The objective function is to minimize the cost of the system. In my simplified example, I specify production costs with random ...
0
votes
0
answers
75
views
I do not understand how to install IPOPT and COUENNE with PYOMO : Can you tell me how to do it?
I have built a model with PYOMO. Now, I want to run it wih Couenne (or ipopt). I have downloaded the binaries for COUENNE 0.3.2 Windows as available by COIN-OR, and added the "bin" subfile (...
0
votes
0
answers
16
views
Is it possible to define a multiperiod optimization with Pyomo network?
I'm looking for help in solving an optimization problem using Pyomo with multi-period optimization. Specifically, I have declared a block with certain variables for a set of time periods (m.date), and ...
0
votes
0
answers
22
views
Cross-installation importing of Python libraries
I have installed Anaconda because it supports Pyomo and I also have installed WinPython for pip installing libraries like TspLib95 whose pip installation gives Anaconda hickups.
I now want to use ...
0
votes
1
answer
34
views
Pyomo stops after one iteration
With the following code, Pyomo stops after just one iteration, while I would expect it to minimize the function and iterate more:
import pyomo.environ as pyo
model = pyo.ConcreteModel()
model.x = pyo....
0
votes
1
answer
47
views
EDITING RHS VALUE WITHIN MULTIPLE SOLVES IN PYOMO
I am trying to switch Gams to pyomo and I'm unexperienced in pyomo. I have a basic model to demonstrate my problem. I want to change right hand side value of some constraints between repeated solves. ...
0
votes
1
answer
31
views
Two dimensional parameter in Pyomo based on an initialized set
I have a 2-dimensional list as follows:
s = [
[0,0,9,6,8,1,6,2,3,9],
[0,0,0,3,1,1,2,5,7,8],
[3,10,0,2,6,4,0,4,8,3],
[7,10,10,0,9,0,2,3,10,7],
[1,10,8,9,0,9,6,6,8,8],
[1,1,9,8,5,0,5,7,10,0],
[3,2,2,6,...
0
votes
1
answer
116
views
Optimizing a batch process in pyomo Python - How to set a fixed operation time for each batch?
I want to optimize an industrial batch process using pyomo in Python. The objective function is to minimize the cost of the system. In my simplified example, I specify production costs with random ...
0
votes
0
answers
58
views
How to do a nonlinear optimization model in Pyomo with an integral in the objective function?
I am attempting to solve a nonlinear dymanic optimization model (discrete time, finite horizon) with Pyomo. My model features two control variables and two state variables : the first one is ...
0
votes
1
answer
31
views
Math modeling of inventory optimization using cplex
I'm trying to solve this using CPLEX using pyomo framework. My code is as follow
import pyomo.environ as pyo
from pyomo.environ import *
from pyomo.opt import SolverFactory
import numpy as np
model=...
0
votes
0
answers
53
views
Pyomo cannot find solver CVXOPT despite it is installed in Conda
I am attempting to solve an optimization problem coded with Python / Pyomon, using the solver CVXOPT.
My full script is :
import pyomo.environ as pyo
import cvxopt
Horizon = 3
model = pyo....
0
votes
1
answer
71
views
Multiplication of an Expression object with a boolean in pyomo
I'm currently trying to upgrade pyomo from 6.5.0 to 6.6.2
However I encounter an issue with the * operator when trying to multiply a boolean with an expression object. It works fine with binary ...
0
votes
1
answer
44
views
Linearize Pyomo model with BigM Constraint
I may have answered my own question posted below with the following.
I believe the construction is now appropriately linear and returns a feasible solution. Though I would appreciate any feedback as I ...