IBM ILOG Solver User's Manual > The Basics > Searching with Predefined Goals: Magic Square > Suggested answers > Exercise 3 |
Exercise 3 |
INDEX
![]() |
Use the magic square code that you just wrote and experiment with changing the order in which variables are bound in the solution search. Note how the number of fails, number of choice points, and elapsed time since creation change as you try the following parameters for the goal IloGenerate
: the default (IloChooseFirstUnboundInt
), IloChooseMinSizeInt
, IloChooseMaxSizeInt
, IloChooseMinMinInt
, IloChooseMaxMinInt
, IloChooseMinMaxInt
, and IloChooseMaxMaxInt
.
To do this, write a line of code for each IloGenerate
goal, using the default and the six other parameters. Comment out all the goals except for the one you are testing. Then comment out that goal and test another.
Results will vary widely depending on the strategy you choose. In the results provided in the following sections, using the parameter IloChooseMinSizeInt
solved the problem the most quickly, in less than one tenth of a second. Solving the problem using the parameter IloChooseMaxSizeInt
took over 16 minutes. These results vividly demonstrate the importance of parameter choice for the goal IloGenerate
. The results may vary depending on platform, machine, configuration, and so on.
The code that has changed from magicsq.cpp
follows. You can view the complete program online in the file YourSolverHome/examples/src/magicsq_ex3.cpp
.
You should get the following results, though the information displayed by IloSolver::printInformation
will vary depending on platform, machine, configuration, and so on.
//Feasible Solution using IloGoal goal = IloGenerate(env, square); 1 2 13 24 25 3 22 19 6 15 23 16 10 11 5 21 7 9 20 8 17 18 14 4 12 Number of fails : 5486 Number of choice points : 5497 Number of variables : 25 Number of constraints : 13 Reversible stack (bytes) : 8064 Solver heap (bytes) : 24144 Solver global heap (bytes) : 4044 And stack (bytes) : 4044 Or stack (bytes) : 4044 Search Stack (bytes) : 4044 Constraint queue (bytes) : 11152 Total memory used (bytes) : 59536 Elapsed time since creation : 0.371 //Feasible Solution using IloGoal goal = IloGenerate(env, square, IloChooseMinSizeInt); 1 2 13 24 25 3 23 17 6 16 20 21 11 8 5 22 4 14 18 7 19 15 10 9 12 Number of fails : 791 Number of choice points : 799 Number of variables : 25 Number of constraints : 13 Reversible stack (bytes) : 8064 Solver heap (bytes) : 20124 Solver global heap (bytes) : 4044 And stack (bytes) : 4044 Or stack (bytes) : 4044 Search Stack (bytes) : 4044 Constraint queue (bytes) : 11152 Total memory used (bytes) : 55516 Elapsed time since creation : 0.09 //Feasible Solution using IloGoal goal = IloGenerate(env, square, IloChooseMaxSizeInt); 1 2 24 21 17 3 16 12 11 23 25 18 13 5 4 22 10 7 20 6 14 19 9 8 15 Number of fails : 15650718 Number of choice points : 15650729 Number of variables : 25 Number of constraints : 13 Reversible stack (bytes) : 12084 Solver heap (bytes) : 28164 Solver global heap (bytes) : 4044 And stack (bytes) : 4044 Or stack (bytes) : 4044 Search Stack (bytes) : 4044 Constraint queue (bytes) : 11152 Total memory used (bytes) : 67576 Elapsed time since creation : 997.564 //Feasible Solution using IloGoal goal = IloGenerate(env, square, IloChooseMinMinInt); 1 2 24 21 17 3 16 12 11 23 25 18 13 5 4 22 10 7 20 6 14 19 9 8 15 Number of fails : 1325537 Number of choice points : 1325548 Number of variables : 25 Number of constraints : 13 Reversible stack (bytes) : 12084 Solver heap (bytes) : 24144 Solver global heap (bytes) : 4044 And stack (bytes) : 4044 Or stack (bytes) : 4044 Search Stack (bytes) : 4044 Constraint queue (bytes) : 11152 Total memory used (bytes) : 63556 Elapsed time since creation : 97.169 //Feasible Solution using IloGoal goal = IloGenerate(env, square, IloChooseMaxMinInt); 1 2 13 24 25 3 23 17 6 16 20 21 11 8 5 22 4 14 18 7 19 15 10 9 12 Number of fails : 849 Number of choice points : 859 Number of variables : 25 Number of constraints : 13 Reversible stack (bytes) : 8064 Solver heap (bytes) : 20124 Solver global heap (bytes) : 4044 And stack (bytes) : 4044 Or stack (bytes) : 4044 Search Stack (bytes) : 4044 Constraint queue (bytes) : 11152 Total memory used (bytes) : 55516 Elapsed time since creation : 0.1 //Feasible Solution using IloGoal goal = IloGenerate(env, square, IloChooseMinMaxInt); 1 2 13 24 25 3 23 19 4 16 22 15 10 12 6 21 8 9 20 7 18 17 14 5 11 Number of fails : 612 Number of choice points : 623 Number of variables : 25 Number of constraints : 13 Reversible stack (bytes) : 8064 Solver heap (bytes) : 16104 Solver global heap (bytes) : 4044 And stack (bytes) : 4044 Or stack (bytes) : 4044 Search Stack (bytes) : 4044 Constraint queue (bytes) : 11152 Total memory used (bytes) : 51496 Elapsed time since creation : 0.09 //Feasible Solution using IloGoal goal = IloGenerate(env, square, IloChooseMaxMaxInt); 1 2 13 24 25 3 22 19 6 15 23 16 10 11 5 21 7 9 20 8 17 18 14 4 12 Number of fails : 9020 Number of choice points : 9029 Number of variables : 25 Number of constraints : 13 Reversible stack (bytes) : 12084 Solver heap (bytes) : 24144 Solver global heap (bytes) : 4044 And stack (bytes) : 4044 Or stack (bytes) : 4044 Search Stack (bytes) : 4044 Constraint queue (bytes) : 11152 Total memory used (bytes) : 63556 Elapsed time since creation : 0.601
© Copyright IBM Corp. 1987, 2009. Legal terms. | PREVIOUS NEXT |