15
votes
How can we write a binary variable as a power to a constant number?
If you check the two cases for $x_{i,j}$, you will see that you can rewrite the expression as a linear function of $x_{i,j}$:
$x_{i,j}=0$ yields $1-0.3^0=0$
$x_{i,j}=1$ yields $1-0.3^1=0.7$
So $1-0....
7
votes
Python to Excel
A great option is to use the pandas library, and specifically pandas.DataFrame.to_excel is what you need.
I suggest you use one column per variable index, and one line per non zero variable.
Here is ...
6
votes
Accepted
VRPTW implementation
Before implementing anything, you need to understand the equations. A good approach is to think in terms of resources. When handling capacity constraints, you are dealing with a load resource which is ...
5
votes
Accepted
CPLEX Python API Manual with References
Do you want the matrix oriented python API or docplex API ?
For docplex, some very simple examples at https://www.linkedin.com/pulse/making-optimization-simple-python-alex-fleischer/
5
votes
Accepted
5
votes
How to collect solutions within CPLEX and retrieve them from PYOMO?
It seems you should take a look at the solution pool feature in CPLEX. This allows you to collect multiple solutions during the branch and bound search and to examine these solutions afterwards. I don'...
4
votes
Accepted
4
votes
Python to Excel
I have used openpyxl several times to create or alter excel files. It is quite easy if one is familiar with Python.
With this module you can iterate through your variables and write its value to a ...
4
votes
Accepted
GAMS default Solver doesn't use much of my RAM and CPU
As @ErwinKalvelagen pointed out: by default gams cplex uses only 1 thread which results in a low usage of the pc ressources.
In order to change this one has to increase the thread number so that ...
4
votes
Accessing Lagrange Multipliers in CPLEX
From the official CPLEX documentation here (CPLEX 20.1): SolutionInterface.get_dual_values() does indeed return the Lagrange/dual values.
4
votes
Accepted
Sensitivity analysis for specific sets of constraints on DoCplex
You can filter the results you get from sensitivity.rhs :
See small example out of the zoo example again:
...
3
votes
Accepted
Can a logical expression be added to the objective function of a model in docplex?
We can use a "big M" approach, assuming that you can find a positive constant $M$ such that $\vert y_{jk}-y_{ik} \vert \le M$ for all $k\in K$ and $(i,j)\in V.$
Introduce new binary ...
3
votes
Dual problem in IBM CPLEX
If the primal LP problem suffers from degeneracy, I believe dual simplex may be faster. You might try using the barrier method to solve the (primal) LP. In cases where the LP has degeneracy issues, I ...
3
votes
Accepted
How can we write a binary variable as a power to a constant number?
Suppose it is needed to linearize the expression $Z=P^U$. It can be written as $$Z=U\times P+1-U$$
where $U$ is a binary variable and $P$ is a parameter. This is a general formulation for calculating $...
3
votes
Accessing Lagrange Multipliers in CPLEX
First of all, you should determine the sign of the multipliers based on the objective function direction and how the complicating constraints are violated. Then you have to use a standard method like ...
3
votes
Getting all active constraints of an LP from Cplex
Just look at the basis status of the rows. Non-basic means binding.
3
votes
GAMS default Solver doesn't use much of my RAM and CPU
This analogy might help: CPU usage is like the power output of an engine - more is better in terms of performance. Memory usage is more like the heat produced by the engine - too much heat, aka memory ...
3
votes
Implementing NLP as QP on docplex
The error message suggests that you tried to access the solution before solving the model. At the point that mdl.maximize(profit) is executed, you have constructed your model, but you have not solved ...
2
votes
Binary variables with multiple indices
You can create a binary decision variable as:
from docplex.mp.model import Model
m = Model(...)
my_var = m.binary_var("name_of_this_var")
The variable is ...
2
votes
Objective value estimate for branches I create in Cplex
Since
branching rules are crucial for the performance of solvers they are
also a very well-guarded secret. I can say from experience that some
form of reliability branching is sufficient to get a ...
2
votes
Using CPLEX academic version with Pyomo on MacOS
One of the following will probably solve the problem:
Add Cplex to the system Path in your laptop
add executable= to the Solver factory:
solver = SolverFactory(...
2
votes
Accepted
Modifying and re-optimizing a model using CPLEX Python API
You can do incremental changes
https://github.com/AlexFleischerParis/zoodocplex/blob/master/zooincremental.py
...
1
vote
Using CPLEX academic version with Pyomo on MacOS
To run CPLEX on MacOS use the code:
solver = SolverFactory('cplex', executable = '/Applications/CPLEX_Studio2211/cplex/bin/x86-64_osx/cplex')
1
vote
Updating constraint set rhs in docplex
I think the method you pointed out would be as follows:
...
1
vote
Modifying and re-optimizing a model using CPLEX Python API
Now with the CPLEX Matrix API you can do the same kind of changes of course.
Let me start with the example from
https://medium.com/@alexfleischer_84755/optimization-simply-do-more-with-less-zoo-buses-...
1
vote
How to do matrix multiplication in docplex in python?
I think you can try something like this list(w.values()) , because continuous_var_matrix returns a dictionary of continuous_var, just convert it to list, and it ...
1
vote
How to iterate a parameter set in docplex model?
See example in easy optimization with python
...
1
vote
Python to Excel
There are both pandas and openpyxl recommendations here. In my experience, if you want to go read and write on the cell level, or do more than basic analysis, use Pandas. Use openpyxl If you want to ...
1
vote
Accepted
Benders implementation on Cplex is very slow
If all the cuts you generate have an impact (i.e., you don't generate cuts that are rendered redundant by other cuts), then at least some of the reason that adding a bunch of cuts at once is faster ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
cplex-python-api × 28cplex × 18
python × 13
docplex × 8
optimization × 5
pyomo × 5
mixed-integer-programming × 2
integer-programming × 2
solver × 2
nonlinear-programming × 2
branch-and-bound × 2
linear-programming × 1
reference-request × 1
combinatorial-optimization × 1
vehicle-routing × 1
or-tools × 1
binary-variable × 1
quadratic-programming × 1
network-flow × 1
graphs × 1
benders-decomposition × 1
facility-location × 1
assignment-problem × 1
ampl × 1
gams × 1