• Aucun résultat trouvé

Minimal Spanning Trees

Distributed Constraint Solving

7.3 Minimal Spanning Trees

The minimal spanning tree problem may be stated as follows:

An undirected graph G = <V,E> consists of a vertex set V and an edge set E. Associated with each edge {u,v} is a cost c(u,v)>0. A minimal spanning tree of G is a connected subgraph <V,E’> such that

{u,v}∈E’c(u,v) is minimal. Such a subgraph must be a tree, since if not there exists a circuit and by removing an edge a lower cost spanning tree can be derived.

The following concept can be used to produce a minimal spanning tree algorithm:

A linked minimal spanning forest of a graph <V,E> is a set of triplets {<V1,E1,L1>,…,<Vn,En,Ln>} where V1,…,Vn partitions V; Ei,Li⊆E; <Vi,Ei> is a minimal spanning tree over

<Vi,{{u,v}∈E|u,v∈Vi}>, Li={{u,v}∈E|u∈Vi,v∈Vj,j

i}, 1<I<n.

That is, the vertices of the graph <V,E> are divided up among the trees of the forest, each tree in the forest is a minimal spanning tree over its vertices With each tree is a set of linking edges, which are those edges in E which link vertices in the tree with vertices in other trees.

Given a linked minimal spanning forest, if {u,v} is the lowest cost member of Li with u∈Vi, v∈Vj, trees [Vi,Ei,Li] and [Vj,Ej,Lj] can be removed from the forest and replace them by [Vk,Ek,Lk] where

Vk=Vi∪ Vj, Ek=Ei∪ Ej∪{(u,v)}, Lk=Li∪ Lj–{{x,y}|x∈Vi,y∈Vj}

The result will also be a linked minimal spanning forest. That is two trees in the forest have been simply linked by their lowest cost linking edge and any other edges that also join these trees deleted. Starting with the linked minimal spanning forest {<{v},{},Lv>|v∈V,Lv={{v,y}∈E}}, where each tree consists of just a single vertex, every time the above replacement is applied it will reduce the number of trees in the forest by one. Eventually the stage where the forest has the single element <V,E',{}>

will be reached, which since it covers all the vertices is a minimal spanning tree for

<V,E>.

The above algorithm is presented in a slightly unorthodox manner. By explicitly partitioning the set of edges into linking edges for each tree an algorithm is produced which is more general than those usually presented. The idea of linking edges is implicit, though not stressed in the algorithm of Lavallée and Roucairol [1986], which is discussed below. It is also found in the work of Yao [1975] and Gabow et al [1989], but not usually in texts introducing the minimal spanning tree problem.

The algorithm as described leaves open the question of which trees are merged at any stage. At any time, if F is the forest, there will be at least |F|/2 mergers possible since each tree will have a minimum cost linking edge to use. But it is possible for a pair of trees to mutually agree on merger – this will occur when the minimum cost linking edge of Vi is {x,y} and that of Vj is {y,x}. (Although these refer to the same edge, the convention that a tree refers to its linking edges by the node that occurs in the tree first is used). The solution to the problem is indeterminate if edge costs are not unique. If there are two or more edges of minimum cost linking two trees in the forest and the cost is minimal for both trees any of the edges may be used leading to a different solution for each. A protocol needs to be established to prevent not just simultaneous attempts at merger using the same edge, but the case where one attempts to merge using one of the edges and the other simultaneously attempts to merge using another. This is discussed in further detail below. At most there will be

|F|–1 mergers possible – this will occur when there is some tree with which each minimum cost linking edge of all the other subtrees links. The classical algorithms of Prim and Kruskal [Barr et al., 1989] can be considered special cases of this algorithm.

Prim's algorithm [1957] (also attributed to Dijkstra [1959]) works by continually adding edges to one subtree until it encompasses all the vertices in the graph.

