% Adrian Pop 2003-12-05

:- use_module(library(clpfd)).

travel(Cities, Distance, Distances) :-
   Cities =     [ C01, C02, C03, C04, C05, C06, C07, C08, C09, C10], 
   element(C01, [   0,  85, 110,  94,  71,  76,  25,  56,  94,  67], D01),
   element(C02, [  85,   0,  26,  70,  62,  60,  63,  62,  70,  49], D02),
   element(C03, [ 110,  26,   0,  71,  87,  89,  88,  87,  93,  73], D03),
   element(C04, [  94,  70,  81,   0, 121,  19,  82, 106, 124, 105], D04),
   element(C05, [  71,  62,  87, 121,   0, 104,  53,  24,   8,  13], D05),
   element(C06, [  76,  60,  89,  19, 104,   0,  65,  89, 108,  93], D06),
   element(C07, [  25,  63,  88,  82,  53,  65,   0,  30,  57,  46], D07),
   element(C08, [  56,  62,  87, 106,  24,  89,  30,   0,  23,  20], D08),
   element(C09, [  94,  70,  93, 124,   8, 108,  57,  23,   0,  20], D09),
   element(C10, [  67,  49,  73, 105,  13,  93,  46,  20,  20,   0], D10),
   Distance #= D01+D02+D03+D04+D05+D06+D07+D08+D09+D10,
   Distances = [D01, D02, D03, D04, D05, D06, D07, D07, D09, D10],   
   circuit(Cities),
   labeling([minimize(Distance)], Cities),
   labeling([], Distances).

:- travel(C, D, Dd).

load_constraint(_, [], _, _).
load_constraint(Load, [C|Cc], Cities, Start) :-
   element(Start, Cities, Next),
   element(Start, [0, 1, 5, -6, 4, 3, -5, 2, 1, -3], NextLoad),
   sum([Load, NextLoad], #<, 16),
   sum([Load, NextLoad], #>, -1),
   X #= Load+NextLoad,
   load_constraint(X, Cc, Cities, Next).


travel_c(Cities, Distance):-
   Cities =     [ C01, C02, C03, C04, C05, C06, C07, C08, C09, C10], 
   element(C01, [   0,  85, 110,  94,  71,  76,  25,  56,  94,  67], D01),
   element(C02, [  85,   0,  26,  70,  62,  60,  63,  62,  70,  49], D02),
   element(C03, [ 110,  26,   0,  71,  87,  89,  88,  87,  93,  73], D03),
   element(C04, [  94,  70,  81,   0, 121,  19,  82, 106, 124, 105], D04),
   element(C05, [  71,  62,  87, 121,   0, 104,  53,  24,   8,  13], D05),
   element(C06, [  76,  60,  89,  19, 104,   0,  65,  89, 108,  93], D06),
   element(C07, [  25,  63,  88,  82,  53,  65,   0,  30,  57,  46], D07),
   element(C08, [  56,  62,  87, 106,  24,  89,  30,   0,  23,  20], D08),
   element(C09, [  94,  70,  93, 124,   8, 108,  57,  23,   0,  20], D09),
   element(C10, [  67,  49,  73, 105,  13,  93,  46,  20,  20,   0], D10),
   Distance #= D01+D02+D03+D04+D05+D06+D07+D08+D09+D10,
   circuit(Cities),
   load_constraint(0, Cities, Cities, 1),
   labeling([ffc, all, minimize(Distance)], Cities).




