00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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);
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();
00088
00089
00090
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
00113
00114
00115
00116