00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "examples/support.hh"
00023
00029 IntArgs l1(6, 1,0,0,0,1,1);
00030 IntArgs l2(6, 0,0,1,1,0,1);
00031 IntArgs l3(6, 1,0,0,0,1,0);
00032 IntArgs l4(6, 1,1,0,1,0,0);
00033 IntArgs l5(6, 0,0,1,0,0,0);
00035
00045 class Cars : public Example {
00046 private:
00047 IntVarArray x; BoolVarArray y;
00048 public:
00049
00050 BoolVar& o(int i, int j) {
00051 return y[(i-1)*5+j-1];
00052 }
00053
00054 void
00055 atmost(int n, int m) {
00056 count(this, x, m, IRT_LQ, n);
00057 }
00058
00059 void ele(const IntArgs& l, int i, int j, int k) {
00060 element(this, l, x[i-1], o(j,k));
00061 }
00062
00063 void sum(int n, BoolVar& b0, BoolVar& b1) {
00064 BoolVarArgs b(2);
00065 b[0]=b0; b[1]=b1;
00066 linear(this, b,IRT_LQ,n);
00067 }
00068
00069 void sum(int n, BoolVar& b0, BoolVar& b1, BoolVar& b2) {
00070 BoolVarArgs b(3);
00071 b[0]=b0; b[1]=b1; b[2]=b2;
00072 linear(this, b,IRT_LQ,n);
00073 }
00074
00075 void sum(int n,
00076 BoolVar& b0, BoolVar& b1, BoolVar& b2, BoolVar& b3, BoolVar& b4) {
00077 BoolVarArgs b(5);
00078 b[0]=b0; b[1]=b1; b[2]=b2; b[3]=b3; b[4]=b4;
00079 linear(this, b,IRT_LQ,n);
00080 }
00081
00082 Cars(const Options&)
00083 : x(this,10,0,5), y(this,50,0,1) {
00084 atmost(1,0);
00085 atmost(1,1);
00086 atmost(2,2);
00087 atmost(2,3);
00088 atmost(2,4);
00089 atmost(2,5);
00090
00091 for (int i = 1; i < 11; i++) {
00092 ele(l1,i,i,1);
00093 ele(l2,i,i,2);
00094 ele(l3,i,i,3);
00095 ele(l4,i,i,4);
00096 ele(l5,i,i,5);
00097 }
00098
00099 for (int i = 1; i <= 9; i++)
00100 sum(1,o(i,1),o(i+1,1));
00101 for (int i = 1; i <= 8; i++)
00102 sum(2,o(i,2),o(i+1,2),o(i+2,2));
00103 for (int i = 1; i <= 8; i++)
00104 sum(1,o(i,3),o(i+1,3),o(i+2,3));
00105 for (int i = 1; i <= 6; i++)
00106 sum(2,o(i,4),o(i+1,4),o(i+2,4),o(i+3,4),o(i+4,4));
00107 for (int i = 1; i <= 6; i++)
00108 sum(1,o(i,5),o(i+1,5),o(i+2,5),o(i+3,5),o(i+4,5));
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131 branch(this, x, BVAR_SIZE_MIN, BVAL_MIN);
00132 }
00133
00134 Cars(bool share, Cars& s)
00135 : Example(share,s) {
00136 x.update(this,share,s.x);
00137 y.update(this,share,s.y);
00138 }
00139
00140 virtual Space*
00141 copy(bool share) {
00142 return new Cars(share,*this);
00143 }
00144
00145 virtual void
00146 print(void) {
00147 std::cout << "\t";
00148 for (int i = 0; i < x.size(); i++)
00149 std::cout << x[i] << ", ";
00150 std::cout << std::endl;
00151 }
00152 };
00153
00154 int
00155 main(int argc, char** argv) {
00156 Options o("Cars");
00157 o.solutions = 0;
00158 o.iterations = 100;
00159 o.parse(argc,argv);
00160 Example::run<Cars,DFS>(o);
00161 return 0;
00162 }
00163
00164
00165