ma7555
ma7555

Reputation: 400

Pyomo Integer Programming - Setting specific variables to fixed numbers heurestically

Using pyomo/cplex:

Suppose I have a cost function that takes 25 integers to be solved, each integer could be from (0 to 4)

The real model is more complex than this but I am trying to minimize the idea.

model.x = Var(range(25), range(5), domain=Binary, initialize=0)

for i in range(25):
    model.constraint.add(sum([model.x[i, j] for j in range(5)]) == 1)

Suppose I found using different logical approach that integer 0, 1, 2 should be equal to 4. What I did is that I set a constraint as follows:

model.constraint.add(model.x[0, 4]) == 1
model.constraint.add(model.x[1, 4]) == 1
model.constraint.add(model.x[2, 4]) == 1

my idea is that I want to set pre-defined integers to fixed solutions that I found by other means to speed up the computation time. However, I have read that by adding more constraints you should take more time to reach solutions.

Can someone with experience provide me with a good opinion if there is a better approach?

Upvotes: 0

Views: 556

Answers (1)

Erwin Kalvelagen
Erwin Kalvelagen

Reputation: 16724

Don't worry. Cplex will presolve this away. These variables will be removed from the model before Cplex starts iterating.

The Cplex log will show some messages about how successful the presolve was. You should see messages like:

MIP Presolve eliminated 497 rows and 497 columns.
MIP Presolve modified 8530 coefficients.
Reduced MIP has 8556 rows, 8915 columns, and 34502 nonzeros.
Reduced MIP has 8915 binaries, 0 generals, 0 SOSs, and 0 indicators.

This will show how much smaller the model has become after the presolve phase.

If you generate a ton of these singleton constraints, it may be more efficient to specify bounds. This can save some time for Pyomo generating the model. In many cases this is not something to really worry about, and using bounds instead of constraints is more a question of taste.

If Cplex can eliminate large parts of the model, it is sometimes useful to inspect the model and see if the model is really larger than needed.

Of course, it may be better to use integer variables directly than a series of binary variables. I assume there is a good reason to use these binary variables.

Upvotes: 1

Related Questions