/// Constructor for cloning e CrowdedChess(bool share, CrowdedChess& e) : Script(share,e), n(e.n) { s.update(*this, share, e.s); queens.update(*this, share, e.queens); rooks.update(*this, share, e.rooks); knights.update(*this, share, e.knights); }

/// Print solution virtual void print(std::ostream& os) const { bool assigned = true; for (int i=0; i<succ.size(); i++) { if (!succ[i].assigned()) { assigned = false; break; } } if (assigned) { os << "\tTour: "; int i=0; do { os << i << " -> "; i=succ[i].val(); } while (i != 0); os << 0 << std::endl; os << "\tCost: " << total << std::endl; } else { os << "\tTour: " << std::endl; for (int i=0; i<succ.size(); i++) { os << "\t" << i << " -> " << succ[i] << std::endl; } os << "\tCost: " << total << std::endl; } }

virtual void print(std::ostream& os) const { os << "queens\t"; for (int i = 0; i < q.size(); i++) { os << q[i]; if ((i+1) % (int)sqrt(q.size()) == 0) { os << std::endl << "\t"; } } os << std::endl; }

// Constructor for cloning s Pandigital(bool share, Pandigital& s) : Script(share,s), base(s.base) { x.update(*this, share, s.x); num1.update(*this, share, s.num1); num2.update(*this, share, s.num2); res.update(*this, share, s.res); }

/// Actual model GolombRuler(const SizeOptions& opt) : IntMinimizeScript(opt), m(*this,opt.size(),0, (opt.size() < 31) ? (1 << (opt.size()-1))-1 : Int::Limits::max) { // Assume first mark to be zero rel(*this, m[0], IRT_EQ, 0); // Order marks rel(*this, m, IRT_LE); // Number of marks and differences const int n = m.size(); const int n_d = (n*n-n)/2; // Array of differences IntVarArgs d(n_d); // Setup difference constraints for (int k=0, i=0; i<n-1; i++) for (int j=i+1; j<n; j++, k++) // d[k] is m[j]-m[i] and must be at least sum of first j-i integers rel(*this, d[k] = expr(*this, m[j]-m[i]), IRT_GQ, (j-i)*(j-i+1)/2); distinct(*this, d, opt.icl()); // Symmetry breaking if (n > 2) rel(*this, d[0], IRT_LE, d[n_d-1]); branch(*this, m, INT_VAR_NONE(), INT_VAL_MIN()); }

// Constructor for cloning s Investments(bool share, Investments& s) : MaximizeScript(share,s) { x.update(*this, share, s.x); total_persons.update(*this, share, s.total_persons); total_budget.update(*this, share, s.total_budget); total_projects.update(*this, share, s.total_projects); total_values.update(*this, share, s.total_values); }

/// Print solution virtual void print(std::ostream& os) const { os << "\t"; for (int i=0; i<x.size(); i++) os << "(" << x[i] << "," << y[i] << ") "; os << std::endl; }

/// Print solution virtual void print(std::ostream& os) const { const int n = x.size(); os << "\tx[" << n << "] = {"; for (int i = 0; i < n-1; i++) os << x[i] << "(" << d[i] << "),"; os << x[n-1] << "}" << std::endl; }

