EasyLocal++: An Object-Oriented Framework for ... - Semantic Scholar

15 downloads 3272 Views 227KB Size Report
Email: [email protected]. 1 Introduction ... Furthermore, the framework can easily be customized by an expert user allowing the development .... figure, templates which are shared by a hierarchy of classes are shown only on the base class. In.
MIC’2001 - 4th Metaheuristics International Conference

287

EasyLocal++: An Object-Oriented Framework for the Design of Local Search Algorithms and Metaheuristics Luca Di Gaspero∗





1

Andrea Schaerf†

Dipartimento di Matematica e Informatica — Universit` a degli Studi di Udine via delle Scienze, 206 — I–33100 Udine, Italy Email: [email protected]

Dipartimento di Ingegneria Elettrica, Gestionale e Meccanica — Universit` a degli Studi di Udine via delle Scienze, 208 — I–33100 Udine, Italy Email: [email protected]

Introduction

Local search is an optimization paradigm based on the idea of navigating the search space by iteratively stepping from one solution to one of its “neighbors”, which are obtained by applying a simple local change to it. In spite of this simple schema, several control strategies for local search are described in the literature, and new algorithms are regularly proposed. Differently from other search paradigms (e.g., branch & bound) no widely-accepted software tool is available up to now for local search; but only a few research-level prototypes have gained limited popularity. In our opinion, the reason for this lack is twofold: On the one hand, the apparent simplicity of local search induces the users to build their applications from scratch. On the other hand, the rapid evolution of local search metaheuristics seems to make impractical the development of general tools. We believe that the use of object-oriented (O-O) frameworks can help in overcoming this problem. A framework is a special kind of software library, which consists of a hierarchy of abstract classes. The user defines suitable derived classes, which implement the virtual functions of the framework ones. Frameworks are characterized by the inverse control mechanism for the communication with the user code: The functions of the framework call the user-defined ones, and not the other way round. Therefore, a framework provides the full control structure of the invariant part of the algorithms, and the user has only to supply the problem-specific details. In this paper we present EasyLocal++, an object-oriented framework that can be used as a general tool for the development of local search algorithms in C++. The basic idea of EasyLocal++ is to capture the essential features of most local search metaheuristics, and their possible compositions. This allows the user to address the design and implementation issues of new heuristics in a more principled way. Furthermore, the framework can easily be customized by an expert user allowing the development of new metaheuristics, and its architecture fully supports the reuse of code. Porto, Portugal, July 16-20, 2001

288

2

MIC’2001 - 4th Metaheuristics International Conference

Local search basics

Local search is a family of general-purpose techniques for search and optimization problems. These techniques are non-exhaustive in the sense that they do not guarantee to find a feasible (or optimal) solution, but they search non-systematically until a specific stop criterion is satisfied. In details, given an instance p of a problem P , we associate a search space S to it. Each element s ∈ S corresponds to a potential solution of p, and is called a state of p. Local search relies on a function N (depending on the structure of P ) which assigns to each s ∈ S its neighborhood N (s) ⊆ S. Each state s ∈ N (s) is called a neighbor of s. A local search algorithm starts from an initial state s0 and enters a loop that navigates the search space, stepping from one state si to one of its neighbors si+1 . The neighborhood is usually composed by the states that are obtained by some local changes (called moves) from the current one. Local search metaheuristics are built upon the abstract local search algorithm reported in Figure 1(a); they differ from each other according to the strategy they use to select the move in each state, to accept it , and to stop the search (encoded in the SelectMove, AcceptMove and StopSearch functions, respectively). In all techniques, the search is driven by a cost function f that estimates the quality of the state. The most common local search metaheuristics are hill climbing, simulated annealing, and tabu search (see, e.g., [1] for a detailed review). One attractive property of the local search paradigm is that different techniques can be combined and alternated to give rise to complex algorithms. An example of a simple mechanism for combining different techniques and/or different neighborhood relations is what we call the token-ring strategy: Given an initial state and a set of basic local search techniques, the token-ring search makes circularly a run of each technique, always starting from the best solution found by the previous one. The search stops when no improvement is obtained by any algorithm in a fixed number of rounds. In the case of two techniques the strategy is also called tandem search.

