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....
RobPratt's user avatar
  • 29.7k
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 ...
Kuifje's user avatar
  • 12.8k
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 ...
Kuifje's user avatar
  • 12.8k
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'...
Sune's user avatar
  • 6,212
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/
Alex Fleischer's user avatar
5 votes
Accepted

CPLEX Python API

with the cplex docplex API you may write ...
Alex Fleischer's user avatar
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.
Kuifje's user avatar
  • 12.8k
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 ...
user9151's user avatar
  • 557
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 ...
Eddiee's user avatar
  • 533
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: ...
Alex Fleischer's user avatar
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 ...
prubin's user avatar
  • 37.4k
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 $...
Optimization team's user avatar
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 ...
mattmilten's user avatar
  • 1,538
3 votes

Getting all active constraints of an LP from Cplex

Just look at the basis status of the rows. Non-basic means binding.
Erwin Kalvelagen's user avatar
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 ...
A.Omidi's user avatar
  • 8,165
3 votes
Accepted

Implementing NLP as QP on docplex

Within docplex I would use cpoptimizer and write ...
Alex Fleischer's user avatar
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 ...
prubin's user avatar
  • 37.4k
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 ...
Joris Kinable's user avatar
2 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 ...
prubin's user avatar
  • 37.4k
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 ...
Alex Fleischer's user avatar
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 ...
A.Omidi's user avatar
  • 8,165
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(...
Oguz Toragay's user avatar
  • 8,567
1 vote

Updating constraint set rhs in docplex

I think the method you pointed out would be as follows: ...
A.Omidi's user avatar
  • 8,165
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-...
Alex Fleischer's user avatar
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')
Maria Chedzoy's user avatar
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 ...
poig's user avatar
  • 111
1 vote

How to iterate a parameter set in docplex model?

See example in easy optimization with python ...
Alex Fleischer's user avatar
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 ...
WAHISHON's user avatar
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 ...
prubin's user avatar
  • 37.4k

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