International Conference on Knowledge-Based and Intelligent Information ... Part of the Lecture Notes in Computer Science book series (LNCS, volume 6277).
Non-procedural Implementation of Local Heuristic Search in Control Network Programming Kostadin Kratchanov1, Emilia Golemanova2, Tzanko Golemanov2, and Tuncay Ercan1 1 Department of Software Engineering, Yasar University, Universite Cad. Yagacli Yol No.35-37, Bornova/Izmir, 35100 Turkey {kostadin.kratchanov,tuncay.ercan}@yasar.edu.tr 2 Department of Computing, Rousse University, 8 Studentska Street, Rousse, Bulgaria {EGolemanova,TGolemanov}@ecs.ru.acad.bg
Abstract. The report describes the type of improved uninformed or heuristic search algorithms that are well-suited for non-procedural implementation in Control network programming, and how this can be achieved using the tools for dynamic computation control. Keywords: Control network programming, heuristic algorithms, programming paradigms, programming languages, nonprocedural programming, local search, automated programming.
1 Introduction Control network programming (CNP) and, more specifically, the Spider language support powerful means for dynamic control of the computation/search process. These means – dynamic control system options and control states - were introduced in [1]. This report is devoted to describing the usage of the dynamic control for nonprocedural implementation of various heuristic strategies. CNP is especially effective for non-procedural implementation of certain type of heuristic algorithms. We refer to this type of algorithms as local search. We address the question of how to recognize this type of heuristic approaches. We also discuss the issue of how to model other types of heuristic algorithms. Although such “non-local” algorithms need a procedural implementation, it turns out that in most cases we can actually use a generic, universal control network (CN), and only correspondingly adjust the primitives used in this CN.
2 Variants of Hill Climbing We start with a discussion of a number of CNP implementations of the well-known Hill Climbing heuristic strategy [2-6] on the example of the map traversal problem as defined in [1]. We assume that the map given is the one shown in Fig. 3 in [1]. As usual for similar problems, the heuristic used is the air distance (also called straightline distance) between the cities (e.g., [2]). Table 1 specifies the air distances. R. Setchi et al. (Eds.): KES 2010, Part II, LNAI 6277, pp. 263–272, 2010. © Springer-Verlag Berlin Heidelberg 2010
264
K. Kratchanov et al.
2.1 Using Control State ORDER – Movements Downhill Allowed An implementation for finding a path in the map is shown in Fig.1. An ORDER state is used for every city in the map with multiple outgoing arrows – in our example these are cities A, B and C. Primitive SetAirDist sets the heuristic values of the arrows according to Table 1. For example, the primitive call SetAirDist (‘B’,A1) associated with the arrow entering control state OrderA finds in Table 1 the air distance from city B to the final city, and assigns this value to variable A1. The value of A1 is actually the heuristic value of the arrow from OrderA to B, in other words, the heuristic value of city B in the classical hill-climbing algorithm. The selectors of all control states ORDER have values 0. Therefore, when the control is in a given control state (e.g., OrderA) the emanating arrows will be attempted in the order of the air distances from the corresponding cities, a city with a smaller air distance chosen first. For state OrderA, if the goal city is D then the values of A1 and A2 will be 15 and 70, respectively and the control will first go to node B, and then to node C if backtracking into OrderA has happened.
Fig. 1. Non-recursive Hill-Climbing solution with usage of control state ORDER
Non-procedural Implementation of Local Heuristic Search in CNP
265
Table 1. Air distances between cities in the map
This algorithm corresponds to steepest ascent hill climbing with backtracking [4] in which moving downhill is allowed. It also corresponds to the hill climbing strategies described in [5,6]. Note that this strategy is complete, in contrast to most of the other approaches described further. 2.2 Using Control State RANGE – Movements Downhill Not Allowed More often, the hill climbing algorithm includes an additional restriction that the heuristic value of a next state cannot be worse than the heuristic value of the current state [4].
Fig. 2. Non-recursive Hill-Climbing solution using control state RANGE – variants 1 and 2
This algorithm can be simulated in CNP using control states RANGE. For our example, the CN will be similar to the one shown in Fig.1. The segment of the modified CN that corresponds to state A is shown in the left part of Fig.2. Primitive call SetAirDist(‘A’,A)is added to the arrow entering node RangeA. The second parameter is an output parameter. The value of variable A is calculated dynamically – note that variable A is actually the higher selector determining the range for the control state RangeA. Option [RANGEORDER=LOWFIRST] must be used
266
K. Kratchanov et al.
for each control state of type RANGE in subnet Map – as a result, a city with the smallest air distance among the possible neighbors of the current city will be attempted, provided the air distance of the neighbor is smaller than the air distance of the current city. A second variant is illustrated in the right part of Fig.2. Primitive SetAirDist has an additional first parameter. Basically, this primitive acts in the same manner as before – SetAirDist(‘A’,’B’,A1) sets the value of variable A1 to equal the air distance from city B to the final city, as specified in Table 1. However, if the air distance from B is larger than the air distance from A then the value of A1 will be made -1. Negative values are outside the range specified for RangeA, and therefore transition from RangeA to B will not be possible (this branch will be cut off). 2.3 A Recursive Solution with Usage of Control State RANGE Fig.3 illustrates another, recursive implementation of the hill-climbing strategy for the map traversal problem. Its idea is similar to the non-recursive solution shown on the left of Fig. 2. Primitive Connection(City, NextCity, AirDist) checks if there is a road from City to NextCity. If such a connection exists then it sets the air distance from NextCity to the final city according to Table 1. In case no link exists the heuristic value is set to -1. The last value is outside the range and therefore such arrows will be pruned.
Fig. 3. Recursive Hill-Climbing solution with usage of control state RANGE
Recursive solutions are typically preferable when the map (or the state space) is too large.
Non-procedural Implementation of Local Heuristic Search in CNP
267
3 System Option NUMBEROFARROWS The system options for static search control in CNP were described in [7]. Most system options for dynamic control were discussed in [1]. The last such option, NUMBEROFARROWS, is introduced here. The value of the system option NUMBEROFARROWS determines the maximum number of outgoing arrows which will be tried by the interpreter for a particular state in the option’s scope. 3.1 Irrevocable Hill Climbing If we modify the CN from Fig.1 adding [NUMBEROFARROWS=1] for each of the three control states then only a single arrow will be attempted. That means that the CNP solution will actually model the well-known fast algorithm of irrevocable hillclimbing [5]. Most hill-climbing algorithms in the literature are actually irrevocable hill-climbing [2,3]. Note that the same effect (irrevocable hill-climbing) will be achieved if, instead of [NUMBEROFARROWS=1]we use [BACKTRACKING=NO]. The Nearest-Neighbor algorithm for the Traveling Salesperson problem [3,8,15] is actually a specific implementation of irrevocable hill climbing. It can be easily modeled in CNP. 3.2 Hill Climbing with Limited Revocability If, instead of [NUMBEROFARROWS=1]we use[NUMBEROFARROWS=b]for a given constant b, then the resulting algorithm will be similar (but not identical) to beam search, called also pruned breadth-first search [2,5,6]. Similarly, based on the hill-climbing solutions of Sections 2.2 and 2.3 instead of the solution from Section 2.1, we can simulate irrevocable hill-climbing using [NUMBEROFARROWS=1] or [BACKTRACKING=NO], and hill climbing with restricted revocability using [NUMBEROFARROWS=b].
4
Introducing Random or Stochastic Choice
It is well known that the local greedy algorithms (such as hill-climbing) can get stuck in a local optimum. Therefore, various variants have been invented expanding the search space in an effort to avoid becoming trapped in a local optimum [2,3]. This is achieved by incorporating certain form of randomness in the choice of the successor of a state, which in the CNP case means in the choice of the outgoing arrow to follow. Such modifications are stochastic hill climbing (a next uphill move is chosen randomly, first-choice hill climbing (successors are generated stochastically and the first of them which is better than the current state is chosen), simulated annealing (a random move is picked; if it is “better” the move is accepted, otherwise the algorithm accepts the move with some probability depending on the steepness of the descent and the “temperature” – bad moves are more likely to be allowed at the start when the temperature is high). For discussions of the importance of introducing randomness in
268
K. Kratchanov et al.
robot control algorithms and generally in computation theory, the interesting reader is referred to [9,10]. The CNP implementation of some of these algorithms is described below. 4.1 Stochastic Hill Climbing Three variants are suggested. They can be illustrated by the diagrams shown in Fig.2 and Fig. 3. The only difference is that the following system option values must be specified: [RANGEORDER=RANDOM] and [NUMBEROFARROWS=1]. The first option sets a random order of the active outgoing arrows. This selection is irrevocable due to [NUMBEROFARROWS=1]. 4.2 First-Choice Hill Climbing This algorithm implements stochastic hill climbing by generating successors randomly until one is generated that is better than the current state. A CNP solution is shown in Fig.4. Arrows emanating from state FromA will be selected randomly due to [ORDEROFARROWS=RANDOM], and the first leading to a city with air distance better than the air distance of the current city will be successful. Primitive IsBetter(Child,Parent) calculates the air distances of Child and Parent and succeeds if Child is better than Parent.
Fig. 4. First-Choice Hill Climbing – declarative solution
The recursive solution can similarly be modified to emulate First-choice hill climbing. 4.3 Simulated Annealing Finally, without much discussion, we will only include here (Fig. 5) the CN for a possible CNP solution to the Traveling Salesperson Problem (for cities A, B, C and D) that implements the Simulated Annealing algorithm. The pseudocode of primitive Accept is very similar to the pseudocode of the basic process in [11]. The effect of
Non-procedural Implementation of Local Heuristic Search in CNP
269
primitive Neighbor and option [RANGEORDER=RANDOM] is swapping randomly a pair of points. The values of NTemps (number of temperature steps to try) and NLimit (number of trials at each temperature) in our solution must be by 1 less than the respective values in [11] as the value of the system option LOOPS limits the maximum number of repeating visits of a state.
Fig. 5. Simulated annealing for TSP
5 Non-procedural Local Search in CNP Traditional search algorithms for both exhaustive and informed search [2-6] typically require “procedural” implementation, that is, a procedure employing loops. In many cases the usage of data structures usually called OPEN and CLOSED is fundamental in these algorithms where OPEN is normally a stack, a queue or a priority queue depending on the type of the search strategy. Instead of iterative, recursive algorithms are sometimes used (e.g., [3]); this, however, does not change their “procedural” nature. Even the implementation of search algorithms in Prolog remains procedural (with few exceptions) – the Prolog program actually models the imperative algorithms [12]. CNP, respectively Spider, has a very interesting feature: a large group of search algorithms can be specified “non-procedurally”. By this we mean that the algorithm is represented by a CN which generally is a description of the problem, and not a simulation of an iterative procedure. Trivial examples would be the algorithms for animal
270
K. Kratchanov et al.
identification and arithmetic expression recognition from [13] where the search performed is simply the extended backtracking search built-in in the Spider interpreter. All other algorithms discussed in [1] and in this paper, with the exception of A*, may be assigned to this group as well. (A mixed case is Simulated annealing which has a considerable procedural element.) The CNs of these CNP implementations are not simulations of procedural algorithms, and no additional data structures such as OPEN are used. Instead, the CNs are conceptually declarative descriptions of the corresponding problem; the usage of appropriate system options and control states ensures that the search performed on the CN by the standard Spider interpreter will actually correspond to the corresponding heuristic or improved uninformed algorithm under question, for example hill climbing or branch-and-bound. What actually happens is that the CNP programmer uses the tools for dynamic control to achieve, without procedurally specifying any algorithm, a behavior of the standard interpreter that corresponds to the desired heuristic or other more advanced search strategy. Not all heuristic or advanced uninformed search algorithms are suited for such non-procedural implementation in CNP. An algorithm that may be directly implemented should be based on the extended backtracking strategy built-in in the interpreter. We can easily model different modes of choice of the candidate outgoing arrow (such as best-first, or randomly, or within a range, or a restricted number of arrows, etc.), or modify other parameters of the backtracking (e.g., forbid backtracking). We can perform such modifications even dynamically. Basically, we can do anything we want with the arrows of the current state; we can backtrack but then we will again have a current state. Therefore, we call this group of search strategies “local search”. This phrase is related to but is not identical with the phrase “local search” as usually understood in the literature (e.g., [2,3,15]) where the emphasis is different. Note also, that our local search is usually revocable. We have illustrated the implementation of a number of local search algorithms in [1] and in this paper, such as optimal search with cutting off insipid paths (branchand-bound), hill climbing, irrevocable hill climbing, nearest neighbor search, version of beam search, stochastic hill climbing, first-choice hill climbing.
6 Some Search Strategies Must Be Implemented Procedurally It must be understood that not all search algorithms are well suited for an elegant nonprocedural implementation in SPIDER. Most importantly, we have no automatic means to implement strategies making use of a global data structure OPEN where OPEN can include candidate arrows emanating from different states. On the other side, CNP is a universal programming paradigm. Therefore, all heuristic and other algorithms can be, in principle, modeled. This can be actually done quite easily, typically using data structures similarly to classical implementations in imperative, logic or functional programming, such as OPEN. Such CNP realizations of heuristic algorithms have also been done, for instance numerous versions of the A* algorithm (e.g., [16]). By the way, one such implementation is the CN program shown in Fig.1 of [1].
Non-procedural Implementation of Local Heuristic Search in CNP
271
These “procedural” implementations fall outside the subject of this report. We would only like to mention that such CNs are actually “generic” – they depend on the strategy to be implemented but normally not on the specific problem being solved. While the CN remains unchanged, only the primitives used must be adjusted to the particular problem. At a second level of generalization, the CN will even remain identical for a number of search strategies. Somewhat similar approach is taken in welldesigned object-oriented implementations (e.g., [12]) based on the usage of abstract classes, interfaces and similar more abstract concepts.
7 Conclusion The most prominent usage of the tools for dynamic search control in CNP is for automatic, “non-procedural” implementation of various heuristic algorithms for informed search or improved uninformed search – no search strategy has to be programmed; the aimed search strategy will be an automatic result of the work of the standard interpreter. The questions of what search algorithms are well suited for such an elegant declarative CNP implementation and how to specify (program) such a strategy have been targeted in this report. A wider view at the approaches to implementing various search strategies in CNP is the subject of [17]. There is a two-fold relationship of this research with automated programming and automated software engineering. Firstly, CNP is a natural choice as an implementation tool when considering many problems involving automated programming. A related early application is [14]. Secondly, a natural next step would be research towards automating CN programming itself or, stated differently, moving to a higher level in CNP programming. Instead of using system options and control states to specify a heuristic algorithm, a challenging but worthy task would be considering the possibility of, for example, simply setting the value of a higher-level option STRATEGY to HILLCLIMBING asking the interpreter to implement itself a hill-climbing strategy for solving the problem specified by the CN. Developing methods for CNP software engineering and automated CNP engineering is also among the possible areas for future research.
References 1. Kratchanov, K., Golemanov, T., Golemanova, E., Ercan, T.: Control Network Programming with SPIDER: Dynamic Search Control. In: 14th Int. Conf. on Knowledge-Based and Intelligent Information & Engineering Systems (KES 2010), Cardiff, UK (2010) 2. Russell, S., Norvig, P.: Artificial Intelligence: A Modern Approach, 3rd edn. Prentice Hall, Upper Saddle River (2010) 3. Luger, G.F.: Artificial Intelligence: Structures and Strategies for Complex Problem Solving, 6th edn. Addison Wesley, Boston (2009) 4. Thornton, C., du Boulay, B.: Artificial Intelligence. In: Strategies, Applications, and Models Through Search, 2nd edn., Amacom, New York (1998) 5. Shinghal, R.: Formal Concepts in Artificial Intelligence. In: Fundamentals. Chapman & Hall, London (1992)
272
K. Kratchanov et al.
6. Winston, P.H.: Artificial Intelligence, 3rd edn. Addison Wesley, Reading (1992) 7. Kratchanov, K., Golemanov, T., Golemanova, E.: Control Network Programs: Static Search Control with System Options. In: 8th WSEAS Int. Conf. on Artificial Intelligence, Knowledge Engineering and Data Bases (AIKED 2009), Cambridge, UK, pp. 423–428. WSEAS Press (2009) 8. http://en.wikipedia.org/wiki/Nearest_neighbour_algorithm 9. Martin, F.G.: Robotic Explorations. Prentice Hall, Upper Saddle River (2001) 10. Hromkovic, J.: Theoretical Computer Science: Introduction to Automata, Computability, Complexity, Algorithmics, Randomization, Communication, and Cryptography. Springer, Berlin (2004) 11. http://home.att.net/~srschmitt/sa_demo/SA-demo_1.html 12. Luger, G.F., Stubblefield, W.A.: AI Algorithms, Data Structures, and Idioms. In: Prolog, Lisp, and Java. Addison Wesley, Boston (2008) 13. Kratchanov, K., Golemanova, E., Golemanov, T.: Control Network Programming Illustrated: Solving Problems With Inherent Graph-Like Structure. In: 7th IEEE/ACIS Conf. on Computer and Information Science (ICIS 2008), Portland, Oregon, USA, pp. 453–459. IEEE Computer Society Press, Los Alamitos (2008) 14. Kratchanov, K.D., Stanev, I.N.: A Rule-Based System for Fuzzy Natural Language Robot Control. In: Plander, I. (ed.) Proc. 4th Intern. Conf. Artificial Intelligence and InformationControl Systems of Robots, Smolenice, Czechoslovakia, pp. 304–309. North-Holland, Amsterdam (1987) 15. Levitin, A.: Introduction to the Design and Analysis of Algorithms, 2nd edn. Addison Wesley, Boston (2007) 16. Golemanov, T.: An Integrated Environment for Control Network Programming. Research report, Rousse University (1996) 17. Kratchanov, K., Golemanova, E., Golemanov, T., Ercan, T., Ekici, B.: Procedural and Non-Procedural Implementation of Search Strategies in Control Network Programming. To be Presented at: Intl Symposium on Innovations in Intelligent Systems and Applications (INISTA 2010). Kayseri & Cappadocia, Turkey (2010)