Assignment 7

Given the following digraph extend/port the in-class example (diagraph.pl) for the following:

1. Write a program that finds all paths from a source node to destination node and the cost of each path. Your program must use file operations (predicates tell, write, and told will be useful) and write the output in the following format to a file:

[the,paths,from,s,to,u,are]

path([s,t,v,u],6)

path([s,t,v,w,u],10)

path([s,t,u],8)

Include at least two test cases: one from node s to u.

2. Add another rule to your program that finds only the optimal path from a source node to a destination node. Include at least two test cases: one from node s to u. Employ the generate-and-test paradigm in your rule, that is, try to state declaratively what it means to be the optimal path (there exists a path from source to desitnation and no other path exists with less cost). Do not create a list of all the paths then select the path with the least cost (this is a procedural approach)! Write the output in the following format:

[the,optimal,path,from,s,to,u,is]

[s,t,v,u]

[with,cost,6]

3. Define a new rule hamiltonian( Graph, Path) which finds an acyclic path comprising all the nodes in a graph. Hint: use generate-and-test by generating a path from some source node to some destination node path(_,_,Graph,Path,_), then test to ensure that the path includes all the nodes in the graph.  Once again, think declaratively!  Write the solution(s) to a file using file operations.