Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

mmn_graph_rep1.h

Go to the documentation of this file.
00001 #ifndef mmn_graph_rep1_h_
00002 #define mmn_graph_rep1_h_
00003 //:
00004 // \file
00005 // \brief Representation of a graph, stored by links at each node.
00006 // \author Tim Cootes
00007 
00008 #include <mmn/mmn_arc.h>
00009 #include <mmn/mmn_dependancy.h>
00010 #include <vcl_vector.h>
00011 #include <vcl_utility.h>  // For vcl_pair
00012 
00013 //: Representation of a graph, stored by links at each node.
00014 //  Optimised for adding arcs and finding arcs for each node.
00015 //  Assumes that there is an ordered list of arcs (but doesn't
00016 //  actually record it explicitly).
00017 class mmn_graph_rep1
00018 {
00019  private:
00020   //: Indicates arcs connected to each node
00021   //  node_data_[i][j].first == vertex connected to node i
00022   //. *.second == index of arc which does the connection.
00023   vcl_vector<vcl_vector<vcl_pair<unsigned,unsigned> > > node_data_;
00024 
00025 #if 0
00026   //: Number of options for each node
00027   //  Used to select most efficient simplification of the graph
00028   vcl_vector<unsigned> n_;
00029 #endif // 0
00030 
00031   //: Maximum number of arcs used
00032   unsigned max_n_arcs_;
00033 
00034   //: Current number of arcs
00035   unsigned n_arcs_;
00036 
00037   //: Remove record of arc v1-v2 from v1
00038   void remove_arc_from_node(unsigned v1, unsigned v2);
00039  public:
00040   //: Default constructor
00041   mmn_graph_rep1();
00042 
00043   //: Indicates arcs connected to each node
00044   //  node_data_[i][j].first == vertex connected to node i
00045   //. *.second == index of arc which does the connection.
00046   const vcl_vector<vcl_vector<vcl_pair<unsigned,unsigned> > >& node_data() const
00047   { return node_data_; }
00048 
00049   //: Maximum number of distinct arcs used
00050   unsigned max_n_arcs() const { return max_n_arcs_; }
00051 
00052   //: Current number of arcs
00053   unsigned n_arcs() const { return n_arcs_; }
00054 
00055   //: Build from list of arcs
00056   void build(unsigned n_nodes, const vcl_vector<mmn_arc>& arcs);
00057 
00058   //: Return index of arc between v1 and v2, or -1 if none
00059   int arc_index(unsigned v1, unsigned v2) const;
00060 
00061   //: Return index of arc between v1 and v2, creating one if none exists
00062   unsigned get_arc(unsigned v1, unsigned v2);
00063 
00064   //: Remove some of leaves of graph, recording dependencies
00065   //  A leaf node is one with only one arc
00066   //  For each leaf node removed, add one dependency object to
00067   //  the deps list.
00068   //  Returns number of leaves removed.
00069   unsigned remove_leaves(vcl_vector<mmn_dependancy>& deps);
00070 
00071   //: Remove all of leaves of graph, recording dependencies
00072   //  A leaf node is one with only one arc
00073   //  For each leaf node removed, add one dependency object to
00074   //  the deps list.  On exit, this graph has no leaves.
00075   //  Returns number of leaves removed.
00076   unsigned remove_all_leaves(vcl_vector<mmn_dependancy>& deps);
00077 
00078   //: Remove arcs from some of the nodes with two neighbours
00079   //  Record the pairwise dependencies.
00080   //  For each node removed, add one dependency object to
00081   //  the deps list.
00082   //  Returns number of removed.
00083   unsigned remove_pair_deps(vcl_vector<mmn_dependancy>& deps);
00084 
00085   //: Compute list of all single and pairwise dependencies
00086   //  Finds ordered list of dependencies.
00087   //  If returns true, then dep is an ordered list of dependencies
00088   //  allowing us solve a minimisation problem one node at a time.
00089   //  If it returns false, then the graph cannot be decomposed into
00090   //  a sequence of single or pairwise dependencies.
00091   //  If dep[i].n_dep==1 for all i, then the graph is a tree, and
00092   //  reversing the order of dep gives a means of traversing from the
00093   //  root to the leaves.  The original order gives a method of
00094   //  visiting every node only after any child/leaf nodes have been
00095   //  visited first.
00096   //  Destroys current structure in the process.
00097   bool compute_dependancies(vcl_vector<mmn_dependancy>& deps);
00098 };
00099 
00100 #endif // mmn_graph_rep1_h_

Generated on Thu Jan 10 14:44:52 2008 for contrib/mul/mmn by  doxygen 1.4.4