brancher-handle.cpp
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 <gecode/kernel.hh>
00039 #include <gecode/int.hh>
00040
00041 #include "test/test.hh"
00042
00043 namespace Test {
00044
00046 class BrancherHandle : public Test::Base {
00047 protected:
00049 class TestSpace : public Gecode::Space {
00050 protected:
00052 Gecode::IntVarArray x;
00053 public:
00055 TestSpace(void) : x(*this,2,0,10) {}
00057 TestSpace(bool share, TestSpace& s) : Space(share,s) {
00058 x.update(*this,share,s.x);
00059 }
00061 Gecode::BrancherHandle post(void) {
00062 using namespace Gecode;
00063 return Gecode::branch(*this, x, INT_VAR_NONE(), INT_VAL_MIN());
00064 }
00066 virtual Space* copy(bool share) {
00067 return new TestSpace(share,*this);
00068 }
00069 };
00071 static const int n_b = 1024;
00073 int index(void) {
00074
00075 return 4;
00076 }
00077 public:
00079 BrancherHandle(void) : Test::Base("BrancherHandle") {}
00081 bool run(void) {
00082 using namespace Gecode;
00083 TestSpace* s = new TestSpace;
00084
00085
00086 for (int i=0; i<n_b; i++) {
00087 Gecode::BrancherHandle b(s->post());
00088 if (!b(*s)) return false;
00089 b.kill(*s);
00090 if (b(*s)) return false;
00091 }
00092
00093 if (s->status() != SS_SOLVED)
00094 return false;
00095
00096
00097 Gecode::BrancherHandle bs[n_b];
00098
00099
00100 for (int i=0; i<n_b; i++) {
00101 Gecode::BrancherHandle b(s->post());
00102 if (!b(*s)) return false;
00103 bs[i] = b;
00104 }
00105 for (int i=0; i<n_b; i++) {
00106 bs[i].kill(*s);
00107 if (bs[i](*s)) return false;
00108 }
00109 if (s->status() != SS_SOLVED)
00110 return false;
00111
00112
00113 for (int i=0; i<n_b; i++) {
00114 Gecode::BrancherHandle b(s->post());
00115 if (!b(*s)) return false;
00116 bs[i] = b;
00117 }
00118 for (int i=n_b; i--; ) {
00119 bs[i].kill(*s);
00120 if (bs[i](*s)) return false;
00121 }
00122 if (s->status() != SS_SOLVED)
00123 return false;
00124
00125
00126 for (int i=0; i<n_b; i++) {
00127 Gecode::BrancherHandle b(s->post());
00128 if (!b(*s)) return false;
00129 bs[i] = b;
00130 }
00131 int a = n_b;
00132 while (a > 0) {
00133 int i = rand(n_b);
00134 if (bs[i](*s)) {
00135 bs[i].kill(*s); a--;
00136 }
00137 }
00138 if (s->status() != SS_SOLVED)
00139 return false;
00140
00141 return true;
00142 }
00143 };
00144
00145 BrancherHandle bh;
00146
00147 }
00148
00149