/// Actual model Alpha(const Options& opt) : Script(opt), le(*this,n,1,n) { IntVar a(le[ 0]), b(le[ 1]), c(le[ 2]), e(le[ 4]), f(le[ 5]), g(le[ 6]), h(le[ 7]), i(le[ 8]), j(le[ 9]), k(le[10]), l(le[11]), m(le[12]), n(le[13]), o(le[14]), p(le[15]), q(le[16]), r(le[17]), s(le[18]), t(le[19]), u(le[20]), v(le[21]), w(le[22]), x(le[23]), y(le[24]), z(le[25]); rel(*this, b+a+l+l+e+t == 45, opt.icl()); rel(*this, c+e+l+l+o == 43, opt.icl()); rel(*this, c+o+n+c+e+r+t == 74, opt.icl()); rel(*this, f+l+u+t+e == 30, opt.icl()); rel(*this, f+u+g+u+e == 50, opt.icl()); rel(*this, g+l+e+e == 66, opt.icl()); rel(*this, j+a+z+z == 58, opt.icl()); rel(*this, l+y+r+e == 47, opt.icl()); rel(*this, o+b+o+e == 53, opt.icl()); rel(*this, o+p+e+r+a == 65, opt.icl()); rel(*this, p+o+l+k+a == 59, opt.icl()); rel(*this, q+u+a+r+t+e+t == 50, opt.icl()); rel(*this, s+a+x+o+p+h+o+n+e == 134, opt.icl()); rel(*this, s+c+a+l+e == 51, opt.icl()); rel(*this, s+o+l+o == 37, opt.icl()); rel(*this, s+o+n+g == 61, opt.icl()); rel(*this, s+o+p+r+a+n+o == 82, opt.icl()); rel(*this, t+h+e+m+e == 72, opt.icl()); rel(*this, v+i+o+l+i+n == 100, opt.icl()); rel(*this, w+a+l+t+z == 34, opt.icl()); distinct(*this, le, opt.icl()); switch (opt.branching()) { case BRANCH_NONE: branch(*this, le, INT_VAR_NONE(), INT_VAL_MIN()); break; case BRANCH_INVERSE: branch(*this, le.slice(le.size()-1,-1), INT_VAR_NONE(), INT_VAL_MIN()); break; case BRANCH_SIZE: branch(*this, le, INT_VAR_SIZE_MIN(), INT_VAL_MIN()); break; } }

/// Print solution virtual void print(std::ostream& os) const { os << "\t"; int a, b; a = b = 0; for (int i = 0; i < x.size(); i++) { a += x[i].val(); b += x[i].val()*x[i].val(); os << x[i] << ", "; } os << " = " << a << ", " << b << std::endl << "\t"; a = b = 0; for (int i = 0; i < y.size(); i++) { a += y[i].val(); b += y[i].val()*y[i].val(); os << y[i] << ", "; } os << " = " << a << ", " << b << std::endl; }

void among(Space& space, IntVarArray x, SetVar ss, IntVar a) { int n = x.size(); BoolVarArgs b(space, n, 0, 1); for(int i = 0; i < n; i++) { rel(space, ss, SRT_SUP, x[i], b[i]); } rel(space, sum(b) == a); }

/// Print solution virtual void print(std::ostream& os) const { os << "queens\t"; for (int i = 0; i < q.size(); i++) { os << q[i] << ", "; if ((i+1) % 10 == 0) os << std::endl << "\t"; } os << std::endl; }

/// Print the solution virtual void print(std::ostream& os) const { os << "\tm = " << m << std::endl << "\tv[] = {"; for (int i = 0; i < v.size(); i++) { os << v[i] << ", "; if ((i+1) % 15 == 0) os << std::endl << "\t "; } os << "};" << std::endl; }

/// Actual model AllInterval(const SizeOptions& opt) : x(*this, opt.size(), 0, opt.size()-1), d(*this, opt.size()-1, 1, opt.size()-1) { const int n = x.size(); // Set up variables for distance for (int i=0; i<n-1; i++) rel(*this, d[i] == abs(x[i+1]-x[i]), opt.icl()); distinct(*this, x, opt.icl()); distinct(*this, d, opt.icl()); // Break mirror symmetry rel(*this, x[0], IRT_LE, x[1]); // Break symmetry of dual solution rel(*this, d[0], IRT_GR, d[n-2]); branch(*this, x, INT_VAR_SIZE_MIN(), INT_VAL_SPLIT_MIN()); }

/// Print solution virtual void print(std::ostream& os) const { #if 0 std::ostringstream outputstring1; #endif const int n = x.size(); os << "\tx[" << n << "] = {"; outputstring << "("; for (int i = 0; i < n-1; i++) { os << x[i] << "(" << abs(x[i+1].val()-x[i].val()) << "),"; outputstring << x[i] << " "; // outputstring << x[i] ; } outputstring << x[n-1] << ")"; os << x[n-1] << "}" << std::endl; // strcpy(result,outputstring.str().c_str()); }

