order.cpp
Go to the documentation of this file.
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
* Main authors:
* Christian Schulte <schulte@gecode.org>
*
* Copyright:
* Christian Schulte, 2019
*
* 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 <gecode/minimodel.hh>
#include "test/int.hh"
namespace Test { namespace Int {
namespace Order {
class Int : public Test {
protected:
int p0, p1;
public:
Int(int _p0, int _p1)
: Test("Order::"+str(_p0)+"::"+str(_p1),3,0,6),
p0(_p0), p1(_p1) {}
virtual bool solution(const Assignment& x) const {
int s0 = x[0], s1 = x[1], b = x[2];
if (b > 1)
return false;
return ((s0+p0<=s1) && (b == 0)) || ((s1+p1<=s0) && (b == 1));
}
virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
using namespace Gecode;
order(home, x[0], p0, x[1], p1, channel(home, x[2]));
}
};
class Create {
public:
Create(void) {
for (int i=1; i<=4; i++)
for (int j=1; j<=4; j++)
(void) new Int(i,j);
}
};
Create c;
}
}}
// STATISTICS: test-int
Gecode::IntVarArray
Integer variable array.
Definition int.hh:763
Gecode::Space
Computation spaces.
Definition core.hpp:1742
Test::Int::Assignment
Base class for assignments
Definition int.hh:59
Test::Int::Order::Create
Help class to create and register tests.
Definition order.cpp:71
Test::Int::Order::Create::Create
Create(void)
Perform creation and registration.
Definition order.cpp:74
Test::Int::Order::Int
Test order for integer variables
Definition order.cpp:48
Test::Int::Order::Int::p0
int p0
Processing times.
Definition order.cpp:51
Test::Int::Order::Int::solution
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition order.cpp:58
Test::Int::Order::Int::Int
Int(int _p0, int _p1)
Create and register test.
Definition order.cpp:54
Test::Int::Order::Int::post
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition order.cpp:65
Test::Int::Order::Int::p1
int p1
Definition order.cpp:51
Test::Int::Test::str
static std::string str(Gecode::IntPropLevel ipl)
Map integer propagation level to string.
Definition int.hpp:209
minimodel.hh
Gecode
Gecode toplevel namespace
Gecode::channel
void channel(Home home, FloatVar x0, IntVar x1)
Post propagator for channeling a float and an integer variable .
Definition channel.cpp:41
Gecode::order
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
Test::Int::Order
Tests for order constraint
Definition order.cpp:40
Test::Int::Order::c
Create c
Definition order.cpp:81
Test::Int
Testing finite domain integers.
Definition int.cpp:40
Test
General test support.
Definition afc.cpp:39
int.hh