Question

How to find the possible routes between cities using Depth-First Search Here this is my code :

DOMAINS
    s = symbol.
    sList = symbol*.

PREDICATES
    nondeterm link(s, s,integer).
    nondeterm depth_first_search(s, s, sList,integer).

CLAUSES


    link("Erbil","Koysinjaq",12).
    link("Erbil","Kirkuk",15).
    link("Erbil","Shaqlawa",15).
    link("Erbil","Mosul",22).
    link("Shaqlawa","Akre",33).
    link("Mosul","Duhok",44).
    link("Mosul","Akre",55).
    link("Kirkuk","Koysinjaq",66).
    link("Kirkuk","Chamchamal",88).
    link("Chamchamal","Sulaimani",34).
    link("Koysinjaq","Sulaimani",22).
    link("Sulaimani","Ranya",33).
    link("Akre","Duhok",22).

    depth_first_search(X, X, [X],0).
    depth_first_search(X, Y, [X|T],NewDis):-
        link(X, Z , Dis),
        NewDis=NewDis+Dis,
        depth_first_search(Z, Y, T,NewDis).

GOAL
    depth_first_search("Erbil", "Duhok", PathToGoal,Dis).

when I executed I got this Error :

E;Test_Goal, pos: 652, 707 Free variable in expression

here I want to the all possible links between these cities with the distance between them now how to do that , thanks for any help

Was it helpful?

Solution

Look this is your error :

depth_first_search(X, X, [X],0).
    depth_first_search(X, Y, [X|T],L):-
        link(X, Z , L1),
        depth_first_search(Z, Y, T,L2),L=L1+L2.

GOAL
    depth_first_search("Erbil", "Duhok", PathToGoal,Dis).

It's working for me now :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top