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

Puzzle.h

00001 // Puzzle.h -- The Puzzle problem represented as a CSP.
00002 
00003 /*
00004  * Copyright (C) 2003-2004 Tudor Hulubei <tudor@hulubei.net>.
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU Lesser General Public License as
00008  * published by the Free Software Foundation; either version 2, or (at
00009  * your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA,
00019  * 02111-1307, USA.
00020  */
00021 
00022 // $Id: Puzzle_8h-source.html,v 1.1 2005/05/25 12:37:18 tudor Exp $
00023 
00024 #ifndef _CSP_EXAMPLES_Puzzle_H
00025 #define _CSP_EXAMPLES_Puzzle_H
00026 
00027 
00028 #ifndef __cplusplus
00029 #error Must use C++ for the type Puzzle.
00030 #endif
00031 
00032 
00033 #include "values/Int.h"
00034 #include "variables/Int.h"
00035 
00036 
00037 CSP_NAMESPACE_BEGIN(Puzzle)
00038 
00039 
00040 using namespace std;
00041 
00042 
00043 typedef csp::values::Int Value;
00044 typedef csp::Domain Domain;
00045 class Variable;
00046 
00047 
00048 class NonConsecutiveConstraint :
00049     public csp::Constraint
00050 {
00051   public:
00052     NonConsecutiveConstraint() : csp::Constraint() {}
00053     virtual bool check() const;
00054 };
00055 
00056 
00057 class DifferentConstraint :
00058     public csp::Constraint
00059 {
00060   public:
00061     DifferentConstraint() : csp::Constraint() {}
00062     virtual bool check() const;
00063 };
00064 
00065 
00066 class Problem :
00067     public csp::Problem
00068 {
00069   public:
00070     Problem(csp::RandomSequence& randomSequence/*int puzzle*/);
00071     Problem(const Problem& problem);
00072 
00073     virtual wstring name() const { return L"Puzzle"; }
00074 
00075     void addNonConsecutiveConstraint(int index0, int index1);
00076     void addDifferentConstraint(int index0, int index1);
00077 
00078     virtual wostream& printSolution(wostream& wos) const;
00079 
00080     virtual wostream& print(wostream& wos) const
00081     {
00082         wos << L"Problem: Puzzle" << endl;
00083         return csp::Problem::print(wos);
00084     }
00085 
00086   private:
00087     void constructor(/*int puzzle*/);
00088 
00089     // We keep the nodes in this vector just to be able to find them
00090     // quickly based on their index.
00091     vector<Variable*> m_nodes;
00092 };
00093 
00094 
00095 class Variable :
00096     public csp::variables::Int
00097 {
00098   public:
00099     Variable(const Problem& problem, int min, int max, int index) :
00100         csp::variables::Int(problem, min, max), m_index(index) {}
00101 
00102     int index() const { return m_index; }
00103 
00104   private:
00105     int m_index;
00106 };
00107 
00108 
00109 CSP_NAMESPACE_END(Puzzle)
00110 
00111 
00112 #endif // _CSP_EXAMPLES_Puzzle_H
00113 
00114 // Local Variables:
00115 // mode: C++
00116 // End:

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