Hot answers tagged

12 votes

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

To get the value of the decision variable, you need to use the varValue property of the LpVariable, so: ...
LarrySnyder610's user avatar
10 votes
Accepted

Complicated constraint with logical operators in PuLP

Suppose your two arrays are indexed by $I$ and $J$, and let $x_i$ be the binary variable. zero or one elements may be selected from first array: $$\sum_{i\in I} x_i \le 1 \tag1$$ zero, one, or many ...
RobPratt's user avatar
  • 30.5k
10 votes

"Out of the box" Mixed Integer Programming Heuristics

You can solve your model via the NEOS server which provides Gurobi, Cplex, and other solvers for free if it is the matter of not having a solver. I am not familiar with PuLP but I know it is easy to ...
Oguz Toragay's user avatar
  • 8,622
10 votes

Change coefficient in PuLP

If the model in PuLP is: ...
Daniel Duque's user avatar
  • 1,345
7 votes
Accepted

Read an LP/MPS file in the PuLP

According to PuLP's documentation, it seems that load_file function in PuLP's Amply class can only handle AMPL files with a ...
Qian Zhang's user avatar
7 votes
Accepted

Find the list with the fewest elements whose cumulative sum reaches threshold

Your model basically reads as $$ \begin{align*} \min \quad n \quad \text{s.t.} \quad \sum_{k = 0}^{n} l_{i,k} \geq b_i \cdot \epsilon, \quad \sum_{i \in L} b_i = 1, \end{align*} $$ where $l_{i,k}$ is ...
joni's user avatar
  • 1,477
7 votes
Accepted

How to call HiGHS solver from python PuLP MIP?

