0

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?

ma7555
  • 362
  • 5
  • 17

1 Answers1

1

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.

Erwin Kalvelagen
  • 15,677
  • 2
  • 14
  • 39
  • Yeah, I saw these lines too when the solver started and thought it must have optimized the model as you said in the presolve phase. I have 0 experience with cplex/pyomo so wanted to be sure I am not making things worse thanks for your answer I will start the solving... – ma7555 Dec 27 '19 at 03:08
  • 1
    Just to add to what Erwin said, we have used this approach quite extensively for testing some meta-heuristic ideas. For example a problem might have maybe 100,000 variables and 200,000 constraints, and we were trying stuff like fixing the values of maybe 95% of the model variables from a known feasible solution so we could explore the neighbourhood around that solution. We did this by adding e.g. 95,000 extra constraints to fix the values of most of the variables. In cases like these, CPLEX pre-solve takes almost all the variables out of the problem, and the result can be solved quickly. – TimChippingtonDerrick Dec 27 '19 at 13:34