/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ /* * Main authors: * David Rijsman * * Contributing authors: * Christian Schulte * * Copyright: * David Rijsman, 2009 * Christian Schulte, 2009 * * 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 #include namespace Test { namespace Int { /// %Tests for sequence constraints namespace Sequence { /** * \defgroup TaskTestIntSequence Sequence constraints * \ingroup TaskTestInt */ //@{ /// %Base test for sequence class SequenceTest : public Test { protected: Gecode::IntSet s; int q,l,u; public: /// Create and register test SequenceTest(const std::string& s, const Gecode::IntSet& s0, int q0, int l0, int u0, int size, int min, int max) : Test("Sequence::"+s,size,min,max), s(s0), q(q0), l(l0), u(u0) { } /// %Test whether \a x is solutionin virtual bool solution(const Assignment& x) const { for (int i=0; i< (x.size() - q + 1); i++ ) { int total = 0; for (int j=i; j < i + q; j++ ) { if (s.in(x[j])) total++; if (total > u) return false; } if ( total < l ) return false; } return true; } }; /// %Test for sequence with boolean variables class SequenceBoolTest : public SequenceTest { public: /// Create and register test SequenceBoolTest(const std::string& s, const Gecode::IntSet& s0, int q0, int l0, int u0, int size) : SequenceTest("Bool::"+s,s0,q0,l0,u0,size,0,1) { } /// Post constraint on \a x virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) { Gecode::BoolVarArgs c(x.size()); for (int i=0; i