3

The EasyLocal++ architecture

The core of EasyLocal++ is composed by a set of cooperating classes that take care of different aspects of local search. The user’s application is obtained by writing derived classes for a selected subset of the framework ones. Such user-defined classes contain only the specific problem description, but no control information for the algorithm. In fact, the relationships between classes, and their interactions by mutual method invocation, are completely dealt with by the framework. EasyLocal++ relies on a few “Design Patterns” [8], which are abstract structures of classes, commonly present in O-O systems, that have been precisely identified and classified. The framework is based on two of them, namely the “Template Method”, to specify and implement the invariant parts of various search algorithms, and the “Strategy Method”, for the communication between the main solver procedure LocalSearch; begin s0 := InitialSolution(); i := 0; while (¬StopSearch(si , i)) do begin m := SelectMove(si , f, N ); if (AcceptableMove(m, si , f )) then si+1 := si ⊕ m; i := i + 1 end end;

template void MoveRunner::Go() { InitializeRun(); while (!StopSearch()) { SelectMove(); if (AcceptableMove()) MakeMove(); UpdateIterationCounter(); } }

(a) The abstract local search algorithm

(b) The EasyLocal++ abstract algorithm

Figure 1: The abstract local search algorithm and the companion EasyLocal++ procedure Porto, Portugal, July 16-20, 2001

MIC’2001 - 4th Metaheuristics International Conference

289

and its component classes. The classes of the framework are split in four categories, and are organized in a hierarchy of abstraction levels as shown in Figure 2(a). Each layer of the hierarchy relies on the services supplied by lower levels and provides a set of more abstract operations, as we are going to describe. The problem representation belongs to the lowest level of the hierarchy and must be defined in terms of a set of basic data classes (computing capabilities are not required). They maintain the states of the search space, the moves, and the input/output data. The local search problem is then embodied in what we call helpers. These classes perform actions related to some specific aspects of the search. For example, what we call NeighborhoodExplorer is responsible for everything concerning the neighborhood: selecting the move, updating the current state by executing a move, and so on. Different NeighborhoodExplorers may be defined in case of composite search, each one handling a specific neighborhood relation used by the algorithm. Helpers cooperate among themselves: For example, the NeighborhoodExplorer is not responsible for the computation of the cost function, and delegates this task to the StateManager which handles the attributes of each state. Helpers do not have their own internal data, but they work on the internal state of the runners, and interact with them through function parameters. Runners represent the algorithmic core of the framework. They are responsible for performing a run of a local search metaheuristic, starting from an initial state and leading to a final one. Each runner has many data objects for representing the state of the search (current state, best state, current move, number of iterations, . . . ), and it maintains links to all the helpers, which are invoked for performing problem-related tasks on its own data. Thanks to the late-binding mechanism, runners can completely abstract from the problem description and delegate these tasks to user-supplied classes which comply to a predefined interface. This allows to describe metaheuristics through incremental specification: For example, we can directly translate the abstract local search algorithm in the EasyLocal++ code presented in Figure 1(b). Then, in order to specify an actual metaheuristic, we have only to define the strategy for move selection and acceptance (through the SelectMove() and AcceptableMove() functions, respectively), and the criterion for stopping the search (by means of the and StopSearch() function). Several common metaheuristics have already been implemented in EasyLocal++; e.g., Hill Climbing, Simulated Annealing and Tabu Search. The highest abstraction level is constituted by the solvers, which represent the external software layer of EasyLocal++. Solvers control the search by generating the initial solutions, and deciding how, and in which sequence, runners have to be activated (e.g., tandem, multistart, hybrid search). This allows, for instance, to implement the token-ring strategy described before, or to design new combinations of basic metaheuristics and/or hybrid methods. In addition, solvers communicate with the external environment, by getting the input and delivering the output, and they are linked to one or more runners and to some of the helpers. The main classes that compose the core of EasyLocal++ are presented in Figure 3 using the UML notation [3]. The data classes, shown in small dashed boxes, are supplied to the other classes as