/// The actual problem Queens(const SizeOptions& opt) : q(*this,opt.size(),0,opt.size()-1) { const int n = q.size(); switch (opt.propagation()) { case PROP_BINARY: for (int i = 0; i<n; i++) for (int j = i+1; j<n; j++) { rel(*this, q[i] != q[j]); rel(*this, q[i]+i != q[j]+j); rel(*this, q[i]-i != q[j]-j); } break; case PROP_MIXED: for (int i = 0; i<n; i++) for (int j = i+1; j<n; j++) { rel(*this, q[i]+i != q[j]+j); rel(*this, q[i]-i != q[j]-j); } distinct(*this, q, opt.icl()); break; case PROP_DISTINCT: distinct(*this, IntArgs::create(n,0,1), q, opt.icl()); distinct(*this, IntArgs::create(n,0,-1), q, opt.icl()); distinct(*this, q, opt.icl()); break; } switch(opt.branching()) { case BRANCH_MIN: branch(*this, q, INT_VAR_SIZE_MIN(), INT_VAL_MIN()); break; case BRANCH_MID: branch(*this, q, INT_VAR_SIZE_MIN(), INT_VAL_MIN()); break; case BRANCH_MAX_MAX: branch(*this, q, INT_VAR_SIZE_MAX(), INT_VAL_MIN()); break; case BRANCH_KNIGHT_MOVE: branch(*this, q, INT_VAR_MIN_MIN(), INT_VAL_MED()); break; } }

/// Print solution virtual void print(std::ostream& os) const { os << "\tNumber of Queens: " << q << std::endl; os << "\tBoard: " << b << std::endl; if (b.assigned()) { // Print a nice board bool* placed = new bool[n*n]; for (int i=0; i<n*n; i++) placed[i] = false; for (int i=0; i<n*n; i++) placed[b[i].val()] = true; for (int j=0; j<n; j++) { std::cout << "\t\t"; for (int i=0; i<n; i++) std::cout << (placed[xy(i,j)] ? 'Q' : '.') << ' '; std::cout << std::endl; } delete [] placed; } os << std::endl; }

/// Actual model AllInterval(const SizeOptions& opt) : x(*this, opt.size(), 0, opt.size() - 1) { const int n = x.size(); IntVarArgs d(n-1); // Set up variables for distance for (int i=0; i<n-1; i++) d[i] = expr(*this, abs(x[i+1]-x[i]), opt.icl()); // Constrain them to be between 1 and n-1 dom(*this, d, 1, n-1); distinct(*this, x, opt.icl()); distinct(*this, d, opt.icl()); // Break mirror symmetry rel(*this, x[0], IRT_LE, x[1]); // Break symmetry of dual solution rel(*this, d[0], IRT_GR, d[n-2]); branch(*this, x, INT_VAR_SIZE_MIN, INT_VAL_SPLIT_MIN); }

/// Constructor used during cloning \a s Partition(bool share, Partition& s) : Script(share,s) { x.update(*this, share, s.x); y.update(*this, share, s.y); }

/// Constructor for cloning \a s Photo(bool share, Photo& s) : IntMinimizeScript(share,s), spec(s.spec) { pos.update(*this, share, s.pos); violations.update(*this, share, s.violations); }

/// Constructor for cloning \a s Kakuro(bool share, Kakuro& s) : Script(share,s), w(s.w), h(s.h) { f.update(*this, share, s.f); }

/// Constructor for cloning \a s WordSquare(bool share, WordSquare& s) : Script(share,s), w_l(s.w_l) { letters.update(*this, share, s.letters); }

/// Constructor for cloning \a l LangfordNumber(bool share, LangfordNumber& l) : Script(share, l), k(l.k), n(l.n) { y.update(*this, share, l.y); }

