*******************Version 1******************* l1: linkLatest (S,D,C,MAX(Tc),Tp) :- periodic (S,5,Tp), linkInitial(S,D,C,Tp), Tp-5 <= Tc <= Tp l2: link (S,D,C,Tp) :- linkLatest (S,D,C,Tc,Tp) l3: link (S,D,C,Tp) :- link(S,D,C,Tp'), Tp=Tp'+5 l4: linkLatest (S,D,C,MAX (Tc), Tp) :- linkAdd (S,D,C,Tc), Tp-5 <= Tc <= Tp h1: hop (S,D,d,C,Tp) :- link (S,D,C,Tp) h2: hop (S,D,Z,c,Tp) :- link (S,Z,C1,Tp), hopMsg (Z,D,W,C2,Tp), C=C1+C2 m1: hopMsg (S,D,Z,C,Tp) :- bestHop (S,D,d,C,Tp'), Tp=Tp'+5 m2: bestHop (S,D,Z,MIN(C),Tp) :- hop (S,D,d,C,Tp) Query bestHop (S,D,Z,C,T) comments: MAX and MIN are aggreates, linkInitial represents the initial neighour information at each node linkAdd is a event that notifies new link to be added into the network topology. hopMsg stores the distance vector information and propagates that to the next round. Restrictions Neighour information must be renewed at each round, and this allows introduction of dynamics: add of links by rule l4. Note that I did not include rule for link deletion, due to negation as failure problem. That is, the current rules only deal with new links. (No link failure or link change) The problem is l3 propagates current link information into the next round, and l4 adds new link informations. Link deletion (change) would require an extra deletion rule and l3 to operate on some mutual tuple, which is illegal. An alternative to avoid this restriction is by the following rules: *******************Version 1'******************* l1: linkLatest (S,D,C,MAX(Tc),Tp) :- periodic (S,5,Tp), linkInput(S,D,C,Tp), Tp-5 <= Tc <= Tp l2: link (S,D,C,Tp) :- linkLatest (S,D,C,Tc,Tp) h1: hop (S,D,d,C,Tp) :- link (S,D,C,Tp) h2: hop (S,D,Z,c,Tp) :- link (S,Z,C1,Tp), hopMsg (Z,D,W,C2,Tp), C=C1+C2 m1: hopMsg (S,D,Z,C,Tp) :- bestHop (S,D,d,C,Tp'), Tp=Tp'+5 m2: bestHopCost (S,D,MIN(C),Tp) :- hop (S,D,d,C,Tp) m3: bestHop (S, D, Z, C, Tp) :- bestHopCost (S,D,C,Tp), hop (S,D,Z,C,Tp) Query bestHop (S,D,Z,C,T) Comments: linkInitial and linkAdd is replaced by linkInput, which represnts neighor information collected by each node at each round. In this case, we can have both link add and link deletion: For example, linkInput tuples at round (n+1) (triggered by periodic (S,5,(n+1)*5)) is the same as those of round n, except that, we add/delete some linkInput tuple.