contrib/mul/mmn/mmn_analyze_graph.cxx
Go to the documentation of this file.
00001 #include "mmn_analyze_graph.h"
00002 //:
00003 // \file
00004 // \brief Analyze a graph to deduce the dependency order.
00005 // \author Tim Cootes
00006 
00007 #include "mmn_graph_rep1.h"
00008 
00009 //: Given a graph with n.size() nodes and arc.size() arcs, deduce dependencies
00010 //  If returns true, then dep is an ordered list of dependencies
00011 //  allowing us solve a minimisation problem one node at a time.
00012 //  If it returns false, then the graph cannot be decomposed into
00013 //  a sequence of single or pairwise dependencies.
00014 //  If dep[i].n_dep==1 for all i, then the graph is a tree, and
00015 //  reversing the order of dep gives a means of traversing from the
00016 //  root to the leaves.  The original order gives a method of
00017 //  visiting every node only after any child/leaf nodes have been
00018 //  visited first.
00019 bool mmn_analyze_graph(const vcl_vector<unsigned>& n,
00020                        const vcl_vector<mmn_arc>& arc,
00021                        vcl_vector<mmn_dependancy>& dep,
00022                        unsigned& max_n_arcs)
00023 {
00024   mmn_graph_rep1 g;
00025   g.build(n.size(),arc);
00026   bool b = g.compute_dependancies(dep);
00027   max_arcs = g.max_n_arcs();
00028   return b;
00029 }