/// Actual model AllInterval(const SizeOptions& opt) : Script(opt), x(*this, opt.size(), 0, 66) { // 66 or opt.size() - 1 const int n = x.size(); IntVarArgs d(n-1); IntVarArgs dd(66); IntVarArgs xx_(n); // pitch class for AllInterval Chords IntVar douze; Rnd r(1U); if ((opt.model() == MODEL_SET) || (opt.model() == MODEL_SET_CHORD) || (opt.model() == MODEL_SSET_CHORD) ||(opt.model() == MODEL_SYMMETRIC_SET)) // Modele original : serie { // Set up variables for distance for (int i=0; i<n-1; i++) d[i] = expr(*this, abs(x[i+1]-x[i]), opt.ipl()); // Constrain them to be between 1 and n-1 dom(*this, d, 1, n-1); dom(*this, x, 0, n-1); if((opt.model() == MODEL_SET_CHORD) || (opt.model() == MODEL_SSET_CHORD)) { /*expr(*this,dd[0]==0); // Set up variables for distance for (int i=0; i<n-1; i++) { expr(*this, dd[i+1] == (dd[i]+d[i])%12, opt.icl()); } // Constrain them to be between 1 and n-1 dom(*this, dd,0, n-1); distinct(*this, dd, opt.icl()); */ rel(*this, abs(x[0]-x[n-1]) == 6, opt.ipl()); } if(opt.symmetry()) { // Break mirror symmetry (renversement) rel(*this, x[0], IRT_LE, x[1]); // Break symmetry of dual solution (retrograde de la serie) -> 1928 solutions pour accords de 12 sons rel(*this, d[0], IRT_GR, d[n-2]); } //series symetriques if ((opt.model() == MODEL_SYMMETRIC_SET)|| (opt.model() == MODEL_SSET_CHORD)) { rel (*this, d[n/2 - 1] == 6); // pivot = triton for (int i=0; i<(n/2)-2; i++) rel(*this,d[i]+d[n-i-2]==12); } } else { for (int j=0; j<n; j++) xx_[j] = expr(*this, x[j] % 12); dom(*this, xx_, 0, 11); distinct(*this, xx_, opt.ipl()); //intervalles for (int i=0; i<n-1; i++) d[i] = expr(*this,x[i+1] - x[i],opt.ipl()); dom(*this, d, 1, n-1); dom(*this, x, 0, n * (n - 1) / 2.); //d'autres choses dont on est certain (contraintes redondantes) : rel(*this, x[0] == 0); rel(*this, x[n-1] == n * (n - 1) / 2.); // break symmetry of dual solution (renversement de l'accord) if(opt.symmetry()) rel(*this, d[0], IRT_GR, d[n-2]); //accords symetriques if (opt.model() == MODEL_SYMMETRIC_CHORD) { rel (*this, d[n/2 - 1] == 6); // pivot = triton for (int i=0; i<(n/2)-2; i++) rel(*this,d[i]+d[n-i-2]==12); } if (opt.model() == MODEL_PARALLEL_CHORD) { rel (*this, d[n/2 - 1] == 6); // pivot = triton for (int i=0; i<(n/2)-2; i++) rel(*this,d[i]+d[n/2 + i]==12); } } distinct(*this, x, opt.ipl()); distinct(*this, d, opt.ipl()); #if 0 //TEST IntVarArray counter(*this,12,0,250); IntVar testcounter(*this,0,250); for (int i=1; i<11; i++) { count(*this, d, i,IRT_EQ,testcounter,opt.icl()); // OK } count(*this, d, counter,opt.icl()); // OK #endif //END TEST if(opt.branching() == 0) branch(*this, x, INT_VAR_SIZE_MIN(), INT_VAL_SPLIT_MIN()); else branch(*this, x, INT_VAR_RND(r), INT_VAL_RND(r)); }

/// Constructor for cloning \a s Donald(bool share, Donald& s) : Script(share,s) { le.update(*this, share, s.le); }

/// Constructor for cloning \a e AllInterval(AllInterval& e) : Script(e) { x.update(*this, e.x); }

// Constructor for cloning s Speakers(bool share, Speakers& s) : Script(share,s) { x.update(*this, share, s.x); }

/// Constructor for cloning \a s GraphColor(bool share, GraphColor& s) : IntMinimizeScript(share,s), g(s.g) { v.update(*this, share, s.v); m.update(*this, share, s.m); }

/// Constructor for cloning \a s OrthoLatinSquare(bool share, OrthoLatinSquare& s) : Script(share,s), n(s.n) { x1.update(*this, share, s.x1); x2.update(*this, share, s.x2); }

SquarePacking(bool share, SquarePacking& sp) : Script(share, sp) { x.update(*this, share, sp.x); y.update(*this, share, sp.y); s.update(*this, share, sp.s); }