IBM ILOG Solver User's Manual > Evolutionary Algorithms > Introduction and Basic Concepts > Features of the library > Evaluating, Comparing, and Selecting Solutions |
Evaluating, Comparing, and Selecting Solutions |
INDEX
![]() |
During the operation of EAs, evaluation, comparison and selection of solutions are fundamental operations. In Solver IIM's EA framework, these operations are carried out by specializations of the template classes IloEvaluator
, IloComparator
and IloSelector
. Selection of solutions is essential for the implementation of EAs as normally better quality solutions are favored for breeding as parents, and likewise poorer solutions tend to be selected as candidates for replacement. The operations of solution comparison and evaluation are often sub-ordinate to those of selection. Evaluators can give the quality of solutions in various different ways, whereas comparators can make pair-wise comparisons of solutions based on one or more different evaluations.
The most obvious evaluation of a solution, is simply the value of the objective function, but other equally simple evaluations are possible, such as the value of a particular variable. The functions IloSolutionEvaluator
return different types of IloEvaluator<IloSolution>
which evaluate either the objective value of a solution, or the value of one of its variables. More complex evaluators can then be built using the available arithmetic operators on evaluators. You can also write a particular custom evaluation from scratch using the macro ILOEVALUATOR
. Below is a code which creates an evaluator which evaluates the profit of a particular solution:
Evaluations can be used to compare two solution objects, but a more general way exists which does not depend on the two solutions being compared having a unique evaluation. This second method uses a comparator object, and more specifically, an instance of IloComparator<IloSolution>
. Comparators are the basic objects used to sort solution pools, as well as perform certain EA selection operations such as tournament selection, which will be covered later in this chapter. The following code sample shows how to sort a population in decreasing order of profit. The member function makeGreaterThanComparator
is used to convert an evaluator into a comparator which prefers higher evaluations.
population.sort(eval.makeGreaterThanComparator()); IloSolution bestSolution = population.getSolution(0); |
The population could have been sorted in increasing order of profit by making use of makeLessThanComparator
. Alternatively, solution pools can store the manner in which they are to be sorted, and so the following is a (nearly) equivalent code. The difference is that afterwards, the population can be sorted in decreasing profit order via a simple call to IloSolutionPool::sort()
.
population.setSortComparator(eval.makeGreaterThanComparator()); population.sort(); IloSolution bestSolution = population.getSolution(0); |
More complicated comparisons can be created by composing simpler comparisons. For example, assume that, for equivalent profit, you prefer a solution which has a lower cost. This can be achieved by using a lexicographic comparison, when compares two objects on ordered criteria. If a particular criterion cannot distinguish if one solution is better than another, than this job falls to the next criterion on the list. The following code shows you how to create a comparator which prefers solutions of higher profit, but when profits are equal, those of lower cost.
Both solution evaluations and comparisons can be used as a basis for solution selection, which is an important part of evolutionary algorithms. The two most common places where you will select solutions are first, to choose parent solutions, and second to choose solutions that the new offspring will replace in the population. Some common selection methods supplied with the Solver IIM EA framework are random selection, tournament selection and roulette wheel selection. The first method, as the name suggests, selects solutions in an unbiased random fashion. The second uses a comparator in order to select solutions which tend to be better (or worse) than average. The third uses an evaluator to weight the probability of selection using the evaluation. To selector a random solution from a solution pool, you would create a random selector as below.
IloRandomSelector<IloSolution, IloSolutionPool> selector(env); |
You could then use this selector to select a solution as follows:
IloSolution selectedSolution; IloBool ok = selector.select(selectedSolution, population); |
Although the usage described above is completely valid, normally you will delegate the call of the selector to other objects called solution pool processors, which will be discussed soon. At the same time, you will also become familiar with more complex selectors, such as the tournament selector.
© Copyright IBM Corp. 1987, 2009. Legal terms. | PREVIOUS NEXT |