I have this cplex model that has 1 binay variable (x_i). Now I have 2 questions regarding its cplex solutions (I put them in one post because they are related).
First: For my model I get 26 solutions but I know in reality there are much more solutions.How solutions are being generated in cplex? Is there any way to increase the number of solution?
Second: I want to access all of the solutions with a solution pool but when I am trying to print all the solutions, It prints all the existing variables(obviously I just need the variables that are equal to 1) with their value.
This is my code for the solution pool:
def generate_soln_pool(mdl):
cpx = mdl.get_cplex()
cpx.solnpoolintensity=4
cpx.solnpoolagap=0
cpx.populatelim=100000
try:
cpx.populate_solution_pool()
except CplexSolverError:
print("Exception raised during populate")
return []
numsol = cpx.solution.pool.get_num()
print(numsol)
nb_vars = mdl.number_of_variables
sol_pool = []
for i in range(numsol):
x_i = cpx.solution.pool.get_values(i)
assert len(x_i) == nb_vars
sol = mdl.new_solution()
for k in range(nb_vars):
vk = mdl.get_var_by_index(k)
sol.add_var_value(vk, x_i[k])
sol_pool.append(sol)
return sol_pool
bm=CModel()
pool = generate_soln_pool(bm)
for s, sol in enumerate(pool,start=1):
print(" this is solution #{0} of the pool".format(s))
sol.display()
This is a part of my output:
x_0 = 0
x_1 = 0
x_2 = 0
x_3 = 0
x_4 = 0
x_5 = 0
x_6 = 0
x_7 = 0
x_8 = 0
x_9 = 0
x_10= 0
x_11 = 1
x_12 = 0
x_13 = 0
.
.
.