Menu


Notice: Undefined index: url2 in /home/u681245571/domains/studyglance.in/public_html/labprograms/aidisplay.php on line 84

Notice: Undefined index: url3 in /home/u681245571/domains/studyglance.in/public_html/labprograms/aidisplay.php on line 85

Notice: Undefined index: url4 in /home/u681245571/domains/studyglance.in/public_html/labprograms/aidisplay.php on line 86

Notice: Undefined index: opurl2 in /home/u681245571/domains/studyglance.in/public_html/labprograms/aidisplay.php on line 89

Notice: Undefined index: opurl3 in /home/u681245571/domains/studyglance.in/public_html/labprograms/aidisplay.php on line 90

Notice: Undefined index: opurl4 in /home/u681245571/domains/studyglance.in/public_html/labprograms/aidisplay.php on line 91

Artificial Intelligence [ Lab Programs ]


Aim:

Write a program in prolog to solve Traveling salesman problem

Solution :

/* Description: 
For example, there are four cities(Kansas City,Houston,Gordon and Tampa). 

-> The distance between Kansas City and Houston is 120.
-> The distance between Kansas City and Tampa is 80.
-> The distance between Houston and Gordon is 100.

*/

% Production Rules:-
 route(Town1,Town2,Distance)🡪 road(Town1,Town2,Distance).
 route(Town1,Town2,Distance)🡪 road(Town1,X,Dist1),
 route(X,Town2,Dist2),
 Distance=Dist1+Dist2,

% Domains

 town = symbol
 distance = integer

% Predicates

 nondeterm road(town,town,distance)
 nondeterm route(town,town,distance)

% Clauses

 road("tampa","houston",200).
 road("gordon","tampa",300).
 road("houston","gordon",100).
 road("houston","kansas_city",120).
 road("gordon","kansas_city",130).

 route(Town1,Town2,Distance):-
	road(Town1,Town2,Distance).
 
 route(Town1,Town2,Distance):-
	road(Town1,X,Dist1),
	route(X,Town2,Dist2),
	Distance=Dist1+Dist2,
	!.

Output:

% Goal
 route("tampa", "kansas_city", X),
 write("Distance from Tampa to Kansas City is ",X),nl.

Distance from Tampa to Kansas City is 320
X=320
1 Solution

Related Content :

Artificial Intelligence Lab Programs

1) Write a program in prolog to implement simple facts and Queries View Solution

2) Write a program in prolog to implement simple arithmetic View Solution

3) Write a program in prolog to solve Monkey banana problem View Solution

4) Write a program in prolog to solve Tower of Hanoi View Solution

5) Write a program in prolog to solve 8 Puzzle problems View Solution

6) Write a program in prolog to solve 4-Queens problem View Solution

7) Write a program in prolog to solve Traveling salesman problem View Solution

8) Write a program in prolog for Water jug problem View Solution