welcome: please sign in
location: attachment:TravellingSalesperson.rfc.asp.txt of EncodingsExamples

Attachment 'TravellingSalesperson.rfc.asp.txt'

Download

   1 % Input graph is undirected, but we use its directed representation
   2 % just because it is easier to deal with it.
   3 edge(Y,X) :- edge(X,Y).
   4 edgewt(Y,X,W) :- edgewt(X,Y,W).
   5 
   6 cycle(X,Y) v non_cycle(X,Y) :- edge(X,Y).
   7 
   8 % Each node must have exactly one incoming and one outgoing arc.
   9 :- vtx(X), not #count{Y : cycle(X,Y)} = 1.
  10 :- vtx(Y), not #count{X : cycle(X,Y)} = 1.
  11 
  12 % Each node must be reached.
  13 reached(X) :- cycle(1,X).
  14 reached(Y) :- reached(X), cycle(X,Y).
  15 :- vtx(X), not reached(X).
  16 
  17 % Total weight must not exceed the maximum weight W.
  18 :- maxweight(W), W < #sum{C,X,Y : edgewt(X,Y,C), cycle(X,Y)}.

Attached Files

You are not allowed to attach a file to this page.