I am working on my thesis about a variant form of Vehicle routing problem (VRP) using a linear mathematical programming approach. I have a well-tested model that I formulated but this model is solved in an acceptable computational time for at most 30 nodes, so I need to implement some metaheuristics to find good feasible solutions for bigger instances, so here is the question. I know that I can generate some solutions using a python-cplex command solution_pool (something like that) so I would like help to know how to generate and access to these solutions (objective function value, decision variables values, etc) my model is a cplex object Model. I know that this is possible if you could help me it would be great. Thanks in advance and greetings from Chile.
Asked
Active
Viewed 948 times
2 Answers
4
Once you have your cpx object you may write
cpx.populate_solution_pool()
numsol = cpx.solution.pool.get_num()
print("The solution pool contains %d solutions." % numsol)
meanobjval = cpx.solution.pool.get_mean_objective_value()
sol_pool = []
for i in range(numsol):
objval_i = cpx.solution.pool.get_objective_value(i)
x_i = cpx.solution.pool.get_values(i)
nb_vars=len(x_i)
sol = []
for k in range(nb_vars):
sol.append(x_i[k])
sol_pool.append(sol)
print("pools =",sol_pool)

halfer
- 19,824
- 17
- 99
- 186

Alex Fleischer
- 9,276
- 2
- 12
- 15
-
Thanks, it worked, but I have a doubt, for example in my model I have different types of variables, for example for an MTZ formulation of the Traveling Salesman Problem, the model has x[i,j] and u[i] variables, so I would like to separate the vector x_i in your example to identify more clearly the value of both type of decision variables. Is it that even possible? sorry but I am new in all this stuff. – Hctor Alonso Hormazbal Vildsol May 27 '19 at 05:31
-
1Then for k in range(nb_vars): sol.append([cpx.variables.get_names(k),x_i[k]]) – Alex Fleischer May 27 '19 at 08:43
1
The solution in the solution pool are available in the Cplex.solution.pool
attribute, see the reference documentation here.
CPLEX by default saves any feasible solution it finds in the solution pool, so you don't have to do anything specific to create those solutions. However, since you are not after proving optimality but want to see good solutions fast, you may want to play with some parameters:
- Setting Cplex.parameters.emphasis to 4 may produce better solutions faster
- There are some more ideas in the manual in the chapter about filling the solution pool. You may want to look at the polishing procedure and/or at
Cplex.populate_solution_pool()
.

Daniel Junglas
- 5,830
- 1
- 5
- 22