IBM ILOG Solver User's Manual > Local Search > Writing a Metaheuristic > Writing a new metaheuristic > Virtual functions of IloMetaHeuristicI |
Virtual functions of IloMetaHeuristicI |
INDEX
![]() |
The virtual functions of IloMetaHeuristicI
, with the exception of reset
and complete
, are called from various Solver goals such as IloStart
and IloNotify
, and are passed an instance of IloSolver
. This instance of IloSolver
is the one executing the Solver goal.
Up to six basic virtual member functions should be defined to implement a metaheuristic. A description of the member functions follows:
IloBool start(IloSolver solver, IloSolution soln); |
The start
method is called to signify to the metaheuristic that soln
is the solution from which moves will be generated. By returning IloFalse
or causing a failure inside this method, you signify that the metaheuristic forbids beginning from soln
.
From the standpoint of our limited tabu metaheuristic, we want to add constraints to ensure that the variable which changed last time keeps its value and that the cost does not vary too much from the best cost value found so far.
IloBool isFeasible(IloSolver solver, IloSolution delta) const; |
The isFeasible
method is used as a fast pre-filter. The suggested change to the solution is delivered in delta
. The move delta
is a move that has been defined by an instance of IloNHood
. If the metaheuristic can ascertain that the application of delta to the solution passed in start
will lead to a solution which is disallowed by the metaheuristic, IloFalse
should be returned. When this happens the neighborhood move can be discarded without the need to instantiate variables of the model.
From the standpoint of our limited tabu metaheuristic, we can look to see if the delta will change the value of our tabu variable. If it will, we can reject this delta by returning IloFalse
.
IloBool test(IloSolver solver, IloSolution delta); |
Whereas isFeasible
is a pre-filter, the test
member function implements a definitive test of the current move with respect to the metaheuristic. When test
is called, all model variables are instantiated, and the metaheuristic can use the solution passed in start
together with the values in the model variables to compute differences.
Alternatively, delta can be used to give the maximum scope of the difference. Not every variable mentioned in delta has necessarily changed value. This can happen when a neighborhood defines a value for a variable in the delta which is the same as the current one.
Be aware that if the metaheuristic is used with the IloTest
goal, which does not take a neighborhood identifier, this method should be robust to delta
being an empty handle.
From the standpoint of our limited tabu metaheuristic, we need only return IloTrue
here, as any tabu or over-costly neighbor will have been rejected by the constraints added in start
Since the default behavior of test
returns IloTrue
, a redefinition of this virtual function is not necessary here.
void notify(IloSolver solver, IloSolution delta); |
The notify
method is called when a move is about to be accepted, but before the solution passed in start
is actually stored. This call makes it possible for the metaheuristic to update some internal data structures that will change its behavior at the next move.
Be aware that if the metaheuristic is used with the IloNotify
goal which does not take a solution reference, this method should be robust to delta
being an empty handle.
From the standpoint of our limited tabu metaheuristic, we store the variable whose value has changed, so that it can be made tabu at the next move.
IloBool complete(); |
When no moves could be taken the last time the neighborhood was explored, the complete
member function is called. Its job is to decide whether the metaheuristic should indicate that it wants to give up search (by returning IloTrue
), or keep going (by returning IloFalse
).
From the standpoint of our limited tabu metaheuristic, we could try relaxing the tabu condition to see if this would allow a move on the next iteration, and return IloFalse
. If the condition is already relaxed, we could return IloTrue
.
void reset(); |
Subclasses of IloMetaHeuristicI
often have some memory so that their behavior can be modified from move to move. The reset
member function should reset any such internal structure. From the standpoint of our limited tabu metaheuristic, we remove the tabu condition.
© Copyright IBM Corp. 1987, 2009. Legal terms. | PREVIOUS NEXT |