Error when trying to generate multiple optimal solutions with CPLEX

Hello. I am trying to find all optimal solutions to a shortest path problem as part of a larger problem. I have two problems loaded, one called ‘main’ and the other called ‘subproblem’. The relevant code is as follows:

option cplex_options 'poolstub=solfile populate=1 poolintensity=4 poolagap=0';
repeat while bestSubobj > -1 * tau and iterationCount < 10 {
	print("Solving main problem");
	option cplex_options 'poolstub=mainsolfile poolcapacity=1';
	problem main;
	solve main;
#Irreleveant code
#Solving to get the correct optimal value
	option cplex_options 'poolstub=unconstrainedsubsolfile poolcapacity=1';
	solve subproblem;
	let optimalLength := Total_Cost;

        #Getting all optimal solutions
	problem subproblem;
	option cplex_options 'poolstub=subsolfile poolcapacity=2100000000 populate=1 poolintensity=4 poolagap=0';	
	solve subproblem;
	print(Current.result);#Put here so I can get a value for a for loop

This generates the following error:

	Bad suffix .npool for subproblem
context:   >>> print(Current.npool) <<< ;
Possible suffix values for subproblem.suffix:
	astatus   exitcode   message   relax
	result    sstatus    stage  

I attempted to fix this error with the following line I found online:

suffix npool OUT;

While this successfully gets it to run, npool is 0, which breaks things. Additionally, cplex options seem to be chosen out of order, as the output is the following:

Solving main problem

CPLEX poolstub=subsolfile
CPLEX optimal integer solution; objective 190
9 MIP simplex iterations
0 branch-and-bound nodes
No basis.

Wrote 1 solution in solution pool
to file subsolfile1.sol.

CPLEX poolstub=mainsolfile
CPLEX optimal solution; objective 190
0 dual simplex iterations (0 in phase I)
Solution determined by presolve;
objective Total_Cost = 190.


The 0 at the end is from print(Current.npool); Could someone help me figure out how to get the correct number of optimal solutions from npool? Thanks!

Setting suffix npool OUT before the loop is the right thing to do here.

The command problem main; makes main the current problem. But also, this command resets all AMPL options to the values that they had the last time that main was the current problem. Thus, in particular, if you want to change cplex_options you should do so after this command:

problem main;
option cplex_options 'poolstub=mainsolfile poolcapacity=1';
solve main;

The same applies to any other problem statements that you have. After this is fixed, you should see the cplex_options settings that you expect.

After the second solve in your example, CPLEX reports “Solution determined by presolve.” It appears that, in this case, no solutions are added to the pool. To work around this, add presolve=0 to your cplex_options string.