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

Problem.h

00001 // Problem.h -- The interface to the super class of all the Constraint
00002 // Satisfaction Problems.
00003 
00004 /*
00005  * Copyright (C) 1997, 1998 Tudor Hulubei <tudor@hulubei.net>.
00006  *
00007  * This library is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU Lesser General Public License as
00009  * published by the Free Software Foundation; either version 2, or (at
00010  * your option) any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA,
00020  * 02111-1307, USA.
00021  */
00022 
00023 /*
00024  * NOTE: This is an interal header file.
00025  * You should not attempt to use it directly.
00026  */
00027 
00028 // $Id: Problem_8h-source.html,v 1.1 2005/05/25 12:37:18 tudor Exp $
00029 
00030 #ifndef _CSP_KERNEL_Problem_H
00031 #define _CSP_KERNEL_Problem_H
00032 
00033 
00034 CSP_NAMESPACE_BEGIN(csp);
00035 
00036 
00040 class CSP_API Problem
00041 {
00042   public:
00043     typedef vhash_type::const_iterator variable_iterator;
00044     typedef chash_type::const_iterator constraint_iterator;
00045     typedef shash_type::const_iterator solution_iterator;
00046 
00047 #ifdef _MSC_VER
00048 // No warnings about unknown warnings.
00049 #pragma warning(disable: 4615)
00050 // No warnings about using `this' in base member initializer list.
00051 #pragma warning(disable: 4355)
00052 #endif
00053 
00055     Problem(RandomSequence& randomSequence);
00056 
00057 #ifdef _MSC_VER
00058 #pragma warning(enable: 4355)
00059 #pragma warning(enable: 4615)
00060 #endif
00061 
00063     virtual ~Problem();
00064 
00071     virtual wstring name() const { return L"Problem"; }
00072 
00078     virtual wstring signature() const;
00079 
00085     size_t variables() const { return m_variables.size(); }
00086 
00092     size_t constraints() const { return m_constraints.size(); }
00093 
00099     size_t solutions() const { return m_solutions.size(); }
00100 
00102     const variable_iterator beginVariables() const
00103     {
00104         return m_variables.begin();
00105     }
00106 
00108     const variable_iterator endVariables() const
00109     {
00110         return m_variables.end();
00111     }
00112 
00114     const constraint_iterator beginConstraints() const
00115     {
00116         return m_constraints.begin();
00117     }
00118 
00120     const constraint_iterator endConstraints() const
00121     {
00122         return m_constraints.end();
00123     }
00124 
00126     const solution_iterator beginSolutions() const
00127     {
00128         return m_solutions.begin();
00129     }
00130 
00132     const solution_iterator endSolutions() const
00133     {
00134         return m_solutions.end();
00135     }
00136 
00138     Variable& variable(id_t id);
00139 
00141     const Variable& variable(id_t id) const;
00142 
00144     Constraint& constraint(id_t id);
00145 
00147     const Constraint& constraint(id_t id) const;
00148 
00159     virtual bool isSolution() const;
00160 
00165     bool isInternallyConsistent() const;
00166 
00173     bool isArcConsistent() const;
00174 
00176     virtual wostream& printSolution(wostream& wos) const;
00177 
00183     virtual void init();
00184 
00188     virtual void done();
00189 
00194     size_t maxDomainSize() const;
00195 
00197     RandomSequence& randomSequence() const { return m_randomSequence; }
00198 
00204     virtual wostream& print(wostream& wos) const;
00205 
00211     virtual void generateGraph(wostream& wos) const;
00212 
00213     friend CSP_API wostream& operator<<(wostream& wos, const Problem& problem)
00214     {
00215         return problem.print(wos);
00216     }
00217 
00223     virtual void save(wofstream& wofs) const;
00224 
00230     virtual void saveSolution(wofstream& wofs) const;
00231 
00238     variable_iterator add(Variable& variable);
00239 
00245     void remove(Variable& variable);
00246 
00253     constraint_iterator add(Constraint& constraint);
00254 
00260     void remove(Constraint& constraint);
00261 
00264     ulonglong totalCCKS() const;
00265 
00267     ulonglong failedCCKS() const;
00268 
00269   protected:
00278     Problem(const Problem& problem);
00279 
00284     void add(Solution& solution);
00285 
00289     int nextRandomNumber(int limit);
00290 
00291   private:
00293     Problem& operator=(const Problem&);
00294 
00296     template<class T>
00297 #if defined(__GNUG__)
00298     void delete_hash(hash_set<T*, hash_id<T*>, equal_id<T*> >& container)
00299 #elif defined(_MSC_VER)
00300     void delete_hash(hash_set<T*, hash_compare<T*, less_id<T*> > >& container)
00301 #endif
00302     {
00303 #if defined(__GNUG__)
00304         typename hash_set<T*, hash_id<T*>, equal_id<T*> >::iterator
00305             ci, next;
00306 #elif defined(_MSC_VER)
00307         typename hash_set<T*, hash_compare<T*, less_id<T*> > >::iterator
00308             ci, next;
00309 #endif
00310         for (ci = container.begin(); !container.empty(); ci = next)
00311         {
00312             next = ci;
00313             ++next;
00314             T* p = *ci;
00315             container.erase(ci);
00316             delete p;
00317         }
00318     }
00319 
00321     template<class T>
00322     void delete_vector(vector<T*>& container)
00323     {
00324         typename vector<T*>::iterator ci = container.begin();
00325         for (; ci != container.end(); ++ci)
00326             delete *ci;
00327         container.resize(0);
00328     }
00329 
00337     vhash_type m_variables;
00338 
00340     chash_type m_constraints;
00341 
00347     shash_type m_solutions;
00348 
00350     id_t m_nextVariableId;
00351 
00353     id_t m_nextConstraintId;
00354 
00356     id_t m_nextSolutionId;
00357 
00360     RandomSequence& m_randomSequence;
00361 };
00362 
00363 
00364 CSP_NAMESPACE_END(csp);
00365 
00366 
00367 #endif // _CSP_KERNEL_Problem_H
00368 
00369 // Local Variables:
00370 // mode: C++
00371 // End:

Generated on Wed May 25 12:21:14 2005 for csp.kdevelop by  doxygen 1.3.9.1