Keeping the trees in the above algorithm in a list, always trying to link the first tree with another and always putting the resulting merged tree at the head of the list gives Prim's algorithm. Sollin’s algorithm [Berge and Ghouila-Houri, 1965] can be obtained by putting the resulting merged tree at the end of the list. The equivalent to Kruskal’s algorithm [1956] can be obtained by linking whichever two trees in the forest can be linked by the shortest link of any possible merger. As conventionally described however, Kruskal’s algorithm delays deleting edges, working instead by considering the edges one by one in order of cost and deleting those which link vertices already in the same tree due to a previous merger.

Barr, Helgaon and Pennington [1989] present a concurrent version of Prim's algorithm in which the parallelism comes in the search for the lowest cost link from the first subtree. Our presentation of the minimal spanning tree problem makes it clear that there is a large source of parallelism in the minimal spanning tree problem apart from this. The main source being the fact, shown above, that at any stage at least |F|/2 mergers are possible. Rather than pick between them they can all be carried out in parallel. The present description of the problem in terms of a linked minimal spanning forest removes all global data structures and the consequent need to co-ordinate access to global structures. It suggests a distributed approach to the problem in which agents represent the trees in the forest. Mergers take place through negotiation between these agents. Although further parallelism is available in the

bookkeeping associated with merging two trees, our concern is with the more fundamental parallelism of allowing several trees to merge at one time.

An actor that contains lists of the vertices and edges that form the tree may represent each tree in the linked minimal spanning forest. The links are represented as a list of channel/cost pairs. Thus if trees Ti and Tj are linked by edge {x,y} on Ti (and hence {y,x} on Tj) there will be a shared channel between the actors representing the trees Ti and Tj. The merger of Ti and Tj can be accomplished by the actor Ti sending a message containing its edges, vertices and links to the actor for Tj on the channel representing the link {x,y} and terminating. On receiving the message, the actor for Tj will adjust its records accordingly to become the actor for the new merged tree. This model therefore assumes that the initiative for a merger is taken by the tree which is to merge. The initial state of the actor system represents the initial graph, with vertices represented by actors and edges represented by channels. This is similar to the initial state in the coloring algorithm above. However whereas in the graph-coloring algorithm the actor and communications structure remains static, here it alters as the algorithm progresses.

Consider what happens when the lowest cost link on Ti is {x,y} and the lowest cost link on Tj is {y,x}. A protocol needs to be established so that both trees do not send merger messages to each other and terminate. Supposing the cost of each edge in the graph is distinct, there is the more general problem of a circuit of trees mutually attempting to merge with each other. Consider the case where one of the lowest cost links (there may be several with the same cost) on Ti is the link to Ti+1. One of the lowest cost links on Ti+1 is a link to Ti+2 and so on to Ti+k and the lowest cost links on Ti+k include a link to Ti. This circuit can only exist if each of its links has an identical cost. Assuming a method for mutual merging across a link, two linked trees can mutually agree to merge at any edge in the circuit, but this will still leave a smaller circuit. Without a circuit-breaking mechanism, the potential problem of each of the trees in the circuit attempting to merge with the next one remains.

Ignoring for now the circuit problem, the case of Ti merging with Tj at the same time as Tj merges with Tk can be easily resolved. It may be noted that the merger operation is associative, so it does not matter if Ti first merges with Tj then the resulting tree merges with Tk, or Tj merges with Tk and Ti merges with the result. So if Tj merges with Tk without waiting for the incoming message from Ti, since the merger operation causes the channels of Tj to be included among the channels of the new merged actor, the incoming message will simply be passed on to this new merged actor. Note that it is not possible for a merger to replace the lowest cost link with a lower cost one. A tree always merges using its lowest cost link (which must be one of the existing links in the tree to which it is merging since the graph is non-directional). A tree can only bring in more links of equal or greater cost, so at most merger can only introduce additional lowest cost links.

The algorithm as described so far originates from attempts to implement the algorithm of Lavallée and Roucairol [1986]. The principal difference is that Lavallée and Roucairol keep the initial actor/channel state throughout the computation. In their

