IBM ILOG Solver User's Manual > Evolutionary Algorithms > Modeling and Solving a Basic EA Problem > Creating an initial solution pool |
Creating an initial solution pool |
INDEX
![]() |
In this section, you will learn how to:
Make a copy of the example file YourSolverHome/examples/src/tutorial/ea1max_init_partial.cpp
and open this copy in your development environment. This file is a program that is only partially completed. You will fill in the blanks in each step in this section. At the end of the section, you will have completed the example and you can compile and run the program.
The main routine starts by parsing command line parameters for the problem size and the population size. You declare an IloEnv
object used for allocation followed by a "try/catch" block to trap possible exceptions which may occur within the function body execution.
Step 1 - | Parse command line parameters |
Add the following code after the comment //Parse command line parameters
Next, you build a Concert model of the "one max" problem. You declare an instance of IloModel
. Then, you declare an IloBoolVarArray
of bits. You constrain the count
integer variable to be the sum of the binary digits in the bits
array. The count
variable has a lower bound of 0 for an array composed entirely of 0's and an upper bound of 50 for an array composed entirely of 1's.
Step 2 - | Create the model |
Add the following code after the comment //Create the model
As all generated solutions must contain the variable array you just modeled, you define a solution prototype. This prototype is a template for all solutions that will be placed in the initial population. Internally, unique solutions will be generated by cloning this prototype and storing the solver's state. You also define the objective function, which is to maximize the count
variable. This addition is useful when solutions are to be compared or sorted.
Step 3 - | Create the solution prototype |
Add the following code after the comment //Create the solution prototype
IloSolution prototype(env);
prototype.add(bits);
IloObjective obj = IloMaximize(env, count, "Obj");
prototype.setObjective(obj);
You will make use of a factory of operators which operate over an array of decision variables specified to the factory. This factory process simplifies the definition of standard operators as the factory has access to certain common parameters, for example, the solution prototype.
Here, you use an operator which randomizes the values of the variables specified in the constructor of the factory, in order to generate a random population. This operator will be called until the number of solutions is equal to the desired population size. Solver verifies the legality of each solution by generating the solutions in a goal search which is backtracked each time a solution is produced. The fail limit specified is applied to the generation of each solution, meaning that the effort to generate each solution is limited. If a solution is not generated within this limit, this small subsearch is abandoned, and the generation loop reiterated.
Step 4 - | Initialize the population |
Add the following code after the comment //Initialize the population
You can then display the solution pool's content.
Step 5 - | Display the population |
Add the following code after the comment //Display the population
env.out() << "INITIAL POPULATION " << population << endl;
Finally, the routine's "try/catch" block as well as its body are closed. This code is provided for you:
} catch(IloException ex) { env.out() << "Caught: " << ex << endl; } env.end(); return 0; } |
You have now completed the model of the "one max" problem and created the initial solution pool. In the next section, you will learn how to write a simple generation loop.
Step 6 - | Compile and run the program |
Compile and run the program. You should get the following results:
The complete program is available in the YourSolverHome/examples/src/ea1max_init.cpp
file.
© Copyright IBM Corp. 1987, 2009. Legal terms. | PREVIOUS NEXT |