assign.cc
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #include "test/assign.hh"
00039
00040 #include "gecode/kernel.hh"
00041 #include "gecode/int.hh"
00042 #include "gecode/search.hh"
00043
00044 namespace Test { namespace Assign {
00045
00047 class IntTestSpace : public Gecode::Space {
00048 public:
00050 Gecode::IntVarArray x;
00052 IntTestSpace(int n, Gecode::IntSet& d)
00053 : x(this, n, d) {}
00055 IntTestSpace(bool share, IntTestSpace& s)
00056 : Gecode::Space(share,s) {
00057 x.update(this, share, s.x);
00058 }
00060 virtual Gecode::Space* copy(bool share) {
00061 return new IntTestSpace(share,*this);
00062 }
00063 };
00064
00066 class BoolTestSpace : public Gecode::Space {
00067 public:
00069 Gecode::BoolVarArray x;
00071 BoolTestSpace(int n)
00072 : x(this, n, 0, 1) {}
00074 BoolTestSpace(bool share, BoolTestSpace& s)
00075 : Gecode::Space(share,s) {
00076 x.update(this, share, s.x);
00077 }
00079 virtual Gecode::Space* copy(bool share) {
00080 return new BoolTestSpace(share,*this);
00081 }
00082 };
00083
00084
00090
00091 const Gecode::IntAssign int_assign[] = {
00092 Gecode::INT_ASSIGN_MIN,
00093 Gecode::INT_ASSIGN_MED,
00094 Gecode::INT_ASSIGN_MAX
00095 };
00097 const int n_int_assign =
00098 sizeof(int_assign)/sizeof(Gecode::IntAssign);
00100 const char* int_assign_name[] = {
00101 "INT_ASSIGN_MIN",
00102 "INT_ASSIGN_MED",
00103 "INT_ASSIGN_MAX"
00104 };
00106
00107 IntTest::IntTest(const std::string& s, int a, const Gecode::IntSet& d)
00108 : Base("Assign::Int::"+s), arity(a), dom(d) {
00109 }
00110
00111 bool
00112 IntTest::run(void) {
00113 using namespace Gecode;
00114 IntTestSpace* root = new IntTestSpace(arity,dom);
00115 post(root, root->x);
00116
00117 for (int val = n_int_assign; val--; ) {
00118 IntTestSpace* clone = static_cast<IntTestSpace*>(root->clone(false));
00119 Gecode::Search::Options o;
00120 o.a_d = Base::rand(10);
00121 o.c_d = Base::rand(10);
00122 assign(clone, clone->x, int_assign[val]);
00123 Gecode::DFS<IntTestSpace> e_s(clone, o);
00124 delete clone;
00125
00126
00127 int solutions = 0;
00128 while (Space* s = e_s.next()) {
00129 delete s; solutions++;
00130 }
00131 if (solutions != 1) {
00132 std::cout << "FAILURE" << std::endl
00133 << "\tc_d=" << o.c_d << ", a_d=" << o.a_d << std::endl
00134 << "\t" << int_assign_name[val] << std::endl;
00135 delete root;
00136 return false;
00137 }
00138 }
00139 delete root;
00140 return true;
00141 }
00142
00143 BoolTest::BoolTest(const std::string& s, int a)
00144 : Base("Assign::Bool::"+s), arity(a) {
00145 }
00146
00147 bool
00148 BoolTest::run(void) {
00149 using namespace Gecode;
00150 BoolTestSpace* root = new BoolTestSpace(arity);
00151 post(root, root->x);
00152
00153 for (int val = n_int_assign; val--; ) {
00154 BoolTestSpace* clone = static_cast<BoolTestSpace*>(root->clone(false));
00155 Gecode::Search::Options o;
00156 o.a_d = Base::rand(10);
00157 o.c_d = Base::rand(10);
00158 assign(clone, clone->x, int_assign[val]);
00159 Gecode::DFS<BoolTestSpace> e_s(clone, o);
00160 delete clone;
00161
00162
00163 int solutions = 0;
00164 while (Space* s = e_s.next()) {
00165 delete s; solutions++;
00166 }
00167 if (solutions != 1) {
00168 std::cout << "FAILURE" << std::endl
00169 << "\tc_d=" << o.c_d << ", a_d=" << o.a_d << std::endl
00170 << "\t" << int_assign_name[val] << std::endl;
00171 delete root;
00172 return false;
00173 }
00174 }
00175 delete root;
00176 return true;
00177 }
00178
00179 }}
00180
00181