# Questions tagged [python]

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

399 questions
Filter by
Sorted by
Tagged with
14k views

### Are Python and Julia used for optimization in industry?

I am giving a small computer exercise that aims at teaching students the basics of a modelling language to model small optimization problems. So far I have been using the modelling language GAMS as ...
• 1,652
15k views

### MATLAB vs. Python in industry

I am a beginning PhD student in math, and I would like to focus on optimization. I am learning programming for the first time, and I have written out some rudimentary optimization algorithms in both ...
• 603
15k views

### Which Python package is suitable for multiobjective optimization

I would like to start using Python for modelling and solving optimization problems. I would like to use both single-objective problems and multi-objective problems with a multidimensional objective ...
• 1,652
4k views

### YALMIP-like modeling environment in Python

What are the handiest optimization parsers out there? Is COIN-OR's PyPy being used actively? I am currently trying to do an optimization project in Python, but I am used to using MATLAB + YALMIP ...
• 3,980
2k views

### How to model a mixed-integer linear programming formulation in Python using Gurobi?

I can remember that I spent some time in understanding how to formulate my first model. So I aimed at presenting a complete model here, wishing to save some time for students or researchers needing it....
• 2,104
2k views

### What are technologies or libraries which greatly improve the speed or ease of use for delivering of OR software?

There are many great technologies/libraries out there to improve the speed and quality of implementing and deploying OR applications. However in my experience I "stumbled" upon many of them ...
• 3,655
7k views

### How to find all vertices of a polyhedron

I have a convex polyhedron given by a set of linear inequalities, for example: $$x_1 \geq 0,~~ x_2 \geq 0, ~~x_3\geq 0 \\ x_1+x_2\leq 1,~~ x_2+x_3\leq 1,~~ x_3+x_1\leq 1$$ I want to list all the ...
4k views

### Settings for a faster solution of a MILP (GUROBI, python)

