Polaris: SimBiGraphIterator.h Source File

SimBiGraphIterator.h

Go to the documentation of this file.
00001 #ifndef _SIMBIGRAPHITERATOR_H
00002 #define _SIMBIGRAPHITERATOR_H
00003 ///
00004 /// \class SimBiGraphIterator 
00005 /// \brief a class for iterating through a bipartite Similarity graph
00006 /// \defgroup Base
00007 /// \ingroup Base
00008 ///  General utility routines
00009 /// \see SimBiGraphIterator.h
00010 /// \see SimBiGraphIterator.cc
00011 /// \see SimBiGraphIterator.h
00012 ///
00013 /// \endcode
00014 /// \section Description Description
00015 /// This module contains the structures needed to represent
00016 /// an Iterator through the edges in a bipartite Similarity graph.
00017 /// 
00018 /// This class allows you to iterate through all the possible combinations
00019 /// of list1 and list2 nodes.  It has structure similar to that of an Iterator.
00020 /// It assumes, however, that when it is used, there is an outer loop
00021 /// bringing up list1 elements and an inner list bringing up list2 elements.
00022 /// executing next_list1_node() resets the list2 node iteration automatically.
00023 ///
00024 /// Example:
00025 /// \code
00026 ///         SimBiGraph sbg (source, write);
00027 ///     SimBiGraphIterator sbgi (sbg);
00028 ///
00029 ///     for ( ; sbgi.list1_valid(); sbgi.next_list1_node()) {
00030 ///
00031 ///     int ard1 = sbgi.current_list1();
00032 ///     AbstractAccess & candidate = source[ard1];
00033 ///
00034 ///     for ( ; sbgi.list2_valid(); sbgi.next_list2_node()) {
00035 ///         
00036 ///         int ard2 = sbgi.current_list2( );
00037 ///
00038 ///         SimEdge & edge = sbgi.current();
00039 ///
00040 ///                        . . . 
00041 ///     }
00042 ///     }
00043 ///
00044 /// 
00045 ///
00046 ///
00047 ///
00048 /// \endcode
00049 /// \section KNOWN KNOWN/POSSIBLE BUGS/LIMITATIONS
00050 ///
00051 #ifdef POLARIS_GNU_PRAGMAS
00052 #pragma interface
00053 #endif
00054 ///
00055 #include "ClassNames.h"
00056 #include "Listable.h"
00057 #include "SimGraph.h"
00058 #include "SimBiGraph.h"
00059 #include "SimEdge.h"
00060 ///
00061 class SimBiGraphIterator : public Listable {
00062 
00063  protected:
00064     Array< bool > * _descr1_exists;  ///< Whether the given descriptor exists in list1
00065     Array< bool > * _descr2_exists;  ///< Whether the given descriptor exists in list2
00066     Array< Array< bool > > * _check_edge;  ///< Whether a particular edge should be returned during the iteration
00067     SimBiGraph * _graph;  ///< Pointer to the similarity graph
00068     bool _list1_valid;   ///< Are there more list1 edges left?
00069     bool _list2_valid;   ///< Are there more list2 edges left?
00070     int _node1_pos;     ///< Current position for node1 in iteration loop
00071     int _node2_pos;     ///< Current position for node2 in iteration loop
00072     List<SimEdge> _created_edges;  ///< A home list for the edges created by current()
00073                                ///< Deleting the SimBiGraphIterator also deletes these.
00074 
00075  public:
00076     SimBiGraphIterator( );
00077     SimBiGraphIterator( SimBiGraph & graph );         ///< Iterate through given graph
00078     ~SimBiGraphIterator( );
00079 
00080     void delete_node1( int node );           ///< Delete the given node in list1 from the graph
00081     void delete_node2( int node );           ///< Delete the given node in list2 from the graph
00082     void record_change( SimTypeOfChange change, SimEdge & edge );
00083     ///< Modify the SimilarityTypes in the graph to reflect a change in one of the descriptors
00084 
00085     bool list1_valid( );                    ///< Any more nodes in list1 to visit?
00086     bool list2_valid( );                    ///< Any more nodes in list2 to visit?
00087     int current_list1( );                   ///< Return the index of the current node in list1
00088     int current_list2( );                   ///< Return the index of the current node in list2
00089     SimEdge & current( );                   ///< Return the SimEdge for the current edge
00090     void next_list1_node( );                ///< Go to next element in list1
00091     void next_list2_node( );                ///< Go to next element in list2
00092     void reset( );                          ///< Start back at the beginning of the iteration
00093 
00094     ///< This one is to satisfy Listable
00095     virtual void    print(ostream & o) const;
00096 
00097     virtual SimBiGraphIterator *clone() const;
00098     virtual Listable *listable_clone() const;
00099 
00100     friend ostream & operator << (ostream & o, const SimBiGraphIterator & ad);
00101 };
00102 
00103 #endif
 © 1995-2005 University of Illinois, Urbana-Champaign. All rights reserved.  Fri Mar 25 23:06:07 2005