Generated on Thu Jan 16 2025 00:00:00 for Gecode by doxygen 1.14.0
order.cpp
Go to the documentation of this file.
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
40 namespace Order {
41
47
48 class Int : public Test {
49 protected:
51 int p0, p1;
52 public:
54 Int(int _p0, int _p1)
55 : Test("Order::"+str(_p0)+"::"+str(_p1),3,0,6),
56 p0(_p0), p1(_p1) {}
57
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
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
71 class Create {
72 public:
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
83
84 }
85}}
86
87// STATISTICS: test-int
88
Integer variable array.
Definition int.hh:772
Computation spaces.
Definition core.hpp:1744
Base class for assignments
Definition int.hh:59
Help class to create and register tests.
Definition order.cpp:71
Create(void)
Perform creation and registration.
Definition order.cpp:74
Test order for integer variables
Definition order.cpp:48
int p0
Processing times.
Definition order.cpp:51
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition order.cpp:58
Int(int _p0, int _p1)
Create and register test.
Definition order.cpp:54
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition order.cpp:65
static std::string str(Gecode::IntPropLevel ipl)
Map integer propagation level to string.
Definition int.hpp:209
Gecode toplevel namespace
void channel(Home home, FloatVar x0, IntVar x1)
Post propagator for channeling a float and an integer variable .
Definition channel.cpp:41
void order(Home home, IntVar s0, int p0, IntVar s1, int p1, BoolVar b, IntPropLevel ipl=IPL_DEF)
Post propagators for ordering two tasks.
Definition order.cpp:41
Post propagator for SetVar x
Definition set.hh:773
Tests for order constraint
Definition order.cpp:40
Testing finite domain integers.
Definition int.cpp:40
General test support.
Definition afc.cpp:39