case, when a tree merges its actor remains in existence, explicitly passing further merger messages onto the actor representing the merged tree. Their description of the algorithm in a CSP-like notation does not allow for channels to be passed in messages and, hence, the necessity for these explicit message passing actors. In GDC, channels are recursive and may easily be passed around in messages. The effect of passing a channel in actor P to actor Q is that messages intended for P will be received by Q.

Lavallée and Roucairol make the assumption that each vertex is identified by a unique integer. The lowest valued identifier in a tree is referred to as its root. Thus the actors representing the roots of the trees at any time can be considered to be the

“real” actors of the algorithm, other actors being simply methods of passing information between roots. The circuit problem is resolved by allowing a tree Ti to send its edge and link details and merge with Tj only if the root of Ti is greater than the root of Tj. It follows that no circuit of mergers can occur.

The difficulty with the algorithm is that an actor Ti cannot simply decide to merge across its lowest cost link, because it does not know the root of Tj, the actor with which it is attempting to merge. Instead it must first send a request to merge containing its own root identifier. On receiving the request, Tj will send back either an acceptance or a refusal depending on the root values. (In fact, the algorithm as described in the reference is slightly different: the message-passing actors answer queries directly and can do so as they hold a record of their root which is updated when mergers take place). Only when an acceptance has been received will Ti send its full details for merger to take place. While waiting for acceptance or refusal of its merger request Ti will accept or refuse any requests it receives and modify its records if it receives any full mergers (which clearly can only come from trees with higher roots than its own, so will not affect its own root value).

If Ti’s request for a merger is refused, it may be the case that Tj has requested a merger which Ti will accept and which will cause its lowest cost link to be deleted when the merger is completed. Otherwise, Ti has no alternative but to repeat the request in the hope that in the meantime Tj has merged with another tree Tk whose root is low enough for the request to be accepted. A modification to the algorithm is suggested in which if Ti’s merger request is refused, Ti will not make any further requests until it has itself received a request from its lowest cost link indicating that Tj has indeed merged with some Tk.

It may be noted that even when the complexities due to the existence of explicit message-passing nodes have been stripped out, the algorithm still requires the interchange of at least three messages to accomplish a merger. Nevertheless, Lavallée and Roucairol claim that their algorithm improves on that of Gallagher, Humblet and Spira [1983] in terms of the number of message exchanges. The algorithm for coordinating tree merger, given below, improves on both, requiring just one message to accomplish each tree merger. The algorithm solves the problem of circuits by making channels between actors representing edges unidirectional. Thus, Lavallée and Roucairol’s imposition of an ordering on potential mergers through root identities may be replaced by an imposition of ordering on individual edges. Unidirectional

channels simplify the representation in GDC, since a single shared channel can represent such a channel. The convention that a unique integer identifier represents each vertex is adopted. A channel representing the link between the vertex identified x and the vertex identified y, where x>y is set to be unidirectional, outgoing from the actor containing the vertex x and incoming at the actor containing vertex y. It should be stressed that the graph itself is still nondirectional – a nondirectional edge is simply represented by a unidirectional channel. It can be seen that this is a similar approach to that adopted in the graph-coloring problem.

At any time during the algorithm’s execution any actor whose lowest cost link is represented by an incoming channel will remain passive waiting for a merger message to arrive. Any actor whose lowest cost link is represented by an outgoing channel will send a message containing its vertices, edges and linking channels (both incoming and outgoing) down this lowest cost channel and terminate. Note that when an actor receives a message, it is not necessarily on its own lowest cost incoming link, so we require the ability to receive on any incoming channel.

