Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding a tour in directed graph

Status
Not open for further replies.

MartijnSmeets

Technical User
Oct 19, 2005
1
NL
I have the following prolog problem, I just don't know how to solve..
I hope somebody is able to help me out...

I have to build the following:
A program that checks a Directed Graph if there's a cycle that ends at it's beginning, and visits each point just once.
The graph should be used as a structure graph(Points, Vertices).
A vertex from a to b is presented like [a,b].

The shape of the routine that should be called:
tour(graph(Points, Vertices),Tour)

Like:

?- tour(graph([a,b,c,d], [[a,b],[b,b],[b,d],[d,c],[c,a]]),Tour).
Tour = [a,b,d,c,a]
yes

?- tour(graph([a,b,c], [[a,b],[b,b],[a,c],[b,c]]),Tour).
no

Who's able to write such a programm. I guess it shouldn't be too hard, but I'm just not good at prolog. I have to have a solution by this weekend.

Any help would be appreciated.
Wit regards,
Martijn Smeets
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top