Solvers Input

Simple Solver

Token-ring Solver

...

Hill Climbing

Tabu Search

Simulated Annealing

Local Search solving strategy

Runners

Helpers

Input

State manager

State

Neighborhood explorer

Move

...

Output

Local Search meta-heuristic

State

Graph

Local Search problem

Basic Data

(a) EasyLocal++ abstraction levels

EasyLocal++

Neighborhood Move Explorer - FirstMove() - BestMove() - SampleMove() - BestNonTabuMove()

User Application

Coloring

RecolorExplorer Recolor - MakeMove() - RandomMove() - NextMove()

(b) The instantiation process

Figure 2: The levels of abstraction in EasyLocal++ and a step of the development process Porto, Portugal, July 16-20, 2001

290

MIC’2001 - 4th Metaheuristics International Conference I

O

Solvers

Runners

Helpers

Solver Template Data Classes Simple Solver

Hybrid Solver

MultiRunner Solver

I

S LocalSearch Solver

Output Producer

I: input O: output S: state M: move

O S I

I

M

S

S

M Prohibition Manager

State Manager

MoveRunner

Runner

I

S

Neighborhood Explorer

TokenRing Solver

Comparative Solver

Hill Climbing

Simulated Annealing

Steepest

Random

Descent

Non-Ascending

M

Tabu Search

Tabu List Manager

Enhanced Tabu Search

Weight Handler

Figure 3: EasyLocal++ core classes

templates, which need to be instantiated by the user with the corresponding problem-specific types. Classes whose name is in normal font represent the interface of the framework with respect to the EasyLocal++ user, and they are meant for direct derivation of user’s concrete classes. Conversely, classes in italic typeface are used only as base classes for the other EasyLocal++ classes. In the figure, templates which are shared by a hierarchy of classes are shown only on the base class. In addition to the classes presented, the framework provides a set of tester classes, which act as a generic user interface of the program, and support both interactive and batch runs of the algorithms. The latter ones can be instructed using a dedicated language, called ExpSpec, which allows to compare different algorithms and parameter settings with very little intervention of the human operator. In order to use the framework, the user has to define the data classes (i.e., the template instantiations) and the derived helper classes which encode the specific problem description. An example of a step of this process is reported in Figure 2(b) in the case of an algorithm for the Graph Coloring problem. The function names drawn in the box RecolorExplorer are pure virtual functions that must be defined in the user’s subclass, whereas the functions in the box NeighborhoodExplorer are already defined in the framework. The classes Graph, Coloring, and Recolor, defined by the user, instantiate the templates Input, State, and Move, respectively. Runners and solvers are provided by the framework by means of templates instantiation, and they need only to be set with the links to the suitable helpers. EasyLocal++ supports also the design of new metaheuristics and the combination of already available algorithms. In fact, it is possible to describe new abstract algorithms (in the sense that they are decoupled from the problem at hand) at the runner level, while, by defining new solvers, it is possible to prescribe strategies for composing pools of basic techniques.

4

Discussion

One of the main characteristics of EasyLocal++ is its full reusability: Once the basic data structures and operations are defined and “plugged-in”, the system provides for free a straight implementation of all standard techniques and a large variety of their combinations. In addition, the system allows the user to generate and to experiment new combinations of features (e.g., neighborhood structures, initial state strategies, and prohibition mechanisms) with a conceptually clear environment and a fast prototyping capability. This is obtained by making a balanced use of O-O features needed for the design of a framework, namely templates and virtual functions. In fact, on the one hand, data classes are provided through templates, providing a better computational efficiency and a type-safe compilation. Porto, Portugal, July 16-20, 2001

MIC’2001 - 4th Metaheuristics International Conference

291

