Main   Namespaces   Classes   Hierarchy   Annotated   Files   Compound   Global   Pages  

VCSet.hpp

Go to the documentation of this file.
00001 //----------------------------------------------------------------------------
00002 /** @file VCSet.hpp
00003  */
00004 //----------------------------------------------------------------------------
00005 
00006 #ifndef VCSET_HPP
00007 #define VCSET_HPP
00008 
00009 #include "SgSystem.h"
00010 #include "SgStatistics.h"
00011 
00012 #include "ChangeLog.hpp"
00013 #include "ConstBoard.hpp"
00014 #include "Groups.hpp"
00015 #include "Hex.hpp"
00016 #include "VC.hpp"
00017 #include "VCList.hpp"
00018 
00019 _BEGIN_BENZENE_NAMESPACE_
00020 
00021 //----------------------------------------------------------------------------
00022 
00023 /** Stores the connections for a board and color. */
00024 class VCSet
00025 {
00026 public:
00027 
00028     /** Creates a VCSet class on the given board size for color. */
00029     VCSet(const ConstBoard& brd, HexColor color);
00030 
00031     /** Copy constructor. */
00032     VCSet(const VCSet& other);
00033 
00034     /** Destructor. */
00035     virtual ~VCSet();
00036 
00037     //------------------------------------------------------------------------
00038     
00039     /** Returns the color of this set of connections. */
00040     HexColor Color() const;
00041 
00042     /** Returns the board the set is defined on. */
00043     const ConstBoard& Board() const;
00044 
00045     /** Returns soft limit for the given type of VC. This affects
00046         VCBuilder's performance! */
00047     int SoftLimit(VC::Type) const;
00048 
00049     /** Returns the VCList between (x, y). */
00050     const VCList& GetList(VC::Type type, HexPoint x, HexPoint y) const;
00051     
00052     /** Returns the VCList between (x, y). */
00053     VCList& GetList(VC::Type type, HexPoint x, HexPoint y);
00054 
00055     /** Determines if there is at least one valid connection between
00056         the given pair of cells for the color and VC type, x and y
00057         must both be the color of this connection set. */
00058     bool Exists(HexPoint x, HexPoint y, VC::Type type) const;
00059 
00060     /** Copies the smallest connection between x and y of type into
00061         out, returns true if successful. Returns false if no
00062         connection exists between x and y. */
00063     bool SmallestVC(HexPoint x, HexPoint y, VC::Type type, VC& out) const;
00064 
00065     /** Stores the valid connections between x and y for color in out
00066         (which is cleared beforehand). */
00067     void VCs(HexPoint x, HexPoint y, VC::Type type,
00068              std::vector<VC>& out) const;
00069 
00070     //------------------------------------------------------------------------
00071 
00072     /** @name Modifying methods */
00073     // @{
00074 
00075     /** See SoftLimit() */
00076     void SetSoftLimit(VC::Type, int limit);
00077 
00078     /** Clears the connections. */
00079     void Clear();
00080 
00081     /** Attempts to add the given vc to the list between (vc.x(),
00082         vc.y()). Returns result of the add operation. This method is
00083         just a wrapper for GetList(vc.type(), vc.x(), vc.y())->add(vc).
00084 
00085         @see VCList::add()
00086     */
00087     VCList::AddResult Add(const VC& vc, ChangeLog<VC>* log);
00088 
00089     /** Uses the given changelog to revert connections to state at 
00090         last marker in the changelog. Log will will have all entries
00091         and last marker removed. */
00092     void Revert(ChangeLog<VC>& log);
00093 
00094     // @}
00095 
00096     //------------------------------------------------------------------------
00097 
00098     /** @name Operators */
00099     // @{
00100 
00101     /** Assignment operator. */
00102     void operator=(const VCSet& other);
00103 
00104     /** Returns true if other is isomorphic to us. */
00105     bool operator==(const VCSet& other) const;
00106 
00107     /** Returns true if other is not isomorphic to us. */
00108     bool operator!=(const VCSet& other) const;
00109 
00110     // @}
00111 
00112 private:
00113 
00114     /** Allocates space for, and copies lists from, the VCLists in
00115         other. */
00116     void AllocateAndCopyLists(const VCSet& other);
00117 
00118     /** Frees all allocated VCLists. */
00119     void FreeLists();
00120 
00121     /** @see Board() */
00122     const ConstBoard* m_brd;
00123 
00124     /** @see Color() */
00125     HexColor m_color;
00126 
00127     /** The lists of vcs. 
00128         @todo use actual boardsize instead of BITSETSIZE? 
00129     */
00130     VCList* m_vc[VC::NUM_TYPES][BITSETSIZE][BITSETSIZE];
00131 };
00132 
00133 inline HexColor VCSet::Color() const
00134 {
00135     return m_color;
00136 }
00137 
00138 inline const ConstBoard& VCSet::Board() const
00139 {
00140     return *m_brd;
00141 }
00142 
00143 inline const VCList& 
00144 VCSet::GetList(VC::Type type, HexPoint x, HexPoint y) const
00145 {
00146     return *m_vc[type][x][y];
00147 }
00148 
00149 inline VCList& 
00150 VCSet::GetList(VC::Type type, HexPoint x, HexPoint y)
00151 {
00152     return *m_vc[type][x][y];
00153 }
00154 
00155 inline 
00156 VCList::AddResult VCSet::Add(const VC& vc, ChangeLog<VC>* log)
00157 {
00158     return m_vc[vc.type()][vc.x()][vc.y()]->add(vc, log);
00159 }
00160 
00161 inline int VCSet::SoftLimit(VC::Type type) const
00162 {
00163     return m_vc[type]
00164         [HexPointUtil::colorEdge1(m_color)]
00165         [HexPointUtil::colorEdge2(m_color)]->softlimit();
00166 }
00167 
00168 //----------------------------------------------------------------------------
00169 
00170 /** Info on the set of connections. */
00171 struct VCSetStatistics
00172 {
00173     std::size_t m_fulls;
00174 
00175     std::size_t m_semis;
00176 
00177     SgStatisticsExt<float, std::size_t> m_fullCounts;
00178     
00179     SgStatisticsExt<float, std::size_t> m_semiCounts;
00180     
00181     SgStatisticsExt<float, std::size_t> m_fullCountsCell;
00182     
00183     SgStatisticsExt<float, std::size_t> m_semiCountsCell;
00184     
00185     SgStatisticsExt<float, std::size_t> m_fullConnectedTo;
00186 
00187     SgStatisticsExt<float, std::size_t> m_semiConnectedTo;
00188     
00189     SgHistogram<std::size_t, std::size_t> m_fullHisto;
00190     
00191     SgHistogram<std::size_t, std::size_t> m_semiHisto;
00192 
00193     VCSetStatistics();
00194 
00195     std::string Write() const;
00196 };
00197 
00198 //----------------------------------------------------------------------------
00199 
00200 /** Utilities on VCSet. */
00201 namespace VCSetUtil 
00202 {
00203     
00204     /** Returns set of cells connected to x. */
00205     bitset_t ConnectedTo(const VCSet& con, const Groups& groups, 
00206                          HexPoint x, VC::Type type);
00207 
00208     /** Returns true if connection sets are equal on the given
00209         groups. */
00210     bool EqualOnGroups(const VCSet& c1, const VCSet& c2,
00211                        const Groups& groups);
00212 
00213     /** Obtain info on connections. */
00214     VCSetStatistics ComputeStatistics(const VCSet& con, const Groups& groups,
00215                                       std::size_t maxConnections,
00216                                       int numBins);
00217 }
00218 
00219 //----------------------------------------------------------------------------
00220 
00221 _END_BENZENE_NAMESPACE_
00222 
00223 #endif // VCSET_HPP


6 Jan 2011 Doxygen 1.6.3