afc.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 AFC : public Test::Base {
00047 protected:
00049 class TestSpace : public Gecode::Space {
00050 protected:
00052 Gecode::IntVar x, y;
00053 public:
00055 TestSpace(void) : x(*this,0,10), y(*this,0,10) {}
00057 TestSpace(bool share, TestSpace& s) : Space(share,s) {
00058 x.update(*this,share,s.x);
00059 y.update(*this,share,s.y);
00060 }
00062 void post(void) {
00063 Gecode::rel(*this, x, Gecode::IRT_LE, y);
00064 }
00066 virtual Space* copy(bool share) {
00067 return new TestSpace(share,*this);
00068 }
00069 };
00071 static const int n_ops = 8 * 1024;
00073 static const int n = 16;
00075 int space(TestSpace* s[]) {
00076 int i = rand(n);
00077 while (s[i] == NULL)
00078 i = (i+1) % n;
00079 return i;
00080 }
00082 int index(void) {
00083 return rand(n);
00084 }
00085 public:
00087 AFC(void) : Test::Base("AFC") {}
00089 bool run(void) {
00090
00091 TestSpace* s[n];
00092
00093 int n_s = 1;
00094
00095 for (int i=n; i--; )
00096 s[i] = NULL;
00097 s[0] = new TestSpace;
00098
00099 for (int o=n_ops; o--; )
00100 switch (rand(3)) {
00101 case 0:
00102
00103 {
00104 int i = index();
00105 if ((s[i] != NULL)) {
00106 if (n_s > 1) {
00107 delete s[i]; s[i]=NULL; n_s--;
00108 } else {
00109 break;
00110 }
00111 }
00112 int j = space(s);
00113 (void) s[j]->status();
00114 s[i] = static_cast<TestSpace*>(s[j]->clone());
00115 n_s++;
00116 }
00117 break;
00118 case 1:
00119
00120 if (n_s > 1) {
00121 int i = space(s);
00122 delete s[i]; s[i]=NULL; n_s--;
00123 }
00124 break;
00125 case 2:
00126
00127 s[space(s)]->post();
00128 break;
00129 default:
00130 GECODE_NEVER;
00131 }
00132
00133 for (int i=n; i--; )
00134 delete s[i];
00135 return true;
00136 }
00137 };
00138
00139 AFC afc;
00140
00141 }
00142
00143