On the other hand, algorithm’s structure is implemented through virtual functions, giving the chance of incremental specification in hierarchy levels and an inverse control communication. Available systems have made different design choices. Most of them are implemented in a fully “blackbox fashion”: The program corresponding to the specified algorithm is assembled internally by the system and therefore its execution is performed “behind the scenes”. Conversely, EasyLocal++ is a “glass-box” system (or “white-box”), in which the exact statements of the program are “before user’s eyes”. The weakness of black-box systems is that the users must learn the syntax of the ad hoc specification language from scratch, whereas in the case of frameworks the representation of the problem is completely left to the user, who only needs to master the standard programming language. In addition, the interface between a black-box system and external modules or public libraries might be quite cumbersome. Finally, the modification of black-box systems would require the intervention of the system designers. In contrast, a framework is fully extensible and customizable by the expert user. A few glass-box O-O frameworks have already been proposed, and are in use in the research community. Two remarkable systems are ABACUS [9], for Branch & Cut, and HotFrame [7] specifically for local search. These systems follow other design ideas, with different advantages and drawbacks: The first system avoids the complexity of the use of templates, and it resorts only to inheritance and virtual functions. This way, though, it compels the programmer to use often pointer and explicit type conversions. The second one relies on template instantiations and results in a very compositional architecture. On the other hand, it does not exploit the power of virtual functions and dynamic binding, which greatly simplifies the development of both system and user modules. Another attempt to design an O-O framework for local search based on Design Patterns has been made by Andreatta et al. [2]. They describe the NeighborSearcher framework, which is proposed as a toolbench for the comparison of different local search algorithms. Moreover, the system supports the interleaving of constructive methods with local search algorithms. Like ABACUS, their architecture is completely based on inheritance and, therefore, could have the same drawbacks in terms of efficiency and reuse of code. We believe that, due to its flexibility and its principled design, based on Design Patterns, the use of EasyLocal++ represents, at least for the local search paradigm, a valid alternative to the above mentioned systems. To support this claim, we experimented the use of EasyLocal++ for the solution of some combinatorial problems. Namely, we worked on the Employee Timetabling, the Graph Coloring, and the Examination Timetabling problems [4, 5, 6], obtaining encouraging results.

References [1] E. Aarts and J. K. Lenstra. Local Search in Combinatorial Optimization. John Wiley & Son, Chichester, 1997. [2] A. Andreatta, S. Carvalho, and C. Ribeiro. An object-oriented framework for local search metaheuristics. In Proc. of the 26th Conf. on Technology of O-O Lang. and Systems, pp. 33–45, 1998. [3] G. Booch, J. Rumbaugh, and I. Jacobson. The unified modeling language user guide. AddisonWesley, Reading (MA), 1999. [4] M. Chiarandini, A. Schaerf, and F. Tiozzo. Solving employee timetabling problems with flexible workload using tabu search. In Proc. of the 3rd Conf. on Practice and Theory of Automated Timetabling, pp. 298–302, Konstanz, 2000. [5] L. Di Gaspero and A. Schaerf. Tabu search techniques for examination timetabling. In Proc. of the 3rd Conf. on Practice and Theory of Automated Timetabling pp. 176–179, Konstanz, 2000. [6] L. Di Gaspero and A. Schaerf. EasyLocal++: An object-oriented framework for flexible design of local search algorithms. Technical Report UDMI/13/2000/RR, Dept. of Math. and Comp. Science, Univ. of Udine, 2000. Available at http://www.diegm.uniud.it/~aschaerf/projects/local++. Porto, Portugal, July 16-20, 2001

292

MIC’2001 - 4th Metaheuristics International Conference

[7] A. Fink, S. Voß, and D. Woodruff. Building reusable software components for heuristc search, 1998. Extended abstract of the talk given at OR98, Z¨ urich. [8] E. Gamma, R. Helm, R. Johnson, and J. Vlissides. Design Patterns, Elements of Reusable ObjectOriented Software. Addison-Wesley, 1994. [9] M. J¨ unger and S. Thienel. The design of the branch-and-cut system ABACUS. Technical Report TR97.263, Univ. of Cologne, Dept. of Computer Science, 1997.

Porto, Portugal, July 16-20, 2001

Suggest Documents