1/*
    2Computing the probability of a path between two nodes in a probabilistic graph.
    3Each edge has a probability of being present.
    4From
    5L. De Raedt, A. Kimmig, and H. Toivonen. ProbLog: A probabilistic Prolog and
    6its application in link discovery. In International Joint Conference on
    7Artificial Intelligence, pages 2462-2467, 2007.
    8*/
    9:- use_module(library(pita)).   10
   11:- if(current_predicate(use_rendering/1)).   12:- use_rendering(c3).   13:- use_rendering(graphviz).   14:- use_rendering(table,[header(['Multivalued variable index','Rule index','Grounding substitution'])]).   15:- endif.   16
   17:- pita.   18
   19:- begin_lpad.   20
   21% path(X,Y) is true if there is a path between nodes X and Y
   22% edge(a,b) indicates that there is an edge between a and b
   23
   24path(X,X).
   25% there is surely a path between a node and itself
   26
   27path(X,Y):-
   28  edge(X,Z),path(Z,Y).
   29% there is surely a path between X and Y if there is another node Z such that
   30% there is an edge between X and Z and there is a path between Z and Y
   31
   32edge(a,b):0.2.
   33% there is an edge between a and b with probability 0.2
   34edge(b,e):0.5.
   35edge(a,c):0.3.
   36edge(c,d):0.4.
   37edge(d,e):0.4.
   38edge(a,e):0.1.
   39
   40:- end_lpad.   41
   42graph(digraph([rankdir='LR'|G])):-
   43    findall(edge((A -> B),[label=P]),
   44      clause(edge(A,B,_,_),(get_var_n(_,_,_,_,[P|_],_),_)),
   45      G).

?- prob(path(a,e),Prob). % what is the probability that a and e are connected? % expected result 0.22888 ?- prob(path(a,e),Prob),bar(Prob,C). % what is the probability that a and e are connected? % expected result 0.22888 ?- graph(G). % shows the probabilistic graph

?- bdd_dot_string(path(a,e),BDD,Var). % What is the BDD for query path(a,e)? % A solid edge indicates a 1-child, a dashed edge indicates a 0-child and % a dotted % edge indicates a negated 0-child. % The table Var contains the associations between the rule groundings and the % multivalued variables.

*/