Questions tagged [python]

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

Filter by
Sorted by
Tagged with
3
votes
1answer
39 views

Access LpVariable as input to another Keras sequential network

I want to use LpVariable as an input argument to a sequential CNN network layer, which is in Keras. When I tried to call the function I got the error as follows: <...
7
votes
1answer
286 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 ...
6
votes
1answer
94 views

Creating a Decision Variable in Python-MIP with Dictionaries

I have already seen in the Python-MIP documentation on how to implement a variable with multiple indices. In each example I read, this is done with the use of lists and integers as indices. This is ...
9
votes
4answers
281 views

Open Source MILP software for Python with user-friendly API to define the optimization problem

Following the accepted answer to Assignment problem where assignments must be done sequentially I would like to write a Python script which can solve the problem defined there. It's a Mixed Integer ...
3
votes
0answers
79 views

Power of variable or tools

I'm working with OR Tools in Python and I need to define the objective function an expression of the variables. In particular, the objective function is $$\frac{c_j}{1.7^{s_j}}$$ with $c_j$ ...
7
votes
1answer
163 views

Floating points in ORtools

I'm trying to solve an RCPSPDc model (maximizing the net present value instead of a makespan). The objective function is: $\sum\limits_{j \in \text{Tasks}} e^{-\theta\cdot s_{j}}\cdot p_{j}$, where $...
4
votes
1answer
113 views

CPLEX Python API

I am trying to run the following optimization problem at Python by using the CPLEX API: $$\min \{x_1 + x_2\ | \ x_1 \geq 3, x_2 \geq 2, 2x_1 + x_2 \geq 9\} $$ I just want to give a matrix of ...
6
votes
1answer
75 views

Interface for Cbc - COIN-OR

I would like to code some IP/MIP models in python and test them with an open-source solver. As of now, I only know the Cbc - COIN-OR open-source solver. I have already tried the or-tools interface, ...
8
votes
1answer
465 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: ...
6
votes
1answer
283 views

Constraint Programming OR-Tools finding Matrix Combinations

As a similar post of mine Find all Combinations of a Matrix I am trying to find matrix combinations with entries $>0$ meaning for a matrix \begin{bmatrix} 0 & 1 & 3 \\ 5 & 2 & 1 \\ ...
5
votes
3answers
844 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-...
7
votes
2answers
206 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 ...
8
votes
2answers
1k 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,...
11
votes
3answers
674 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 ...
5
votes
1answer
81 views

Scheduling with transition costs - DOCPLEX

I am dealing with a kind of scheduling problem. I have a set of tasks to be executed by a set of machines. It is known that different machines are able to execute the same task, but each machine can ...
11
votes
4answers
544 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$ ...
10
votes
1answer
315 views

TSP problem: traveller does not visit all nodes - Google OR-tools

Context: I am dealing with a kind of scheduling problem, in which I have a set of tasks and machines. All tasks must be assigned to machines (not necessary all of them). In addition to that, I must ...
5
votes
0answers
25 views

Restricted assignment problem with variable required tasks: feasibility in docplex.cp

I am trying to solve a kind of restricted assignment problem in which the tasks required are dependent of the user input. Let me suppose that the user can enter a set of requirements. According to ...
5
votes
0answers
32 views

How to handle constraints in docplex to states the relation between two variables?

I am using docplex.cp and I need to state the following constraint: $$\sum_{c}(X_p{_w}_{cj}+X_{p+1}{_{w'}}_{cj+1})\leqslant T_w{_{w'}}_{,jj+1} + 1$$ Knowing that the binary variables are: $X_p{_w}...
6
votes
0answers
131 views

How to make constraints satisfy disciplined convex programming guidelines?

How do I turn my convex constraints (described below) into constraints that are DCP so that I can solve them in CVXPy? Is there some ``cheat sheet'' of standard tricks? I'm trying to implement the ...
7
votes
1answer
36 views

DOCPLEX: tips to manipulate data input (binary parameter)

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 ...
7
votes
0answers
123 views

Having trouble with objective function in Python: “GurobiError: Variable not in model”. What else could I try?

I am trying to figure out how I can write this objective function into python using Gurobi. I have to minimize the sum of the product of three dictionary's values. The reason I am confused is that ...
8
votes
2answers
935 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 ...
5
votes
2answers
76 views

How to establish constraint between variables with multiple indexes using CPLEX in Python

I am new in CPLEX and I am using docplex in Python to solve an ILP. I would like to translate the following constraint in docplex: $$\sum_{c}(X_p{_w}_{cj}+X_{p+1}{_{w'}}_{cj+1})\leqslant T_w{_{w'}}...
9
votes
2answers
321 views

Reading an LP/MPS file using Pyomo software

I would like to know is it possible to read an LP/MPS file into the Pyomo software and solve the problem? If so, how can I do that?
7
votes
1answer
160 views

Pyomo: Looping Over A Variable Method

I am trying to extract my variable values into unique lists so that I can pass them to a panadas dataframe and eventually export the dataframe to Excel after I solve my model. The idea is to have the ...
8
votes
3answers
542 views

Maximize assigned tasks to each worker

In a scheduling problem I want to assign the maximum number of tasks to one worker before assigning it to another. For example, if I have $10$ tasks and $2$ workers, the best assignment would be $(10, ...
9
votes
2answers
108 views

When should I use a solver for IP and MIP and can I just use a library from Python, R, Matlab, etc…?

Are there any rules of thumb for figuring out when you need to use a solver like Gurobi or CPLEX, and when you can just solve you problems directly with a Python, R, or Matlab package? Is it just a ...
4
votes
1answer
157 views

Machine Allocation & optimal Utilization using python

Problem statement: Meet the demand which can be met across 2 facilities each having multiple machines where several components are made. The objective is to find the optimal solution to meet the ...
7
votes
1answer
146 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: \begin{equation} \sum_{k=1}^{K} \sum_{j=1}^{n}\...
8
votes
2answers
129 views

Common structures in Gurobi - Python

I'm new to Gurobi in Python and I was wondering if someone knows how to code some common structures of linear constraints. I'm trying to understand how you'll code something like the following ...
11
votes
1answer
220 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 ...
10
votes
1answer
444 views

Simulation in Python

What is the most common package for discrete-event simulation in the OR community? I have found SimPy package.
10
votes
2answers
289 views

How to get GAMS's solvers to work from Pyomo?

I want to run a model written in Pyomo language with CPLEX solver of GAMS. However I get the following error: ...
7
votes
1answer
210 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 ...
10
votes
2answers
138 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 ...
11
votes
1answer
136 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 ...
10
votes
1answer
115 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 ...
8
votes
3answers
617 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 ...
11
votes
3answers
404 views

How to write 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....
8
votes
1answer
206 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 ...
9
votes
1answer
919 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— ...
8
votes
2answers
682 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 ...
5
votes
1answer
104 views

Python PuLP - Unable to Model Non-Square Matrix

I am having issues with setting up constraints using both input arrays from excel and variable arrays within PuLP. It appears the model only works with square matrices and my final code has a matrix ...
9
votes
1answer
132 views

pyomo - pass time limit to NEOS

I am sending a pretty complex Pyomo MINLP to NEOS using Couenne. I'm getting an error message that the solve time is too long (sorry, I don't have it still in my Python console). Is there a way to set ...