Data Structures and Algorithms with Object-Oriented Design Patterns in C#
next up previous contents index

Abstract Solvers

Program gif defines the AbstractSolver class. The AbstractSolver class implements the Solver interface defined in Program gif. The AbstractSolver class contains two fields, bestSolution and bestObjective, two concrete methods, UpdateBest and Solve and the abstract method Search. Since Search is an abstract method, its implementation must be given in a derived class.

   program32501
Program: AbstractSolver class.

The Solve method does not search the solution space itself--it merely sets things up for the Search method. It is the Search method, which is provided by a derived class, that does the actual searching. When Search returns it is expected that the bestSolution field will refer to the best solution and that bestObjective will be the value of the objective function for the best solution.

The UpdateBest method is meant to be called by the Search method as it explores the solution space. As each complete solution is encountered, the UpdateBest method is called to keep track of the solution which minimizes the objective function.


next up previous contents index

Bruno Copyright © 2001 by Bruno R. Preiss, P.Eng. All rights reserved.