Questions tagged [python]

For questions about solving Operations Research problems using the Python programming language.

Filter by
Sorted by
Tagged with
0 votes
3 answers
120 views

Using PULP to model machines in a factory

Complete revision: I have all 4 machines that can run in positive and negative directions which results in 2 outputs: $ P_1 = \begin{cases} -390 \le P_1 \le -300 & \text{for neg mode}\\ 0 &...
sino's user avatar
  • 1
2 votes
0 answers
62 views

Pyomo Terminal Condition: other

I have written a huge optimization code in pyomo. The code serves for any planning horizon. The variables are indexed in time (t). When I set t to have 365 days, the termination condition is feasible/...
Alex's user avatar
  • 21
1 vote
1 answer
55 views

Python and GLPK to solve Linear programming problem (infeasible solution)

I'm using Python and the GLPK Solver to find recommendations for an infeasible problem. I'm optimizing for price, and this is the problem data: Define problem data foods = ['Food 0', 'Food 1', 'Food 2'...
Joao Branco's user avatar
0 votes
0 answers
32 views

Why does changing this one thing in the Primal Effective Capacity Heuristic improve the solutions it generates for the MDK problem?

For a long-done project presentation, I implemented the Primal Effective Capacity (PECH) Heuristic to look for initial greedy solutions for the Multidimensional Knapsack (MDK) problem in Python. I ...
Miss Mae's user avatar
  • 101
2 votes
2 answers
78 views

Small negative decision variable returned in Gurobipy model

I have a multi-period model in gurobipy with 7 types continuous decision variables and 1 type of binary (Thousands indexed total). The model solves properly and the solution has passed many validation ...
TroyE219's user avatar
  • 105
3 votes
1 answer
70 views

Solver options in Pyomo as long as using the NEOS solvers

I am working on a scheduling problem that is already coded in Pyomo. To solve the problem, I have used the NEOS solver, CPLEX. Now, to test and run some of the instances, I need to call some CPLEX ...
A.Omidi's user avatar
  • 7,559
5 votes
2 answers
119 views

What are my options for exact linear programming solvers in python3 that work as of April 2023?

So a while back I had asked this question: Is there a Linear Programming Library that natively supports fractions instead of floating point arithmetic? And basically the overwhelming consensus was ...
Sidharth Ghoshal's user avatar
1 vote
0 answers
30 views

Which Python package is suitable for finding the optimal non dominated set in multiobjective optimization?

I would like to know how to use pyhon or Cplex or both for finding the whole optimal pareto front for a biobjective mixed integer linear programming problem? Thanks
Mansour's user avatar
  • 11
2 votes
1 answer
94 views

Using networkx predecessors in Pyomo initialize method

I am working on the directed graph by using the Networkx package and what I need is to use its predecessors' method on an optimization model. Let's say, there exists a directed graph with just $12$ ...
A.Omidi's user avatar
  • 7,559
0 votes
1 answer
80 views

Optimal blending of gasoline via LP

...
N_ote's user avatar
  • 11
1 vote
4 answers
155 views

Multi-period Inventory Balance in Gurobipy

I would like to get the inventory balance in the oponed facility $\text{C}$ such that, the Inventory at time $t$ is equal to the previous one, plus the inflow minus the outflow. I have tried to create ...
Abde's user avatar
  • 81
2 votes
2 answers
167 views

How to represent the objective function of the Weapon Target Assignment problem in CVXPY?

I am trying to use CVXPY to analyse a problem and the objective function for this problem involves calculating a product and a sum as per the problem description below (taken from a draft paper I am ...
BRavos's user avatar
  • 29
0 votes
0 answers
55 views

Gurobi-Python, unmet demand of customers

I would like to capture the unmet demand by modeling the following constraint with two decision variables. where $QU_{wc}$ is the unmet demand and $QW_{wc}$ the shipped amount of products. I model the ...
Abde's user avatar
  • 81
0 votes
2 answers
105 views

Modelling with Gurobi-Python a Supply Chain Problem

I would like to write the following simple model in GurobiPy, which is part of many terms that's belongs to the objective function, I assumed that I have three suppliers are selected and three ...
Abde's user avatar
  • 81
0 votes
0 answers
52 views

Multi-Scenario Gurobi Python Output

I have an lp and am trying to solve multiple scenarios at once. One of my scenarios is infeasible though this is not the issue. For some reason, when I print m.status, both solutions have a status of ...
TroyE219's user avatar
  • 105
2 votes
2 answers
151 views

I want to solve an optimization problem with nonlinear piecewise objective function (I tried Pyomo with "ipopt" solver but I had an error)

I want to solve an optimization problem where the objective function is the summation of nonlinear, piecewise functions in the decision variables q_i's such that when a decision variable q_i < 1, ...
3bod's user avatar
  • 21
3 votes
1 answer
112 views

Converting continuous variable dict to binary variables in python docplex

I am solving a problem using linear relaxation at the initial phase. Hence, I need continuous variables at the beginning. Then I need to convert some continuous variables to binary and solve the same ...
user avatar
2 votes
1 answer
130 views

Implementing a MINLP problem in Pyomo: giving an infeasible solution

I'm trying to implement a MINLP problem which is described in a previous post here: How do we formulate a problem where the decision variable has an index that is also a decision variable? The only ...
Steven01123581321's user avatar
0 votes
0 answers
35 views

Creating a simple class in python for doing simulation of MDP

I am currently learning Python and doing object-oriented programming. I am trying to create a simulation for MDP. My problem statement is: "I have four stages of process. Each stage has two ...
Margi Shah's user avatar
2 votes
1 answer
76 views

Grid search for optimization problem

Suppose you wanted to solve the following optimization problem: $$\inf_{a \geq 0}\sup_{b \geq 0}\dfrac{(a^2 + 1)(a + b)}{2a + b} + \dfrac{b}{a + b} - ab,$$ where $a, b$ are scalars. How would you use ...
Nico Konrad's user avatar
3 votes
1 answer
92 views

Question about implementation method for optimization problem

Suppose we wanted to solve the following optimization problem: $$\inf_{x \geq 0}\sup_{y \in [0, 1];\ z > 0} f(x, y, z),$$ where $f(x, y, z)$ is some objective function with a closed form that can ...
Nico Konrad's user avatar
5 votes
6 answers
2k views

How can I solve this algorithmic task in Python?

I am trying to solve this task: There are three datasets: first data on offices in cities: each city has a certain number of offices and each office has its own capacity of employees. Second, data on ...
Ir8_mind's user avatar
2 votes
1 answer
88 views

How to change the price in the objective function, depending on its sign, in python, with Z3?

My objective function is $$ f_{objective} = \sum_{n=0}^{m} \int\limits_{I_n}^{I_n + \Delta i_n} P_{normal}(t) \,dt - \int\limits_{S_n}^{S_n + \Delta s_n} P_{CO_2}(t) \,dt $$ ($P(t)$ is the price,) ...
Andreas Schuldei's user avatar
3 votes
2 answers
598 views

Pulp problem gets the right objective value but fails to find the minimal solution

I converted an excel solver problem to Pulp. However, while the pulp program calculates the objective function value correctly, it doesn't arrive at the right answer. I can't figure out what is wrong ...
Murtaza's user avatar
  • 39
2 votes
1 answer
102 views

Updating constraint set rhs in docplex

I am trying to update the rhs of a constraint iteratively under a while loop in docplex, however, it does not work properly. As I analyze the output text file, while some constraints are updated as I ...
user avatar
2 votes
1 answer
59 views

How to find the maximum probability of satisfying the conditions in all combinations of arrays

for example, I got a list of tokens and each token's number of characters(length) is length = [2, 1, 1, 2, 2, 3, 2, 1, 1, 2, 2, 2] and here is the list of each ...
ryrie23's user avatar
  • 21
-1 votes
1 answer
92 views

GurobiPy Tutorials and hands on from beginner to advanced

What is the best way to start modelling with GurobiPy, in order to utilize it, for research purpose (i.e. more complicated problems)?
Abde's user avatar
  • 81
3 votes
1 answer
93 views

How to maximise a function with non-differentiable constraints while integrating over a time series data series with linear programming?

In this problem, I need to pick the optimal charging and discharging times and durations of an electric car-sharing battery to maximize income - not just for a single (dis)charging cycle, but a whole ...
Andreas Schuldei's user avatar
3 votes
0 answers
38 views

Pygmo2: What is the point of evolving an archipelago in a loop if number of generations already set in algo

I want to solve a multi-objective problem with nsga2 or moead taking advantage of the parallelism available in pygmo library. I have seen a very nice example on github posted below. However I am not ...
Sophie's user avatar
  • 31
1 vote
2 answers
188 views

Capacitated Maximum Coverage Location Problem, Python and Gurobi

I am trying to solve a capacitated MCLP problem with two additional constraints. Non-overlapping circles Minimum and Maximum value for the capacity for a circle. for 2nd constraint, I am able to add ...
Nandy's user avatar
  • 13
4 votes
2 answers
169 views

XPRESS variables as indices for mixed integer linear programming

Can XPRESS variables not be used as indices to retrieve other XPRESS variables. In Python, for example, say that I have a list of XPRESS variables, each which can take on values (0->24). I'd like ...
jbuddy_13's user avatar
  • 471
5 votes
4 answers
247 views

What are the key pros and cons to mention when asked why one prefer Julia over Python in OR-research-industry interviews and vice-versa?

I want to apply for a position after my PhD in an industrial laboratory that does research in OR. They stipulate that they want either Python or Julia programming languages. Since my Bachelor's ...
JKHA's user avatar
  • 583
3 votes
1 answer
124 views

Expressing $\{0,1\}$ assignment across a matrix in MILP?

I have a MILP (Xpress) constraint, which is doing what I want it to, but I'm struggling to translate it into a LaTeX friendly mathematical expression. The below code enforces that in the matrix $V$, ...
jbuddy_13's user avatar
  • 471
4 votes
3 answers
1k views

Genetic Algorithm

Is there any Python library as published on PyPi, with genetic algorithm (GA) or GA inspired solver that helps with constrained optimization? I am aware of Matlab's GA solver and also aware that costs ...
Sutanu's user avatar
  • 3,073
3 votes
2 answers
174 views

Modifying and re-optimizing a model using CPLEX Python API

I came across the following functionality that is offered by CPLEX for modifying and re-optimizing a model based on previous computations: https://perso.ensta-paris.fr/~diam/ro/online/cplex/cplex1271/...
Pia MiA's user avatar
  • 392
1 vote
1 answer
494 views

TypeError: unsupported operand type(s) for *: 'IntVar' and 'float' in ortools [closed]

I am trying to implement a constraint as follows: ...
mufassir's user avatar
  • 181
2 votes
1 answer
105 views

Correct way to set a quadratic constraint Xpress

I'm implementing on Xpress a problem with different solution proposed on a paper. The idea is to decompose a matrix $X$ into a convex sum $\sum_{t}\lambda_t M^{(t)}$, where each $M^{(t)}$ has only ...
Davide Trono's user avatar
2 votes
1 answer
79 views

Control load per trip in multi trip VRP in ORTools

I have implemented multitrip VRP in ortools (To be specific, solved CVRPTW with virtual depots). Maximum number of trips per vehicle is limited to 2. I want to put a hard constraint that load carried ...
mufassir's user avatar
  • 181
3 votes
2 answers
814 views

Is solving a quadratic programming optimization problem using python slower than C++?

I am using the cvxpy library in python to solve a quadratic programming problem and the solver used is scip. I found that when the amount of data becomes large, the solution process will be ...
happy's user avatar
  • 63
1 vote
1 answer
196 views

MIQP — CVXPY unable to treat summation of variables as a variable

I have a quadratic integer programming assignment problem. The goal is to assign riders seats on a bus such that distance between any two riders is maximized; however, the importance of each objective ...
jbuddy_13's user avatar
  • 471
1 vote
1 answer
147 views

Applying weights to assignment problems for linear MIP solvers

In previous posts, A & B, I posed the Movie Theater Problem. In short, the movie theater problem encompasses assigning viewers to seats such that the distance between viewers is maximized, however,...
jbuddy_13's user avatar
  • 471
2 votes
2 answers
109 views

Mixed Integer Programming: Iterative assignment problem

I have a real world problem, which is analogous to the below toy problem, which I call 'The Movie Theater Problem' (TMTP.) In TMTP, movie viewers are assigned seats which principally balances two ...
jbuddy_13's user avatar
  • 471
1 vote
1 answer
114 views

Create constraint when variable is within a given range MILP

What is the best way to specify whether a given variable is within a given range in Pyomo? Here I have a binary decision variable assign[t, e] which I want to ...
Pia MiA's user avatar
  • 392
5 votes
1 answer
322 views

How to formulate the inequality constraint $\sqrt{x^2+y^2} \leq z$ using gurobipy?

How to formulate the following constraint using gurobipy $$ \sqrt{x^2 + y^2} \le z$$ where $x, y, z$ are continuous optimization variables? I saw how to formulate it using CVXPY: ...
Hussein Sharadga's user avatar
1 vote
2 answers
198 views

How to solve this mixed integer quadratic program using cvxpy or other method?

My problem is described in this picture: $$ \begin{array}{l} \left\{\begin{array}{l} \text { objective function: } \\ f = \min \sum_\limits{l=1}^2 \sum_\limits{i=0}^{2^l-1} \sum_\limits{j=0}^{2^l-2}\...
happy's user avatar
  • 63
2 votes
1 answer
90 views

Difference between cplex_direct and cplex in Pyomo SolverFactory

I noticed some people specify the solver as "cplex_direct" whereas others as "cplex" when passing the option to SolverFactory in Pyomo. Is there ...
Pia MiA's user avatar
  • 392
2 votes
2 answers
188 views

Improve Network Flow computation with additional Pyomo constraints based on previous computation

I am performing several max-flow computations on extremely similar networks and I seek to improve their execution time based on information from previous computations (As there is a lot of repetitive ...
Pia MiA's user avatar
  • 392
1 vote
1 answer
57 views

Are there any performance overheads if we specify Pyomo Constraints in different way?

I am interested to know whether there are any performance overheads for specifying Pyomo Constraints in different ways. For example, which of the two ways is better? I am trying to speed up one of my ...
Pia MiA's user avatar
  • 392
7 votes
3 answers
474 views

Profit Maximization LP and Incentives Scenarios

I wrote a profit maximization LP with inventory, component usage, production, and machine hours constraints. When I optimize the model, it solves as expected. When applied towards a business case, ...
TroyE219's user avatar
  • 105
2 votes
1 answer
164 views

Implementing subtour constraints to a VRP in python

Hi I have a problem related to the vehicle routing problem, where I want to implement the subtour constraints $\sum_{(i,j)\in S} x_{ij} \leq \lvert S \rvert - r(S), \: \forall S \subseteq N, S > 2$ ...
Magnus M's user avatar

1
2 3 4 5
7