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 int j = space(s);
00112 (void) s[j]->status();
00113 s[i] = static_cast<TestSpace*>(s[j]->clone());
00114 n_s++;
00115 }
00116 break;
00117 case 1:
00118
00119 if (n_s > 1) {
00120 int i = space(s);
00121 delete s[i]; s[i]=NULL; n_s--;
00122 }
00123 break;
00124 case 2:
00125
00126 s[space(s)]->post();
00127 break;
00128 default:
00129 GECODE_NEVER;
00130 }
00131
00132 for (int i=n; i--; )
00133 delete s[i];
00134 return true;
00135 }
00136 };
00137
00138 AFC afc;
00139
00140 }
00141
00142