[eclipse-clp-users] Problem with TSP(travelling salesman Problem) code when testing on real data

From: Nada Ossama <nadaossama90_at_...6...>
Date: Sat, 30 Apr 2011 19:18:28 +0200
I was using this TSP(travelling salesman Problem) code in my project
and it was working perfectly on these set of data
% Data

c(0,1,30).
c(0,2,60).
c(0,3,41).
c(0,4,17).
c(0,5,70).
c(1,2,58).
c(1,3,46).
c(1,4,46).
c(1,5,48).
c(2,3,21).
c(2,4,59).
c(2,5,40).
c(3,4,38).
c(3,5,50).
c(4,5,78).

However these were not the real data i will make my application work upon
there are:
% Data

c(1,0,0.00136225).
c(2,0,0.0022772499999999998).
c(2,1,9.15E-4).
c(3,0,0.0036787499999999997).
c(3,1,0.0023165).
c(3,2,0.0014015).

So to accommodate the code to my data
I edited in this procedure by changing the domain

%Initialize a list and make sure that all its contents are different
init_cities(N,List) :-
   length(List,N),
   List::0..1,
   ic:alldifferent(List).

but its not working and I don't know why
can someone help me please???

%%%%%%%%%   The File  %%%%%%%%%%%%
:- lib(ic), lib(ic_global), lib(propia), lib(branch_and_bound).

%%%%%%%%%   Testing   %%%%%%%%%%%%

% Goal
test(N,List,Cost) :-
    tsp(N,List, Cost).

% call other predicates
tsp(N,List,Cost) :-
   init_cities(N,List),
   constrain_dists(N,List,Dists),
   search_min(List,Dists,Cost).

%Initialize a list and make sure that all its contents are different
init_cities(N,List) :-
   length(List,N),
   M is N-1,
   List::0..M,
   ic:alldifferent(List).

%Add a term to Cities and add distances to edges
constrain_dists(N,List,Dists) :-
   List = [Home|_],
   append(List,[Home],Circuit),
   Cities =.. [cities|Circuit],
   ( for(I,1,N),
     foreach(Dist,Dists),
     param(Cities)
   do
     dist(Cities[I],Cities[I+1],Dist)
   ).

%Since it is an undirected graph it searches for distances both ways
dist(City1,City2,D) :-
   X is City1,
   Y is City2,
   ( c(X,Y,D) ; c(Y,X,D) ) infers ac.

%Label my list and find its minimum value and fint total cost
search_min(List,Dists,Cost) :-
   Cost #= sum(Dists),
   minimize(labeling(List), Cost).


-- 
Best Regards,
Nada Ossama
Received on Sat Apr 30 2011 - 17:18:34 CEST

This archive was generated by hypermail 2.2.0 : Mon Jul 09 2018 - 02:05:29 CEST