When a passive actor receives a merger message from one of its incoming channels, it appends the vertices and edges to its own and adds the new edge from which the merger message was received. It then deletes from its links any links, incoming or outgoing, which link to the newly added vertices. It adds to its links any of the new links, which do not link to any of its existing vertices. These new links retain their status unchanged as incoming or outgoing. If the result is that the lowest cost link is still represented by an incoming channel, the actor remains passive. Otherwise it merges and terminates using its lowest cost link, as above. Execution continues until there is only one actor left with no links – the edges on this actor then form the minimal spanning tree. When there is an incoming link and an outgoing link of the same cost and no links of lower cost, the actor remains passive if the vertex of the actor to which the incoming link joins has a lower identifier than the vertex which the outgoing link joins. (The vertex must be in a different actor and hence must have a different identifier.) Otherwise the actor is active. If an actor is active and has more than one outgoing link of the same cost and this cost is the lowest cost, the choice of which to use for merging is non-determinate.

The algorithm is a version of the more general algorithm stated initially, so it must terminate with a minimal spanning tree providing it does not deadlock and we do not get a circuit of actors simultaneously merging and terminating. At any stage in the computation there will be a link between two actors whose cost is less than or equal to the cost of any other link and whose destination vertex has an identifier less than or equal to that of any links of equal cost. The actor which has this link as an outgoing edge will always be able to use it to send a merge message and terminate, reducing the number of actors by one. Its destination actor must always be passive and thus will eventually receive the message, hence the algorithm cannot deadlock.

Channels are unidirectional, so for any potential circuit every actor in the circuit will have one incoming channel forming part of the circuit and one outgoing channel.

Unless all links in the circuit are of the same cost, there must be one actor which will not participate in the circuit merger since its incoming circuit channel represents a lower cost link than its outgoing circuit channel. It therefore remains passive or,

should it have outgoing links to non-circuit actors of lower cost than its incoming circuit link, merges with an actor not part of the circuit. The circuit may shrink but will never totally merge and cause every one of its actors to terminate. The point will eventually be reached where the circuit consists of two actors, each linked to the other, one active and one passive. The active one will terminate, sending a merger message. The passive one will receive the message and delete its link to the former active actor before becoming active itself.

Consider, now, a potential circuit all of whose links are of the same cost. Taking into account the unidirectionality of links, such a circuit cannot exist in the original graph, since that would imply that every vertex in the circuit has an identifier greater than the identifier of the vertex at the destination of its outgoing link in the circuit.

However, once merges take place circuits can form. If this occurs, there must be one actor for which the incoming link that forms part of the circuit has the destination vertex with the lowest identifier of any incoming link in the circuit. This actor will not participate in the circuit merger, since its outgoing circuit link must be to a vertex with a higher identifier.

As an example, the graph on the left of Figure 7.3.1 does not contain a circuit because of the directionality imposed. However when the actors representing the vertices 1 and 5 are merged, giving the graph on the right, there is a potential circuit. Assuming all edge costs are the same, there would not be a complete circuit merger. Because the actor representing the vertices {1,5} has incoming edge {1,2}, destination 1 and outgoing edge {5,4}, destination 4, it will remain passive as the vertex to which its lowest cost incoming link connects has a lower identifier than the vertex to which its lowest cost outgoing edge connects. In Figure 7.3.1, the bold integers are the vertex identifiers, the italic integer pairs are the edge identifiers at their destinations. The section enclosed within dotted lines on the left may be considered shrunk to a single

As an example, the graph on the left of Figure 7.3.1 does not contain a circuit because of the directionality imposed. However when the actors representing the vertices 1 and 5 are merged, giving the graph on the right, there is a potential circuit. Assuming all edge costs are the same, there would not be a complete circuit merger. Because the actor representing the vertices {1,5} has incoming edge {1,2}, destination 1 and outgoing edge {5,4}, destination 4, it will remain passive as the vertex to which its lowest cost incoming link connects has a lower identifier than the vertex to which its lowest cost outgoing edge connects. In Figure 7.3.1, the bold integers are the vertex identifiers, the italic integer pairs are the edge identifiers at their destinations. The section enclosed within dotted lines on the left may be considered shrunk to a single