PuLP has an API for HiGHS but that version is not sent to pip yet. For the time being, you should pip install PuLP from Github. See the command taken from their readme below. (ps. You might need to ...
berkorbay's user avatar
  • 341
6 votes
Accepted

How to set these constraints in a linear optimization problem (PuLP)?

The rule "works on Saturday implies works on Sunday" can be expressed as $$(D_{i,6} \lor N_{i,6}) \implies (D_{i,7} \lor N_{i,7}),$$ which can be rewritten in conjunctive normal form as follows: \...
RobPratt's user avatar
  • 30.5k
6 votes
Accepted

How to enforce this specific constraint in PuLP?

In other words, you want to avoid a pattern of 010. As a logical proposition: $$\neg (\neg V_{i,j} \land V_{i,j+1} \land \neg V_{i,j+2}),$$ which you can write in conjunctive normal form as: $$V_{i,j}...
RobPratt's user avatar
  • 30.5k
6 votes
Accepted

How do I turn off preprocessing in pulp?

You can use presolve parameter and can pass it to solver(CBC) using following statement (model is your problem object) ...
anjikum's user avatar
  • 974
6 votes

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

How do you define the "right" answer? If the objective function value is computed correctly and reaches minimum value, then it is possible that the optimal solution is not unique, and that ...
Kuifje's user avatar
  • 12.9k
5 votes
Accepted

Python "Coffee Shop Scheduling Problem" - Scheduling Lunches/Breaks

The model you linked in the question will do the job. You just set $a_{jt}=0$ if a worker on shift $j$ would be taking a break at time $t$.
prubin's user avatar
  • 37.9k
5 votes
Accepted

Multi period inventory / reordering MILP in PULP

Some comments on your model: you can remove constraints $\#1$ and $\#2$, as you have already defined the variables as non negative the problem is infeasible, because the inventory is not a variable, ...
Kuifje's user avatar
  • 12.9k
5 votes
Accepted

I'm trying to solve an OR problem written using pulp framework , with gurobi, in Linux , but I'm not able to solve it

The path in Linux has to point to the gurobi_cl binary, which is located in the bin folder. ...
Richard's user avatar
  • 3,459
5 votes
Accepted

Binary Integer Programming Problem - Enforce Zeros on Certain Groups

Let $G$ be the set of groups. For group $g\in G$, let $I_g$ be the set of indices $i$ in that group. Introduce binary decision variable $y_g$ to indicate whether $x_i=0$ for all $i\in I_g$. To ...
RobPratt's user avatar
  • 30.5k
4 votes
Accepted

Representing Date Variables in Pulp

You don't want to create a variable representing a date in pulp. You want to utilize zero-one indicator variables for each option. In this case your options are the vessel-date combinations. Index the ...
Wesley Dyk's user avatar
4 votes

How to transfer an optimization problem written with GUROBI (in python) in a grammar that can be readily solved with another solver?

I think pySCIPOpt might be a good choice, provided you are willing to make minor changes to the code. The modelling interface is very similar to Gurobi and the underlying SCIP solver also supports ...
joni's user avatar
  • 1,477
4 votes
Accepted

Conditional constraints in PuLP

I believe the issue was with the following constraint name: ...
gernworm's user avatar
  • 151
4 votes
Accepted

Violation of specific constraint in Pulp

Introduce linear constraints: $$\sum_{\text{h}} z[\text{h}][\text{driver}] \le 1 \quad\text{for each driver}$$
RobPratt's user avatar
  • 30.5k
4 votes

Scheduling optimisation constraint on consecutive shifts & consecutive night shifts (`python`)

There are certainly different ways of achieving what you want. Here is how I would proceed: Start by predefining the set of all possible schedules which satisfy your constraints $2,3,4,6$. Although ...
Kuifje's user avatar
  • 12.9k
4 votes
Accepted

How to convert static variables into arrays for use with PuLP

Your code is correct, you have used pulp.LpVariable.dicts correctly. For better readability, it is often better to use dictionaries. So the idea is to convert your ...
Kuifje's user avatar
  • 12.9k
4 votes
Accepted

How to generate multiple solutions to linear program in Python?

When I understand your question correctly you are not interested in the full solution space. In that case you can generate alternative optimal solutions by first solving your problem to optimality. ...
SimonT's user avatar
  • 701
4 votes
Accepted

Python Pulp - LpMinimize Not Returning Expected Output - Scheduling Problem

First, it is confusing when you say The final solution does not satisfy the workforce requirements for the various time windows, it's substantially short. Only 5 shifts are filled in total. You do ...
Kuifje's user avatar
  • 12.9k
4 votes

Designing a multi-commodity network flow optimizer

Question 1 You could simply use the priority function as the cost function on the arcs. This way, it is for example cheaper to ship a commodity to $D_1$ from $W_2$ ($1$ unit of cost per unit of flow) ...
Kuifje's user avatar
  • 12.9k
4 votes
Accepted

Subtour elimination implementation (DFJ) using Python (PULP). While loop never exits

In constraint ...
fontanf's user avatar
  • 2,495
4 votes

Any Idea why PuLP is ignoring binary variables?

You need to capitalize the first letter in the cat option: ...
PeterD's user avatar
  • 1,461
3 votes

How to generate multiple solutions to linear program in Python?

Your problem does not have any objective function, so you do not have to use software to solve linear programs here. It is just a system of linear inequalities. (Of course, you still can use LP tools ...
ttnick's user avatar
  • 566
3 votes
Accepted

Advanced Heuristics for MIP vehicle routing problem in PuLP

It is difficult to tell from this information. You need the examine the logs of the solver if your primal bound (how good are the solutions) or dual bound (how good is the relaxation) is not moving as ...
user3680510's user avatar
  • 3,635
3 votes

"Out of the box" Mixed Integer Programming Heuristics

I have some experience in solving large-scale airline crew pairing combinatorial optimization problems (an NP-hard problem) with difficulty similar to vehicle routing problems. Yes, solving such ...
Divyam Aggarwal's user avatar
3 votes

CBC stalling after approximately 10 seconds

CBC does have its fair share of bugs, especially when it comes to proper termination. If you are running in multithreaded mode try running in serial (or vice-versa), and see if that helps. If you are ...
Nikos Kazazakis's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible