Generated on Wed Nov 1 15:04:27 2006 for Gecode by doxygen 1.4.5

cars.cc

Go to the documentation of this file.
00001 /*
00002  *  Main authors:
00003  *     Christian Schulte <schulte@gecode.org>
00004  *
00005  *  Copyright:
00006  *     Christian Schulte, 2003
00007  *
00008  *  Last modified:
00009  *     $Date: 2005-10-19 14:46:42 +0200 (Wed, 19 Oct 2005) $ by $Author: schulte $
00010  *     $Revision: 2376 $
00011  *
00012  *  This file is part of Gecode, the generic constraint
00013  *  development environment:
00014  *     http://www.gecode.org
00015  *
00016  *  See the file "LICENSE" for information on usage and
00017  *  redistribution of this file, and for a
00018  *     DISCLAIMER OF ALL WARRANTIES.
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     // redundant constraints
00111 
00112     /*
00113       O11+O21+O31+O41+O51+O61+O71+O81 #>= 4,
00114       O11+O21+O31+O41+O51+O61         #>= 3,
00115       O11+O21+O31+O41                 #>= 2,
00116       O11+O21                         #>= 1,
00117 
00118       O12+O22+O32+O42+O52+O62+O72     #>= 4,
00119       O12+O22+O32+O42                 #>= 2,
00120       O12                             #>= 0,
00121 
00122       O13+O23+O33+O43+O53+O63+O73     #>= 2,
00123       O13+O23+O33+O43                 #>= 1,
00124       O13                             #>= 0,
00125 
00126       O14+O24+O34+O44+O54             #>= 2,
00127 
00128       O15+O25+O35+O45+O55             #>= 1,
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 // STATISTICS: example-any
00165