Using GUROBI with python. When solving a MILP, I notice that the incumbent is very early (25sec) at the optimal point but the best bound is so slow to fall (maximization problem) that it takes ages (...
223 views

### Are there examples of spatially explicit MIP problems?

Disclosure: I am an MSc student in economics, but not an expert by any means in OR. I am trying to model a spatial MIP problem of an invasive species similar to this academic paper, however, my ...
• 2,319
4k views

### Python API and CPLEX

Note: See the EDIT below for one possible solution. I apologize if this is not appropriate but I don't really have anywhere else to turn. I was hoping that someone would be able to post how they ...
• 2,319
1k views

### Change coefficient in PuLP

Once a model is implemented in PuLP, how do you change a coefficient (e.g., $a_{ij}$, $b_i$ or $c_j$) of a program of the from $\min\{c^{\top}x: Ax=b, x\geq0\}$? Specifically: How to update ...
• 1,355
971 views

### Termination Criteria of Solver in Pyomo

I am solving a nonlinear optimization problem using Pyomo with Ipopt as solver. The solver exits with the status: EXIT: Optimal Solution Found. This I can cross ...
• 1,485
2k views

### Simulation in Python

What is the most common package for discrete-event simulation in the OR community? I have found SimPy package.
• 400
755 views

### How to solve the Cumulative Traveling Salesman Problem using or-tools in python?

The objective of the Cumulative Traveling Salesman Problem (CTSP) is to minimize the sum of arrival times at customers, instead of the total travelling time. This is different than minimizing the ...
2k views

### Integer programming problem with simple quadratic objective function in Python

I have $n$ objects that need to be divided among $k$ groups. Each group must receive at least $5$ objects. In addition, the percentage of objects in group $i$ should be as close as possible to $p_i$ ...
• 343
827 views

### Modeling and solvers

I have just started to dive into OR world on my work. Currently we are using GAMS with Gurobi but some of us have strong programming background and would like to have more programmatic approach to OR. ...
• 203
2k views

### Implementing solvers with Object Oriented Programming

I would like to know what are some best practices in designing a solver implementation with Object Oriented Programming. We have implemented a solver with procedural programming paradigm, using python,...
564 views

### Significant bias introduced into simple simulation

This question has been asked on Cross Validated Introduction Service is allocated to an infinite source of customers i.e. there is always a service in progress. The duration of the $i^{th}$ service ...
• 463
14k views

### How do I access the value of a variable in PuLP?

In Python's PuLP package, how can I get the value of a decision variable? For example, if I declare a variable— ...
• 13.1k
2k views

• 1,414
761 views

### Creating a Continuous Decision Variable between 0 and 1 in Python-MIP Interface

This task appears to be harder than it seems to me. I want to create a continuous variable $x \in [0,1]$. To test this, I did use the open-source Python-MIP interface which uses the CBC-Solver out ...
• 1,193
6k views

### Python does not identify the academic version of CPLEX

Python does not identify the academic version of CPLEX. I am using Linux, Ubuntu. I have Python 3.6. I installed CPLEX studio 12.9 (academic version installed via the file ...
• 2,104
575 views

### Using the values of variable in the objective function before optimizing

I am facing a problem to multiply a term in objective function. My objective function is : $$\min \sum_{t=1}^\top p_{t} \cdot (1+r) \cdot y_{t}$$ where $p$ is the ...
• 99
759 views

### Travelling salesman problem with given number of locations to visit

There's a great example here of how to find a solution to the travelling salesman problem: ...
187 views

### Specific filter on the set using Python

I'm trying to write an optimization model using an open-source solver's Python API. I'm new to use Python. The model objective function is as follows: \sum_{k=1}^{K} \sum_{j=1}^{n}\...
• 8,960
439 views

### Why is Gurobi output in Pyomo returning floating-point values rather than optimal integer solution?

I am hoping someone will be able to point me in the direction of why I am experiencing floating-point outputs rather than simply model.X = [15,15] and model.Z = [15,5] as solutions to this model? Note ...
• 333
4k views

### How can I add this conditional constraint to my model in Python?

I am creating an optimization model with 2 sets of binary decision variables. The first, site, is regarding which of 380 cities to place manufacturing sites in, and ...
• 447
1k views

### Read an LP/MPS file in the PuLP

I was trying to read a MPS file by using the PuLP package in the Python, but I can't find any related documents on it. Does ...
• 8,960
3k views

### Gurobi's "Out of memory" error without exhausting the RAM?

I wrote a branch-and-price algorithm in Python 2.7 which solves several small LP and MIP models by Gurobi 8.1 in each node. The algorithm runs fine at first, it produces both lower bound and upper ...
• 683
247 views

### Heuristic Search Planning Tree Leading to Worse TSP Solutions than Naive Greedy

I'm doing a Traveling Salesman Problem (TSP) homework for a coursera optimization course. My first attempt was a regular naive greedy approach, from each point, moving to the closest node (that hadn't ...
3k views

### Python vs. compiled languages in OR research using metaheuristics

In many articles that use metaheuristics to solve optimization problems, the programming language of choice is C++. For example, the following two articles present state-of-the-art metaheuristics to ...
• 185
1k views

### Finding a solution to a linear program with a small number of zeros

It is known that, in a linear program with $k$ constraints, there exists a basic feasible solution in which at most $k$ variables are non-zero. How can I find such a solution? Is there a polynomial-...
502 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, ...
• 105
1k views

### Problem is infeasible with Gurobi, feasible with cbc (but can't access objective value)

I am solving a MILP with cbc and gurobi (via pyomo). Gurobi states that the model is infeasible. As to cbc the solver status states that a feasible and optimal solution is found, but then it fails to ...
• 424
509 views

### Can docplex (module for Constraint Programming optimizer CPLEX for Python) read .lp or .mps file?

I want to solve a problem with docplex.cp (module for Constraint Programming optimizer CPLEX for Python), and the problem is available in ...
• 2,104
I am coding a MIP problem in docplex and I would like to ask for some tips. I would like to input a binary parameter that states a compatibility relation: I have a set of characteristics $H$ to be ...