this repo has no description
at develop 2.8 kB view raw
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ 2/* 3 * Main authors: 4 * Christian Schulte <schulte@gecode.org> 5 * 6 * Copyright: 7 * Christian Schulte, 2019 8 * 9 * This file is part of Gecode, the generic constraint 10 * development environment: 11 * http://www.gecode.org 12 * 13 * Permission is hereby granted, free of charge, to any person obtaining 14 * a copy of this software and associated documentation files (the 15 * "Software"), to deal in the Software without restriction, including 16 * without limitation the rights to use, copy, modify, merge, publish, 17 * distribute, sublicense, and/or sell copies of the Software, and to 18 * permit persons to whom the Software is furnished to do so, subject to 19 * the following conditions: 20 * 21 * The above copyright notice and this permission notice shall be 22 * included in all copies or substantial portions of the Software. 23 * 24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 28 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 29 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 30 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 31 * 32 */ 33 34#include <gecode/minimodel.hh> 35#include "test/int.hh" 36 37namespace Test { namespace Int { 38 39 /// %Tests for order constraint 40 namespace Order { 41 42 /** 43 * \defgroup TaskTestIntOrder Order constraint 44 * \ingroup TaskTestInt 45 */ 46 //@{ 47 /// %Test order for integer variables 48 class Int : public Test { 49 protected: 50 /// Processing times 51 int p0, p1; 52 public: 53 /// Create and register test 54 Int(int _p0, int _p1) 55 : Test("Order::"+str(_p0)+"::"+str(_p1),3,0,6), 56 p0(_p0), p1(_p1) {} 57 /// %Test whether \a x is solution 58 virtual bool solution(const Assignment& x) const { 59 int s0 = x[0], s1 = x[1], b = x[2]; 60 if (b > 1) 61 return false; 62 return ((s0+p0<=s1) && (b == 0)) || ((s1+p1<=s0) && (b == 1)); 63 } 64 /// Post constraint on \a x 65 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) { 66 using namespace Gecode; 67 order(home, x[0], p0, x[1], p1, channel(home, x[2])); 68 } 69 }; 70 /// Help class to create and register tests 71 class Create { 72 public: 73 /// Perform creation and registration 74 Create(void) { 75 for (int i=1; i<=4; i++) 76 for (int j=1; j<=4; j++) 77 (void) new Int(i,j); 78 } 79 }; 80 81 Create c; 82 //@} 83 84 } 85}} 86 87// STATISTICS: test-int 88