linear-int.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, 2002
*
* 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/int/linear.hh>
namespace Gecode {
using namespace Int;
void
linear(Home home,
const IntVarArgs& x, IntRelType irt, int c,
IntPropLevel ipl) {
GECODE_POST;
Region re;
Linear::Term<IntView>* t = re.alloc<Linear::Term<IntView>>(x.size());
for (int i=0; i<x.size(); i++) {
t[i].a=1; t[i].x=x[i];
}
Linear::post(home,t,x.size(),irt,c,ipl);
}
void
linear(Home home,
const IntVarArgs& x, IntRelType irt, int c, Reify r,
IntPropLevel) {
GECODE_POST;
Region re;
Linear::Term<IntView>* t = re.alloc<Linear::Term<IntView>>(x.size());
for (int i=0; i<x.size(); i++) {
t[i].a=1; t[i].x=x[i];
}
Linear::post(home,t,x.size(),irt,c,r);
}
void
linear(Home home,
const IntArgs& a, const IntVarArgs& x, IntRelType irt, int c,
IntPropLevel ipl) {
if (a.size() != x.size())
throw ArgumentSizeMismatch("Int::linear");
GECODE_POST;
Region re;
Linear::Term<IntView>* t = re.alloc<Linear::Term<IntView>>(x.size());
for (int i=0; i<x.size(); i++) {
t[i].a=a[i]; t[i].x=x[i];
}
Linear::post(home,t,x.size(),irt,c,ipl);
}
void
linear(Home home,
const IntArgs& a, const IntVarArgs& x, IntRelType irt, int c,
Reify r, IntPropLevel) {
if (a.size() != x.size())
throw ArgumentSizeMismatch("Int::linear");
GECODE_POST;
Region re;
Linear::Term<IntView>* t = re.alloc<Linear::Term<IntView>>(x.size());
for (int i=0; i<x.size(); i++) {
t[i].a=a[i]; t[i].x=x[i];
}
Linear::post(home,t,x.size(),irt,c,r);
}
void
linear(Home home,
const IntVarArgs& x, IntRelType irt, IntVar y,
IntPropLevel ipl) {
GECODE_POST;
Region re;
Linear::Term<IntView>* t = re.alloc<Linear::Term<IntView>>(x.size()+1);
for (int i=0; i<x.size(); i++) {
t[i].a=1; t[i].x=x[i];
}
int min, max;
estimate(t,x.size(),0,min,max);
IntView v(y);
switch (irt) {
case IRT_EQ:
GECODE_ME_FAIL(v.gq(home,min)); GECODE_ME_FAIL(v.lq(home,max));
break;
case IRT_GQ:
GECODE_ME_FAIL(v.lq(home,max));
break;
case IRT_LQ:
GECODE_ME_FAIL(v.gq(home,min));
break;
default: ;
}
if (home.failed()) return;
t[x.size()].a=-1; t[x.size()].x=y;
Linear::post(home,t,x.size()+1,irt,0,ipl);
}
void
linear(Home home,
const IntVarArgs& x, IntRelType irt, IntVar y, Reify r,
IntPropLevel) {
GECODE_POST;
Region re;
Linear::Term<IntView>* t = re.alloc<Linear::Term<IntView>>(x.size()+1);
for (int i=0; i<x.size(); i++) {
t[i].a=1; t[i].x=x[i];
}
t[x.size()].a=-1; t[x.size()].x=y;
Linear::post(home,t,x.size()+1,irt,0,r);
}
void
linear(Home home,
const IntArgs& a, const IntVarArgs& x, IntRelType irt, IntVar y,
IntPropLevel ipl) {
if (a.size() != x.size())
throw ArgumentSizeMismatch("Int::linear");
GECODE_POST;
Region re;
Linear::Term<IntView>* t = re.alloc<Linear::Term<IntView>>(x.size()+1);
for (int i=0; i<x.size(); i++) {
t[i].a=a[i]; t[i].x=x[i];
}
int min, max;
estimate(t,x.size(),0,min,max);
IntView v(y);
switch (irt) {
case IRT_EQ:
GECODE_ME_FAIL(v.gq(home,min)); GECODE_ME_FAIL(v.lq(home,max));
break;
case IRT_GQ:
GECODE_ME_FAIL(v.lq(home,max));
break;
case IRT_LQ:
GECODE_ME_FAIL(v.gq(home,min));
break;
default: ;
}
if (home.failed()) return;
t[x.size()].a=-1; t[x.size()].x=y;
Linear::post(home,t,x.size()+1,irt,0,ipl);
}
void
linear(Home home,
const IntArgs& a, const IntVarArgs& x, IntRelType irt, IntVar y,
Reify r, IntPropLevel) {
if (a.size() != x.size())
throw ArgumentSizeMismatch("Int::linear");
GECODE_POST;
Region re;
Linear::Term<IntView>* t = re.alloc<Linear::Term<IntView>>(x.size()+1);
for (int i=0; i<x.size(); i++) {
t[i].a=a[i]; t[i].x=x[i];
}
t[x.size()].a=-1; t[x.size()].x=y;
Linear::post(home,t,x.size()+1,irt,0,r);
}
}
// STATISTICS: int-post
Gecode::ArgArrayBase::size
int size(void) const
Return size of array (number of elements).
Definition array.hpp:1607
Gecode::FloatVal::size
FloatNum size(void) const
Return size of float value (distance between maximum and minimum).
Definition val.hpp:78
Gecode::Home
Home class for posting propagators
Definition core.hpp:856
Gecode::Home::failed
bool failed(void) const
Check whether corresponding space is failed.
Definition core.hpp:4048
Gecode::IntArgs
Passing integer arguments.
Definition int.hh:628
Gecode::IntVarArgs
Passing integer variables.
Definition int.hh:656
Gecode::IntVar
Integer variables.
Definition int.hh:371
Gecode::Int::ArgumentSizeMismatch
Exception: Arguments are of different size
Definition exception.hpp:73
Gecode::Int::IntView
Integer view for integer variables.
Definition view.hpp:129
Gecode::Int::Linear::Term
Class for describing linear term .
Definition linear.hh:1336
Gecode::Int::Linear::Term::x
View x
View.
Definition linear.hh:1341
Gecode::Int::Linear::Term::a
int a
Coefficient.
Definition linear.hh:1339
Gecode::Region
Handle to region.
Definition region.hpp:55
Gecode::Region::alloc
T * alloc(long unsigned int n)
Allocate block of n objects of type T from region.
Definition region.hpp:386
Gecode::Reify
Reification specification.
Definition int.hh:876
Gecode::Int::Linear::post
void post(Home home, Term< IntView > *t, int n, IntRelType irt, int c, IntPropLevel=IPL_DEF)
Post propagator for linear constraint over integers.
Definition int-post.cpp:219
GECODE_POST
#define GECODE_POST
Check for failure in a constraint post function.
Definition macros.hpp:40
GECODE_ME_FAIL
#define GECODE_ME_FAIL(me)
Check whether modification event me is failed, and fail space home.
Definition macros.hpp:77
Gecode::linear
void linear(Home home, const FloatVarArgs &x, FloatRelType frt, FloatVal c)
Post propagator for .
Definition linear.cpp:41
Gecode::IntRelType
IntRelType
Relation types for integers.
Definition int.hh:925
Gecode::IntPropLevel
IntPropLevel
Propagation levels for integer propagators.
Definition int.hh:974
Gecode::IRT_EQ
@ IRT_EQ
Equality ( ).
Definition int.hh:926
Gecode::IRT_GQ
@ IRT_GQ
Greater or equal ( ).
Definition int.hh:930
Gecode::IRT_LQ
@ IRT_LQ
Less or equal ( ).
Definition int.hh:928
linear.hh
Gecode::Int
Finite domain integers.
Gecode
Gecode toplevel namespace
Gecode::min
void min(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition arithmetic.cpp:67
Gecode::max
void max(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition arithmetic.cpp:49