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 #include <gecode/kernel.hh>
00035 #include <gecode/int.hh>
00036
00037 #include "test/test.hh"
00038
00039 namespace Test {
00040
00042 class AFC : public Test::Base {
00043 protected:
00045 class TestSpace : public Gecode::Space {
00046 protected:
00048 Gecode::IntVar x, y;
00049 public:
00051 TestSpace(void) : x(*this,0,10), y(*this,0,10) {}
00053 TestSpace(TestSpace& s) : Space(s) {
00054 x.update(*this,s.x);
00055 y.update(*this,s.y);
00056 }
00058 void post(void) {
00059 Gecode::rel(*this, x, Gecode::IRT_LE, y);
00060 }
00062 virtual Space* copy(void) {
00063 return new TestSpace(*this);
00064 }
00065 };
00067 static const int n_ops = 8 * 1024;
00069 static const int n = 16;
00071 int space(TestSpace* s[]) {
00072 int i = rand(n);
00073 while (s[i] == NULL)
00074 i = (i+1) % n;
00075 return i;
00076 }
00078 int index(void) {
00079 return rand(n);
00080 }
00081 public:
00083 AFC(void) : Test::Base("AFC") {}
00085 bool run(void) {
00086
00087 TestSpace* s[n];
00088
00089 int n_s = 1;
00090
00091 for (int i=n; i--; )
00092 s[i] = NULL;
00093 s[0] = new TestSpace;
00094
00095 for (int o=n_ops; o--; )
00096 switch (rand(3)) {
00097 case 0:
00098
00099 {
00100 int i = index();
00101 if ((s[i] != NULL)) {
00102 if (n_s > 1) {
00103 delete s[i]; s[i]=NULL; n_s--;
00104 } else {
00105 break;
00106 }
00107 }
00108 int j = space(s);
00109 (void) s[j]->status();
00110 s[i] = static_cast<TestSpace*>(s[j]->clone());
00111 n_s++;
00112 }
00113 break;
00114 case 1:
00115
00116 if (n_s > 1) {
00117 int i = space(s);
00118 delete s[i]; s[i]=NULL; n_s--;
00119 }
00120 break;
00121 case 2:
00122
00123 s[space(s)]->post();
00124 break;
00125 default:
00126 GECODE_NEVER;
00127 }
00128
00129 for (int i=n; i--; )
00130 delete s[i];
00131 return true;
00132 }
00133 };
00134
00135 AFC afc;
00136
00137 }
00138
00139