Jump to content


Prolog and graphs


7 replies to this topic

#1 chetah

    New Member

  • Members
  • Pip
  • 3 posts

Posted 05 April 2009 - 12:31 PM

Problem
A graph G has a set of edges defined by
edge(U,V,W)
meaning there is an edge from U to node V with cost W.

Trying to find:
(a.) clause path(S,D) which succeed if there is a path from S to D
(b.) clause pathcost(S,D,Cost) returns the cost from S to D
(c.) clause thepath(S, D, Path) returns, in Path, a list fo the nodes on the path from S to D including S and D.

My solution(I am on the correct path)
(a.)
edge(S,D)
path(S,D) :- edge(S,D);edge(D,S)

(b.)
edge(S,D,Cost)
pathcost(S,D,Cost):- travel(A,B,[A],Q), reverse(Q,Path)

(c.)
thepath(S,D,Path)
travel(S,D,P,[D|P]) :-connected(S,D).

Any explanation to help my understanding is appreciated.

#2 roel

    Senior Member

  • Members
  • PipPipPipPip
  • 697 posts

Posted 05 April 2009 - 12:56 PM

This is a homework question?

#3 chetah

    New Member

  • Members
  • Pip
  • 3 posts

Posted 05 April 2009 - 02:04 PM

No not home work. Trying to work an example associated to this site I am working on
http://www.csupomona.../pt_framer.html

#4 Reedbeta

    DevMaster Staff

  • Administrators
  • 4969 posts
  • LocationBellevue, WA

Posted 05 April 2009 - 04:12 PM

If you're not doing homework, why bother learning Prolog? No one outside academia uses it.
reedbeta.com - developer blog, OpenGL demos, and other projects

#5 Mihail121

    Senior Member

  • Members
  • PipPipPipPip
  • 1052 posts

Posted 05 April 2009 - 04:25 PM

Reedbeta said:

If you're not doing homework, why bother learning Prolog? No one outside academia uses it.

OH, COME ON, THAT'S JUST PLAIN CRAZY!!!!!!!

I use it for proof of concepts even of graphical tasks all the time and I have friends that use it too and I know many many useful things in it that are not available in other languages, so just never say the 'outside academica'-part for logical programming, ASP and CSP again please.

#6 Reedbeta

    DevMaster Staff

  • Administrators
  • 4969 posts
  • LocationBellevue, WA

Posted 05 April 2009 - 04:29 PM

I stand corrected. :)
reedbeta.com - developer blog, OpenGL demos, and other projects

#7 Rubicon

    Member

  • Members
  • PipPip
  • 90 posts

Posted 05 April 2009 - 11:31 PM

Yeah, come on. No absolutes. Let's just settle for 1 in 10 trillion billion people use it ;)

I can't believe uni's are still teaching this dead crap. I can accept it might have a use somewhere sometime, but students should be learning stuff they're gonna use *all* the time when they go into the real world. C++ and maybe some java or python or c# or other clone
Regards, Paul Johnson
www.rubicondev.com
My Free 3D Tower Defence Game

#8 Reedbeta

    DevMaster Staff

  • Administrators
  • 4969 posts
  • LocationBellevue, WA

Posted 07 April 2009 - 05:18 PM

I'm closing this thread since it is not gamedev related.
reedbeta.com - developer blog, OpenGL demos, and other projects





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users