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 "examples/support.hh"
00039
00045 class Partition : public Example {
00046 protected:
00048 IntVarArray x;
00050 IntVarArray y;
00051 public:
00053 Partition(const SizeOptions& opt)
00054 : x(this,opt.size(),1,2*opt.size()),
00055 y(this,opt.size(),1,2*opt.size()) {
00056 const int n = opt.size();
00057
00058 rel(this, x, IRT_LE);
00059 rel(this, y, IRT_LE);
00060
00061 rel(this, x[0], IRT_LE, y[0]);
00062
00063 IntVarArgs xy(2*n);
00064 for (int i = n; i--; ) {
00065 xy[i] = x[i]; xy[n+i] = y[i];
00066 }
00067 distinct(this, xy, opt.icl());
00068 IntArgs c(2*n);
00069 for (int i = n; i--; ) {
00070 c[i] = 1; c[n+i] = -1;
00071 }
00072 linear(this, c, xy, IRT_EQ,0);
00073
00074
00075 IntVarArray sxy(this,2*n,1,4*n*n);
00076 IntVarArgs sx(n);
00077 IntVarArgs sy(n);
00078
00079 for (int i = n; i--; ) {
00080 mult(this,x[i],x[i],sxy[i]); sx[i] = sxy[i];
00081 mult(this,y[i],y[i],sxy[n+i]); sy[i] = sxy[n+i];
00082 }
00083 linear(this, c,sxy,IRT_EQ,0);
00084
00085
00086 linear(this, x, IRT_EQ, 2*n*(2*n+1)/4);
00087 linear(this, y, IRT_EQ, 2*n*(2*n+1)/4);
00088 linear(this, sx, IRT_EQ, 2*n*(2*n+1)*(4*n+1)/12);
00089 linear(this, sy, IRT_EQ, 2*n*(2*n+1)*(4*n+1)/12);
00090 branch(this, xy, INT_VAR_SIZE_MIN, INT_VAL_MIN);
00091 }
00092
00094 Partition(bool share, Partition& s) : Example(share,s) {
00095 x.update(this, share, s.x);
00096 y.update(this, share, s.y);
00097 }
00099 virtual Space*
00100 copy(bool share) {
00101 return new Partition(share,*this);
00102 }
00104 virtual void
00105 print(std::ostream& os) {
00106 os << "\t";
00107 int a, b;
00108 a = b = 0;
00109 for (int i = 0; i < x.size(); i++) {
00110 a += x[i].val();
00111 b += x[i].val()*x[i].val();
00112 os << x[i] << ", ";
00113 }
00114 os << " = " << a << ", " << b << std::endl << "\t";
00115 a = b = 0;
00116 for (int i = 0; i < y.size(); i++) {
00117 a += y[i].val();
00118 b += y[i].val()*y[i].val();
00119 os << y[i] << ", ";
00120 }
00121 os << " = " << a << ", " << b << std::endl;
00122 }
00123 };
00124
00129 int
00130 main(int argc, char* argv[]) {
00131 SizeOptions opt("Partition");
00132 opt.size(32);
00133 opt.icl(ICL_DOM);
00134 opt.parse(argc,argv);
00135 Example::run<Partition,DFS,SizeOptions>(opt);
00136 return 0;
00137 }
00138
00139
00140
00141