Something went wrong. Try again.
This repository has no description
Something went wrong. Try again.
44 kB · 1261 lines
C++
at develop
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- *//* * Main authors: * Christian Schulte <schulte@gecode.org> * * Copyright: * Christian Schulte, 2005 * * This file is part of Gecode, the generic constraint * development environment: * http://www.gecode.org * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */
#include "test/int.hh"
#include <cmath>#include <algorithm>
#include <gecode/minimodel.hh>
namespace Test { namespace Int {
/// %Tests for arithmetic constraints namespace Arithmetic {
/** * \defgroup TaskTestIntArithmetic Arithmetic constraints * \ingroup TaskTestInt */ //@{ /// %Test for multiplication constraint class MultXYZ : public Test { public: /// Create and register test MultXYZ(const std::string& s, const Gecode::IntSet& d, Gecode::IntPropLevel ipl) : Test("Arithmetic::Mult::XYZ::"+str(ipl)+"::"+s,3,d,false,ipl) {} /// %Test whether \a x is solution virtual bool solution(const Assignment& x) const { double d0 = static_cast<double>(x[0]); double d1 = static_cast<double>(x[1]); double d2 = static_cast<double>(x[2]); return d0*d1 == d2; } /// Post constraint on \a x virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) { Gecode::mult(home, x[0], x[1], x[2], ipl); } };
/// %Test for multiplication constraint with shared variables class MultXXY : public Test { public: /// Create and register test MultXXY(const std::string& s, const Gecode::IntSet& d, Gecode::IntPropLevel ipl) : Test("Arithmetic::Mult::XXY::"+str(ipl)+"::"+s,2,d,false,ipl) {} /// %Test whether \a x is solution virtual bool solution(const Assignment& x) const { double d0 = static_cast<double>(x[0]); double d1 = static_cast<double>(x[0]); double d2 = static_cast<double>(x[1]); return d0*d1 == d2; } /// Post constraint on \a x virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) { Gecode::mult(home, x[0], x[0], x[1], ipl); } };
/// %Test for multiplication constraint with shared variables class MultXYX : public Test { public: /// Create and register test MultXYX(const std::string& s, const Gecode::IntSet& d, Gecode::IntPropLevel ipl) : Test("Arithmetic::Mult::XYX::"+str(ipl)+"::"+s,2,d,false,ipl) {} /// %Test whether \a x is solution virtual bool solution(const Assignment& x) const { double d0 = static_cast<double>(x[0]); double d1 = static_cast<double>(x[1]); double d2 = static_cast<double>(x[0]); return d0*d1 == d2; } /// Post constraint on \a x virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) { Gecode::mult(home, x[0], x[1], x[0], ipl); } };
/// %Test for multiplication constraint with shared variables class MultXYY : public Test { public: /// Create and register test MultXYY(const std::string& s, const Gecode::IntSet& d, Gecode::IntPropLevel ipl) : Test("Arithmetic::Mult::XYY::"+str(ipl)+"::"+s,2,d,false,ipl) {} /// %Test whether \a x is solution virtual bool solution(const Assignment& x) const { double d0 = static_cast<double>(x[0]); double d1 = static_cast<double>(x[1]); double d2 = static_cast<double>(x[1]); return d0*d1 == d2; } /// Post constraint on \a x virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) { Gecode::mult(home, x[0], x[1], x[1], ipl); } };
/// %Test for multiplication constraint with shared variables class MultXXX : public Test { public: /// Create and register test MultXXX(const std::string& s, const Gecode::IntSet& d, Gecode::IntPropLevel ipl) : Test("Arithmetic::Mult::XXX::"+str(ipl)+"::"+s,1,d,false,ipl) {} /// %Test whether \a x is solution virtual bool solution(const Assignment& x) const { double d0 = static_cast<double>(x[0]); double d1 = static_cast<double>(x[0]); double d2 = static_cast<double>(x[0]); return d0*d1 == d2; } /// Post constraint on \a x virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) { Gecode::mult(home, x[0], x[0], x[0], ipl); } };
/// %Test for squaring constraint class SqrXY : public Test { public: /// Create and register test SqrXY(const std::string& s, const Gecode::IntSet& d, Gecode::IntPropLevel ipl) : Test("Arithmetic::Sqr::XY::"+str(ipl)+"::"+s,2,d,false,ipl) {} /// %Test whether \a x is solution virtual bool solution(const Assignment& x) const { double d0 = static_cast<double>(x[0]); double d1 = static_cast<double>(x[1]); return d0*d0 == d1; } /// Post constraint on \a x virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) { Gecode::sqr(home, x[0], x[1], ipl); } };
/// %Test for squaring constraint with shared variables class SqrXX : public Test { public: /// Create and register test SqrXX(const std::string& s, const Gecode::IntSet& d, Gecode::IntPropLevel ipl) : Test("Arithmetic::Sqr::XX::"+str(ipl)+"::"+s,1,d,false,ipl) {} /// %Test whether \a x is solution virtual bool solution(const Assignment& x) const { double d0 = static_cast<double>(x[0]); return d0*d0 == d0; } /// Post constraint on \a x virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) { Gecode::sqr(home, x[0], x[0], ipl); } };
/// %Test for square root constraint class SqrtXY : public Test { public: /// Create and register test SqrtXY(const std::string& s, const Gecode::IntSet& d, Gecode::IntPropLevel ipl) : Test("Arithmetic::Sqrt::XY::"+str(ipl)+"::"+s,2,d,false,ipl) {} /// %Test whether \a x is solution virtual bool solution(const Assignment& x) const { double d0 = static_cast<double>(x[0]); double d1 = static_cast<double>(x[1]); return (d0 >= 0) && (d0 >= d1*d1) && (d0 < (d1+1)*(d1+1)); } /// Post constraint on \a x virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) { Gecode::sqrt(home, x[0], x[1], ipl); } };
/// %Test for square root constraint with shared variables class SqrtXX : public Test { public: /// Create and register test SqrtXX(const std::string& s, const Gecode::IntSet& d, Gecode::IntPropLevel ipl) : Test("Arithmetic::Sqrt::XX::"+str(ipl)+"::"+s,1,d,false,ipl) {} /// %Test whether \a x is solution virtual bool solution(const Assignment& x) const { double d0 = static_cast<double>(x[0]); return (d0 >= 0) && (d0 >= d0*d0) && (d0 < (d0+1)*(d0+1)); } /// Post constraint on \a x virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) { Gecode::sqrt(home, x[0], x[0], ipl); } };
/// %Test for power constraint class PowXY : public Test { protected: /// The exponent int n; public: /// Create and register test PowXY(const std::string& s, int n0, const Gecode::IntSet& d, Gecode::IntPropLevel ipl) : Test("Arithmetic::Pow::XY::"+str(n0)+"::"+str(ipl)+"::"+s, 2,d,false,ipl), n(n0) {} /// %Test whether \a x is solution virtual bool solution(const Assignment& x) const { long long int p = 1; for (int i=0; i<n; i++) { p *= x[0]; if ((p < Gecode::Int::Limits::min) || (p > Gecode::Int::Limits::max)) return false; } return p == x[1]; } /// Post constraint on \a x virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) { using namespace Gecode; if (n > 4) pow(home, x[0], n, x[1], ipl); else rel(home, expr(home, pow(x[0],n), ipl), IRT_EQ, x[1], ipl); } };
/// %Test for power constraint with shared variables class PowXX : public Test { protected: /// The exponent int n; public: /// Create and register test PowXX(const std::string& s, int n0, const Gecode::IntSet& d, Gecode::IntPropLevel ipl) : Test("Arithmetic::Pow::XX::"+str(n0)+"::"+str(ipl)+"::"+s, 1,d,false,ipl), n(n0) {} /// %Test whether \a x is solution virtual bool solution(const Assignment& x) const { long long int p = 1; for (int i=0; i<n; i++) { p *= x[0]; if ((p < Gecode::Int::Limits::min) || (p > Gecode::Int::Limits::max)) return false; } return p == x[0]; } /// Post constraint on \a x virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) { Gecode::pow(home, x[0], n, x[0], ipl); } };
bool powgr(int n, long long int r, int x) { assert(r >= 0); long long int y = r; long long int p = 1; do { p *= y; n--; if (p > x) return true; } while (n > 0); return false; }
int fnroot(int n, int x) { if (x < 2) return x; /* * We look for l such that: l^n <= x < (l+1)^n */ long long int l = 1; long long int u = x; do { long long int m = (l + u) >> 1; if (powgr(n,m,x)) u=m; else l=m; } while (l+1 < u); return static_cast<int>(l); }
bool powle(int n, long long int r, int x) { assert(r >= 0); long long int y = r; long long int p = 1; do { p *= y; n--; if (p >= x) return false; } while (n > 0); assert(y < x); return true; }
int cnroot(int n, int x) { if (x < 2) return x; /* * We look for u such that: (u-1)^n < x <= u^n */ long long int l = 1; long long int u = x; do { long long int m = (l + u) >> 1; if (powle(n,m,x)) l=m; else u=m; } while (l+1 < u); return static_cast<int>(u); }
/// %Test for nroot constraint class NrootXY : public Test { protected: /// The root index int n; /// Floor public: /// Create and register test NrootXY(const std::string& s, int n0, const Gecode::IntSet& d, Gecode::IntPropLevel ipl) : Test("Arithmetic::Nroot::XY::"+str(n0)+"::"+str(ipl)+"::"+s, 2,d,false,ipl), n(n0) {} /// %Test whether \a x is solution virtual bool solution(const Assignment& x) const { if (n == 1) return x[0] == x[1]; if ((n % 2 == 0) && ((x[0] < 0) || (x[1] < 0))) return false; int r = (x[0] < 0) ? -cnroot(n,-x[0]) : fnroot(n,x[0]); return r == x[1]; } /// Post constraint on \a x virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) { using namespace Gecode; if (n > 4) nroot(home, x[0], n, x[1], ipl); else rel(home, expr(home, nroot(x[0],n), ipl), IRT_EQ, x[1], ipl); } };
/// %Test for nroot constraint with shared variables class NrootXX : public Test { protected: /// The root index int n; public: /// Create and register test NrootXX(const std::string& s, int n0, const Gecode::IntSet& d, Gecode::IntPropLevel ipl) : Test("Arithmetic::Nroot::XX::"+str(n0)+"::"+str(ipl)+"::"+s, 1,d,false,ipl), n(n0) {} /// %Test whether \a x is solution virtual bool solution(const Assignment& x) const { if (n == 1) return true; if (n % 2 == 0) { return (x[0] >= 0) && (x[0] <= 1); } else { return (x[0] >= -2) && (x[0] <= 1); } } /// Post constraint on \a x virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) { Gecode::nroot(home, x[0], n, x[0], ipl); } };
/// %Test for division/modulo constraint class DivMod : public Test { private: /// Return the absolute value of \a a static int abs(int a) { return a<0 ? -a:a; } /// Return the sign of \a a static int sgn(int a) { return a<0 ? -1:1; } public: /// Create and register test DivMod(const std::string& s, const Gecode::IntSet& d) : Test("Arithmetic::DivMod::"+s,4,d) {} /// %Test whether \a x is solution virtual bool solution(const Assignment& x) const { return x[0] == x[1]*x[2]+x[3] && abs(x[3]) < abs(x[1]) && (x[3] == 0 || sgn(x[3]) == sgn(x[0])); } /// Post constraint on \a x virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) { Gecode::divmod(home, x[0], x[1], x[2], x[3]); } };
/// %Test for division constraint class Div : public Test { public: /// Create and register test Div(const std::string& s, const Gecode::IntSet& d) : Test("Arithmetic::Div::"+s,3,d) {} /// %Test whether \a x is solution virtual bool solution(const Assignment& x) const { if (x[1] == 0) return false; int divsign = (x[0] / x[1] < 0) ? -1 : 1; int divresult = divsign * static_cast<int>(floor(static_cast<double>(std::abs(x[0]))/ static_cast<double>(std::abs(x[1])))); return x[2] == divresult; } /// Post constraint on \a x virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) { Gecode::div(home, x[0], x[1], x[2]); } };
/// %Test for modulo constraint class Mod : public Test { public: /// Create and register test Mod(const std::string& s, const Gecode::IntSet& d) : Test("Arithmetic::Mod::"+s,3,d) {} /// %Test whether \a x is solution virtual bool solution(const Assignment& x) const { if (x[1] == 0) return false; int divsign = (x[0] / x[1] < 0) ? -1 : 1; int divresult = divsign * static_cast<int>(floor(static_cast<double>(std::abs(x[0]))/ static_cast<double>(std::abs(x[1])))); return x[0] == x[1]*divresult+x[2]; } /// Post constraint on \a x virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) { Gecode::mod(home, x[0], x[1], x[2]); } };
/// %Test for absolute value constraint class AbsXY : public Test { public: /// Create and register test AbsXY(const std::string& s, const Gecode::IntSet& d, Gecode::IntPropLevel ipl) : Test("Arithmetic::Abs::XY::"+str(ipl)+"::"+s,2,d,false,ipl) {} /// %Test whether \a x is solution virtual bool solution(const Assignment& x) const { double d0 = static_cast<double>(x[0]); double d1 = static_cast<double>(x[1]); return (d0<0 ? -d0 : d0) == d1; } /// Post constraint on \a x virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) { Gecode::abs(home, x[0], x[1], ipl); } };
/// %Test for absolute value constraint with shared variables class AbsXX : public Test { public: /// Create and register test AbsXX(const std::string& s, const Gecode::IntSet& d, Gecode::IntPropLevel ipl) : Test("Arithmetic::Abs::XX::"+str(ipl)+"::"+s,1,d,false,ipl) {} /// %Test whether \a x is solution virtual bool solution(const Assignment& x) const { double d0 = static_cast<double>(x[0]); double d1 = static_cast<double>(x[0]); return (d0<0 ? -d0 : d0) == d1; } /// Post constraint on \a x virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) { Gecode::abs(home, x[0], x[0], ipl); } };
/// %Test for binary minimum constraint class MinXYZ : public Test { public: /// Create and register test MinXYZ(const std::string& s, const Gecode::IntSet& d, Gecode::IntPropLevel ipl) : Test("Arithmetic::Min::Bin::XYZ::"+str(ipl)+"::"+s,3,d,false,ipl) {} /// %Test whether \a x is solution virtual bool solution(const Assignment& x) const { return std::min(x[0],x[1]) == x[2]; } /// Post constraint on \a x virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) { Gecode::min(home, x[0], x[1], x[2], ipl); } };
/// %Test for binary minimum constraint with shared variables class MinXXY : public Test { public: /// Create and register test MinXXY(const std::string& s, const Gecode::IntSet& d, Gecode::IntPropLevel ipl) : Test("Arithmetic::Min::Bin::XYX::"+str(ipl)+"::"+s,2,d) {} /// %Test whether \a x is solution virtual bool solution(const Assignment& x) const { return std::min(x[0],x[0]) == x[1]; } /// Post constraint on \a x virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) { Gecode::min(home, x[0], x[0], x[1], ipl); } };
/// %Test for binary minimum constraint with shared variables class MinXYX : public Test { public: /// Create and register test MinXYX(const std::string& s, const Gecode::IntSet& d, Gecode::IntPropLevel ipl) : Test("Arithmetic::Min::Bin::XYX::"+str(ipl)+"::"+s,2,d) {} /// %Test whether \a x is solution virtual bool solution(const Assignment& x) const { return std::min(x[0],x[1]) == x[0]; } /// Post constraint on \a x virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) { Gecode::min(home, x[0], x[1], x[0], ipl); } };
/// %Test for binary minimum constraint with shared variables class MinXYY : public Test { public: /// Create and register test MinXYY(const std::string& s, const Gecode::IntSet& d, Gecode::IntPropLevel ipl) : Test("Arithmetic::Min::Bin::XYY::"+str(ipl)+"::"+s,2,d) {} /// %Test whether \a x is solution virtual bool solution(const Assignment& x) const { return std::min(x[0],x[1]) == x[1]; } /// Post constraint on \a x virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) { Gecode::min(home, x[0], x[1], x[1], ipl); } };
/// %Test for binary minimum constraint with shared variables class MinXXX : public Test { public: /// Create and register test MinXXX(const std::string& s, const Gecode::IntSet& d, Gecode::IntPropLevel ipl) : Test("Arithmetic::Min::Bin::XXX::"+str(ipl)+"::"+s,1,d) {} /// %Test whether \a x is solution virtual bool solution(const Assignment& x) const { return std::min(x[0],x[0]) == x[0]; } /// Post constraint on \a x virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) { Gecode::min(home, x[0], x[0], x[0], ipl); } };
/// %Test for binary maximum constraint class MaxXYZ : public Test { public: /// Create and register test MaxXYZ(const std::string& s, const Gecode::IntSet& d, Gecode::IntPropLevel ipl) : Test("Arithmetic::Max::Bin::XYZ::"+str(ipl)+"::"+s,3,d) { contest = CTL_BOUNDS_Z; } /// %Test whether \a x is solution virtual bool solution(const Assignment& x) const { return std::max(x[0],x[1]) == x[2]; } /// Post constraint on \a x virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) { Gecode::max(home, x[0], x[1], x[2], ipl); } };
/// %Test for binary maximum constraint with shared variables class MaxXXY : public Test { public: /// Create and register test MaxXXY(const std::string& s, const Gecode::IntSet& d, Gecode::IntPropLevel ipl) : Test("Arithmetic::Max::Bin::XXY::"+str(ipl)+"::"+s,2,d) {} /// %Test whether \a x is solution virtual bool solution(const Assignment& x) const { return std::max(x[0],x[0]) == x[1]; } /// Post constraint on \a x virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) { Gecode::max(home, x[0], x[0], x[1], ipl); } };
/// %Test for binary maximum constraint with shared variables class MaxXYX : public Test { public: /// Create and register test MaxXYX(const std::string& s, const Gecode::IntSet& d, Gecode::IntPropLevel ipl) : Test("Arithmetic::Max::Bin::XYX::"+str(ipl)+"::"+s,2,d) {} /// %Test whether \a x is solution virtual bool solution(const Assignment& x) const { return std::max(x[0],x[1]) == x[0]; } /// Post constraint on \a x virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) { Gecode::max(home, x[0], x[1], x[0], ipl); } };
/// %Test for binary maximum constraint with shared variables class MaxXYY : public Test { public: /// Create and register test MaxXYY(const std::string& s, const Gecode::IntSet& d, Gecode::IntPropLevel ipl) : Test("Arithmetic::Max::Bin::XYY::"+str(ipl)+"::"+s,2,d) {} /// %Test whether \a x is solution virtual bool solution(const Assignment& x) const { return std::max(x[0],x[1]) == x[1]; } /// Post constraint on \a x virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) { Gecode::max(home, x[0], x[1], x[1], ipl); } };
/// %Test for binary maximum constraint with shared variables class MaxXXX : public Test { public: /// Create and register test MaxXXX(const std::string& s, const Gecode::IntSet& d, Gecode::IntPropLevel ipl) : Test("Arithmetic::Max::Bin::XXX::"+str(ipl)+"::"+s,1,d) {} /// %Test whether \a x is solution virtual bool solution(const Assignment& x) const { return std::max(x[0],x[0]) == x[0]; } /// Post constraint on \a x virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) { Gecode::max(home, x[0], x[0], x[0], ipl); } };
/// %Test for n-ary minimmum constraint class MinNary : public Test { public: /// Create and register test MinNary(Gecode::IntPropLevel ipl) : Test("Arithmetic::Min::Nary::"+str(ipl),4,-4,4,false,ipl) {} /// %Test whether \a x is solution virtual bool solution(const Assignment& x) const { return std::min(std::min(x[0],x[1]), x[2]) == x[3]; } /// Post constraint on \a x virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) { Gecode::IntVarArgs m(3); m[0]=x[0]; m[1]=x[1]; m[2]=x[2]; Gecode::min(home, m, x[3], ipl); } };
/// %Test for n-ary minimmum constraint with shared variables class MinNaryShared : public Test { public: /// Create and register test MinNaryShared(Gecode::IntPropLevel ipl) : Test("Arithmetic::Min::Nary::Shared::"+str(ipl),3,-4,4,false,ipl) {} /// %Test whether \a x is solution virtual bool solution(const Assignment& x) const { return std::min(std::min(x[0],x[1]), x[2]) == x[1]; } /// Post constraint on \a x virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) { Gecode::IntVarArgs m(3); m[0]=x[0]; m[1]=x[1]; m[2]=x[2]; Gecode::min(home, m, x[1], ipl); } };
/// %Test for n-ary maximum constraint class MaxNary : public Test { public: /// Create and register test MaxNary(Gecode::IntPropLevel ipl) : Test("Arithmetic::Max::Nary::"+str(ipl),4,-4,4,false,ipl) {} /// %Test whether \a x is solution virtual bool solution(const Assignment& x) const { return std::max(std::max(x[0],x[1]), x[2]) == x[3]; } /// Post constraint on \a x virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) { Gecode::IntVarArgs m(3); m[0]=x[0]; m[1]=x[1]; m[2]=x[2]; Gecode::max(home, m, x[3], ipl); } };
/// %Test for n-ary maximum constraint with shared variables class MaxNaryShared : public Test { public: /// Create and register test MaxNaryShared(Gecode::IntPropLevel ipl) : Test("Arithmetic::Max::Nary::Shared::"+str(ipl),3,-4,4,false,ipl) {} /// %Test whether \a x is solution virtual bool solution(const Assignment& x) const { return std::max(std::max(x[0],x[1]), x[2]) == x[1]; } /// Post constraint on \a x virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) { Gecode::IntVarArgs m(3); m[0]=x[0]; m[1]=x[1]; m[2]=x[2]; Gecode::max(home, m, x[1], ipl); } };
/// %Test for argument maximum constraint class ArgMax : public Test { protected: /// Offset to be used int offset; /// Whether to use tie-breaking bool tiebreak; public: /// Create and register test ArgMax(int n, int o, bool tb) : Test("Arithmetic::ArgMax::"+str(o)+"::"+str(tb)+"::"+str(n), n+1,0,n+1, false,tb ? Gecode::IPL_DEF : Gecode::IPL_DOM), offset(o), tiebreak(tb) {} /// %Test whether \a x is solution virtual bool solution(const Assignment& x) const { int n=x.size()-1; if ((x[n] < offset) || (x[n] >= n + offset)) return false; int m=x[0]; int p=0; for (int i=1; i<n; i++) if (x[i] > m) { p=i; m=x[i]; } return tiebreak ? (p + offset == x[n]) : (m == x[x[n]-offset]); } /// Post constraint on \a x virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) { int n=x.size()-1; Gecode::IntVarArgs m(n); for (int i=0; i<n; i++) m[i]=x[i]; Gecode::argmax(home, m, offset, x[n], tiebreak); } };
/// %Test for argument maximum constraint with shared variables class ArgMaxShared : public Test { protected: /// Whether to use tie-breaking bool tiebreak; public: /// Create and register test ArgMaxShared(int n, bool tb) : Test("Arithmetic::ArgMax::Shared::"+str(tb)+"::"+str(n),n+1,0,n+1, false), tiebreak(tb) { testfix=false; } /// %Test whether \a x is solution virtual bool solution(const Assignment& x) const { int n=x.size()-1; if ((x[n] < 0) || (x[n] >= 2*n)) return false; Gecode::IntArgs y(2*n); for (int i=0; i<n; i++) y[2*i+0]=y[2*i+1]=x[i]; int m=y[0]; int p=0; for (int i=1; i<2*n; i++) if (y[i] > m) { p=i; m=y[i]; } return tiebreak ? (p == x[n]) : (m == y[x[n]]); } /// Post constraint on \a x virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) { int n=x.size()-1; Gecode::IntVarArgs m(2*n); for (int i=0; i<n; i++) m[2*i+0]=m[2*i+1]=x[i]; Gecode::argmax(home, m, x[n], tiebreak); } };
/// %Test for argument minimum constraint class ArgMin : public Test { protected: /// Which offset to use int offset; /// Whether to use tie-breaking bool tiebreak; public: /// Create and register test ArgMin(int n, int o, bool tb) : Test("Arithmetic::ArgMin::"+str(o)+"::"+str(tb)+"::"+str(n), n+1,0,n+1, false,tb ? Gecode::IPL_DEF : Gecode::IPL_DOM), offset(o), tiebreak(tb) {} /// %Test whether \a x is solution virtual bool solution(const Assignment& x) const { int n=x.size()-1; if ((x[n] < offset) || (x[n] >= n + offset)) return false; int m=x[0]; int p=0; for (int i=1; i<n; i++) if (x[i] < m) { p=i; m=x[i]; } return tiebreak ? (p+offset == x[n]) : (m == x[x[n]-offset]); } /// Post constraint on \a x virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) { int n=x.size()-1; Gecode::IntVarArgs m(n); for (int i=0; i<n; i++) m[i]=x[i]; Gecode::argmin(home, m, offset, x[n], tiebreak); } };
/// %Test for argument minimum constraint with shared variables class ArgMinShared : public Test { protected: /// Whether to use tie-breaking bool tiebreak; public: /// Create and register test ArgMinShared(int n, bool tb) : Test("Arithmetic::ArgMin::Shared::"+str(tb)+"::"+str(n),n+1,0,n+1, false), tiebreak(tb) { testfix=false; } /// %Test whether \a x is solution virtual bool solution(const Assignment& x) const { int n=x.size()-1; if ((x[n] < 0) || (x[n] >= 2*n)) return false; Gecode::IntArgs y(2*n); for (int i=0; i<n; i++) y[2*i+0]=y[2*i+1]=x[i]; int m=y[0]; int p=0; for (int i=1; i<2*n; i++) if (y[i] < m) { p=i; m=y[i]; } return tiebreak ? (p == x[n]) : (m == y[x[n]]); } /// Post constraint on \a x virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) { int n=x.size()-1; Gecode::IntVarArgs m(2*n); for (int i=0; i<n; i++) m[2*i+0]=m[2*i+1]=x[i]; Gecode::argmin(home, m, x[n], tiebreak); } };
/// %Test for Boolean argument maximum constraint class ArgMaxBool : public Test { protected: /// Offset to be used int offset; /// Whether to use tie-breaking bool tiebreak; public: /// Create and register test ArgMaxBool(int n, int o, bool tb) : Test("Arithmetic::ArgMaxBool::"+str(o)+"::"+str(tb)+"::"+str(n), n+1,0,n+1, false,tb ? Gecode::IPL_DEF : Gecode::IPL_DOM), offset(o), tiebreak(tb) {} /// %Test whether \a x is solution virtual bool solution(const Assignment& x) const { int n=x.size()-1; if ((x[n] < offset) || (x[n] >= n + offset)) return false; int m=x[0]; int p=0; if (x[0] > 1) return false; for (int i=1; i<n; i++) { if (x[i] > 1) return false; if (x[i] > m) { p=i; m=x[i]; } } return tiebreak ? (p + offset == x[n]) : (m == x[x[n]-offset]); } /// Post constraint on \a x virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) { int n=x.size()-1; Gecode::BoolVarArgs m(n); for (int i=0; i<n; i++) m[i]=channel(home,x[i]); Gecode::argmax(home, m, offset, x[n], tiebreak); } };
/// %Test for argument maximum constraint with shared variables class ArgMaxBoolShared : public Test { protected: /// Whether to use tie-breaking bool tiebreak; public: /// Create and register test ArgMaxBoolShared(int n, bool tb) : Test("Arithmetic::ArgMaxBool::Shared::"+str(tb)+"::"+str(n),n+1,0,n+1, false), tiebreak(tb) { testfix=false; } /// %Test whether \a x is solution virtual bool solution(const Assignment& x) const { int n=x.size()-1; if ((x[n] < 0) || (x[n] >= 2*n)) return false; Gecode::IntArgs y(2*n); for (int i=0; i<n; i++) y[2*i+0]=y[2*i+1]=x[i]; int m=y[0]; int p=0; if (y[0] > 1) return false; for (int i=1; i<2*n; i++) { if (y[i] > 1) return false; if (y[i] > m) { p=i; m=y[i]; } } return tiebreak ? (p == x[n]) : (m == y[x[n]]); } /// Post constraint on \a x virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) { int n=x.size()-1; Gecode::BoolVarArgs m(2*n); for (int i=0; i<n; i++) m[2*i+0]=m[2*i+1]=channel(home,x[i]); Gecode::argmax(home, m, x[n], tiebreak); } };
/// %Test for argument minimum constraint class ArgMinBool : public Test { protected: /// Which offset to use int offset; /// Whether to use tie-breaking bool tiebreak; public: /// Create and register test ArgMinBool(int n, int o, bool tb) : Test("Arithmetic::ArgMinBool::"+str(o)+"::"+str(tb)+"::"+str(n), n+1,0,n+1, false,tb ? Gecode::IPL_DEF : Gecode::IPL_DOM), offset(o), tiebreak(tb) {} /// %Test whether \a x is solution virtual bool solution(const Assignment& x) const { int n=x.size()-1; if ((x[n] < offset) || (x[n] >= n + offset)) return false; int m=x[0]; int p=0; if (x[0] < 0 || x[0] > 1) return false; for (int i=1; i<n; i++) { if (x[i] < 0 || x[i] > 1) return false; if (x[i] < m) { p=i; m=x[i]; } } return tiebreak ? (p+offset == x[n]) : (m == x[x[n]-offset]); } /// Post constraint on \a x virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) { int n=x.size()-1; Gecode::BoolVarArgs m(n); for (int i=0; i<n; i++) m[i]=channel(home,x[i]); Gecode::argmin(home, m, offset, x[n], tiebreak); } };
/// %Test for argument minimum constraint with shared variables class ArgMinBoolShared : public Test { protected: /// Whether to use tie-breaking bool tiebreak; public: /// Create and register test ArgMinBoolShared(int n, bool tb) : Test("Arithmetic::ArgMinBool::Shared::"+str(tb)+"::"+str(n),n+1,0,n+1, false), tiebreak(tb) { testfix=false; } /// %Test whether \a x is solution virtual bool solution(const Assignment& x) const { int n=x.size()-1; if ((x[n] < 0) || (x[n] >= 2*n)) return false; Gecode::IntArgs y(2*n); for (int i=0; i<n; i++) y[2*i+0]=y[2*i+1]=x[i]; int m=y[0]; int p=0; if (y[0] > 1) return false; for (int i=1; i<2*n; i++) { if (y[i] > 1) return false; if (y[i] < m) { p=i; m=y[i]; } } return tiebreak ? (p == x[n]) : (m == y[x[n]]); } /// Post constraint on \a x virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) { int n=x.size()-1; Gecode::BoolVarArgs m(2*n); for (int i=0; i<n; i++) m[2*i+0]=m[2*i+1]=channel(home,x[i]); Gecode::argmin(home, m, x[n], tiebreak); } };
/// Help class to create and register tests class Create { public: /// Perform creation and registration Create(void) {
const int va[7] = { Gecode::Int::Limits::min, Gecode::Int::Limits::min+1, -1,0,1, Gecode::Int::Limits::max-1, Gecode::Int::Limits::max }; const int vb[9] = { static_cast<int>(-sqrt(static_cast<double> (-Gecode::Int::Limits::min))), -4,-2,-1,0,1,2,4, static_cast<int>(sqrt(static_cast<double> (Gecode::Int::Limits::max))) };
Gecode::IntSet a(va,7); Gecode::IntSet b(vb,9); Gecode::IntSet c(-8,8); Gecode::IntSet d(-70,70);
(void) new DivMod("A",a); (void) new DivMod("B",b); (void) new DivMod("C",c);
(void) new Div("A",a); (void) new Div("B",b); (void) new Div("C",c);
(void) new Mod("A",a); (void) new Mod("B",b); (void) new Mod("C",c);
for (IntPropLevels ipls; ipls(); ++ipls) { (void) new AbsXY("A",a,ipls.ipl()); (void) new AbsXY("B",b,ipls.ipl()); (void) new AbsXY("C",c,ipls.ipl());
(void) new AbsXX("A",a,ipls.ipl()); (void) new AbsXX("B",b,ipls.ipl()); (void) new AbsXX("C",c,ipls.ipl()); if (ipls.ipl() != Gecode::IPL_VAL) { (void) new MultXYZ("A",a,ipls.ipl()); (void) new MultXYZ("B",b,ipls.ipl()); (void) new MultXYZ("C",c,ipls.ipl());
(void) new MultXXY("A",a,ipls.ipl()); (void) new MultXXY("B",b,ipls.ipl()); (void) new MultXXY("C",c,ipls.ipl());
(void) new MultXYX("A",a,ipls.ipl()); (void) new MultXYX("B",b,ipls.ipl()); (void) new MultXYX("C",c,ipls.ipl());
(void) new MultXYY("A",a,ipls.ipl()); (void) new MultXYY("B",b,ipls.ipl()); (void) new MultXYY("C",c,ipls.ipl());
(void) new MultXXX("A",a,ipls.ipl()); (void) new MultXXX("B",b,ipls.ipl()); (void) new MultXXX("C",c,ipls.ipl());
(void) new SqrXY("A",a,ipls.ipl()); (void) new SqrXY("B",b,ipls.ipl()); (void) new SqrXY("C",c,ipls.ipl());
(void) new SqrXX("A",a,ipls.ipl()); (void) new SqrXX("B",b,ipls.ipl()); (void) new SqrXX("C",c,ipls.ipl());
for (int n=0; n<=6; n++) { (void) new PowXY("A",n,a,ipls.ipl()); (void) new PowXY("B",n,b,ipls.ipl()); (void) new PowXY("C",n,c,ipls.ipl()); (void) new PowXY("D",n,d,ipls.ipl());
(void) new PowXX("A",n,a,ipls.ipl()); (void) new PowXX("B",n,b,ipls.ipl()); (void) new PowXX("C",n,c,ipls.ipl()); (void) new PowXX("D",n,d,ipls.ipl()); }
for (int n=1; n<=6; n++) { (void) new NrootXY("A",n,a,ipls.ipl()); (void) new NrootXY("B",n,b,ipls.ipl()); (void) new NrootXY("C",n,c,ipls.ipl()); (void) new NrootXY("D",n,d,ipls.ipl());
(void) new NrootXX("A",n,a,ipls.ipl()); (void) new NrootXX("B",n,b,ipls.ipl()); (void) new NrootXX("C",n,c,ipls.ipl()); (void) new NrootXX("D",n,d,ipls.ipl()); }
for (int n=30; n<=34; n++) { (void) new PowXY("C",n,c,ipls.ipl()); (void) new PowXX("C",n,c,ipls.ipl()); (void) new NrootXY("C",n,c,ipls.ipl()); (void) new NrootXX("C",n,c,ipls.ipl()); }
(void) new SqrtXY("A",a,ipls.ipl()); (void) new SqrtXY("B",b,ipls.ipl()); (void) new SqrtXY("C",c,ipls.ipl());
(void) new SqrtXX("A",a,ipls.ipl()); (void) new SqrtXX("B",b,ipls.ipl()); (void) new SqrtXX("C",c,ipls.ipl());
(void) new MinXYZ("A",a,ipls.ipl()); (void) new MinXYZ("B",b,ipls.ipl()); (void) new MinXYZ("C",c,ipls.ipl());
(void) new MinXXY("A",a,ipls.ipl()); (void) new MinXXY("B",b,ipls.ipl()); (void) new MinXXY("C",c,ipls.ipl());
(void) new MinXYX("A",a,ipls.ipl()); (void) new MinXYX("B",b,ipls.ipl()); (void) new MinXYX("C",c,ipls.ipl());
(void) new MinXYY("A",a,ipls.ipl()); (void) new MinXYY("B",b,ipls.ipl()); (void) new MinXYY("C",c,ipls.ipl());
(void) new MinXXX("A",a,ipls.ipl()); (void) new MinXXX("B",b,ipls.ipl()); (void) new MinXXX("C",c,ipls.ipl());
(void) new MaxXYZ("A",a,ipls.ipl()); (void) new MaxXYZ("B",b,ipls.ipl()); (void) new MaxXYZ("C",c,ipls.ipl());
(void) new MaxXXY("A",a,ipls.ipl()); (void) new MaxXXY("B",b,ipls.ipl()); (void) new MaxXXY("C",c,ipls.ipl());
(void) new MaxXYX("A",a,ipls.ipl()); (void) new MaxXYX("B",b,ipls.ipl()); (void) new MaxXYX("C",c,ipls.ipl());
(void) new MaxXYY("A",a,ipls.ipl()); (void) new MaxXYY("B",b,ipls.ipl()); (void) new MaxXYY("C",c,ipls.ipl());
(void) new MaxXXX("A",a,ipls.ipl()); (void) new MaxXXX("B",b,ipls.ipl()); (void) new MaxXXX("C",c,ipls.ipl());
(void) new MinNary(ipls.ipl()); (void) new MinNaryShared(ipls.ipl()); (void) new MaxNary(ipls.ipl()); (void) new MaxNaryShared(ipls.ipl()); } }
for (int i=1; i<5; i++) { (void) new ArgMax(i,0,true); (void) new ArgMax(i,1,true); (void) new ArgMaxShared(i,true); (void) new ArgMin(i,0,true); (void) new ArgMin(i,1,true); (void) new ArgMinShared(i,true); (void) new ArgMax(i,0,false); (void) new ArgMax(i,1,false); (void) new ArgMaxShared(i,false); (void) new ArgMin(i,0,false); (void) new ArgMin(i,1,false); (void) new ArgMinShared(i,false);
(void) new ArgMaxBool(i,0,true); (void) new ArgMaxBool(i,1,true); (void) new ArgMaxBoolShared(i,true); (void) new ArgMinBool(i,0,true); (void) new ArgMinBool(i,1,true); (void) new ArgMinBoolShared(i,true); (void) new ArgMaxBool(i,0,false); (void) new ArgMaxBool(i,1,false); (void) new ArgMaxBoolShared(i,false); (void) new ArgMinBool(i,0,false); (void) new ArgMinBool(i,1,false); (void) new ArgMinBoolShared(i,false); } } };
Create c; //@}
}}}
// STATISTICS: test-int