prolog - Directed Multigraph, I have to calculate the sums of costs from node 1 to node 2 -



prolog - Directed Multigraph, I have to calculate the sums of costs from node 1 to node 2 -

i'm making topic cause i'm lost in have do...

i have next edges in next sintaxis:

edge(n1,n2,c1,c2,color).

where:

n1 means node 1. n2 means node 2. c1 cost go node 1 node 2. c2 cost go node 2 node 1. and color color of edge.

now, because directed multigraph can have n edges n1 n2, , thing have create rule calculate sum of costs go n1 n2 (the color doesn't matter), have have sintaxis of "rule(n1,n2,x)" x give sum of costs, if have next facts.

edge(a,b,1,6,red). edge(c,b,2,1,blue). edge(d,a,4,7,yellow). edge(a,b,6,2,green). edge(c,b,3,4,black). edge(d,a,2,7,white). edge(a,b,1,6,green).

i should able this: ?- sumofcosts(a,b,x): x= 8.

i have been seen lot of ways have counter in prolog, acumulate, etc... have problem create me don't know how start, acumulators, counters, etc... implemented lists, in case there not list (or have implement 1 in list?).

i need help!!!.

with findall/3 can list of costs between 2 nodes n1 , n2:

sumofcosts(n1,n2,sum) :- findall(c1,edge(n1,n2,c1,_,_),costs), ... .

now, computing sum of list's elements should easy.

prolog

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -