i have small problem prolog. don't understand language. have check if graph tree , have no idea how can this. have idea?
well...first, want define "tree". off top of head, tree directed graph. , need way represent directed graph in prolog. once such way this:
% % predicate define nodes. not necessary, % might find useful carrying payload around. % node(x [, payload] ). % % says edge run node x node y. % might want carry payload here (for % instance, edges might have weight/cost associated % them, such distance, price, etc. % edge(x,y [, payload] ). % says edge runs node x node y.
and tree has following following properties:
each node in tree has, @ most, single parent node (cardinality zero-or-one), connected via single inbound edge (implying child node not know parent is).
each node in tree has 0 or more child nodes (cardinality zero-to-many), each of connected via single outbound edge (implying each node knows children are).
a tree has a single root node, 1 without parent (e.g., no inbound edges). if directed graph has multiple root nodes, forest (of trees).
nodes no children (outbound edges) leaf nodes.
this leads recursive definition of tree: each node in tree can looked @ being tree on own, right? should lead descriptive solution (in prolog).
give try, show sample code , can give help.
Comments
Post a Comment