idx-view.hpp
Go to the documentation of this file.
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
* Main authors:
* Christian Schulte <schulte@gecode.org>
*
* Contributing authors:
* Guido Tack <tack@gecode.org>
*
* Copyright:
* Christian Schulte, 2004
* Guido Tack, 2004
*
* 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.
*
*/
namespace Gecode { namespace Int {
template<>
class ViewToVarArg<IntView> {
public:
typedef IntVarArgs argtype;
};
template<>
class ViewToVarArg<MinusView> {
public:
typedef IntVarArgs argtype;
};
template<>
class ViewToVarArg<BoolView> {
public:
typedef BoolVarArgs argtype;
};
template<>
class ViewToVarArg<NegBoolView> {
public:
typedef BoolVarArgs argtype;
};
template<class View>
forceinline IdxView<View>*
IdxView<View>::allocate(Space& home, int n) {
return home.alloc<IdxView<View> >(n);
}
template<class View>
forceinline
IdxViewArray<View>::IdxViewArray(void) : xs(NULL), n(0) {}
template<class View>
forceinline
IdxViewArray<View>::IdxViewArray(const IdxViewArray<View>& a) {
n = a.n; xs = a.xs;
}
template<class View>
forceinline
IdxViewArray<View>::IdxViewArray(Space& home,
const typename ViewToVarArg<View>::argtype& xa) : xs(NULL) {
n = xa.size();
if (n>0) {
xs = IdxView<View>::allocate(home, n);
for (int i=0; i<n; i++) {
xs[i].idx = i; xs[i].view = xa[i];
}
}
}
template<class View>
forceinline
IdxViewArray<View>::IdxViewArray(Space& home, int n0) : xs(NULL) {
n = n0;
if (n>0) {
xs = IdxView<View>::allocate(home, n);
}
}
template<class View>
forceinline int
IdxViewArray<View>::size(void) const {
return n;
}
template<class View>
forceinline void
IdxViewArray<View>::size(int n0) {
n = n0;
}
template<class View>
forceinline IdxView<View>&
IdxViewArray<View>::operator [](int i) {
assert((i >= 0) && (i < size()));
return xs[i];
}
template<class View>
forceinline const IdxView<View>&
IdxViewArray<View>::operator [](int i) const {
assert((i >= 0) && (i < size()));
return xs[i];
}
template<class View>
forceinline void
IdxViewArray<View>::subscribe(Space& home, Propagator& p, PropCond pc,
bool process) {
for (int i=0; i<n; i++)
xs[i].view.subscribe(home,p,pc,process);
}
template<class View>
forceinline void
IdxViewArray<View>::cancel(Space& home, Propagator& p, PropCond pc) {
for (int i=0; i<n; i++)
xs[i].view.cancel(home,p,pc);
}
template<class View>
forceinline void
IdxViewArray<View>::reschedule(Space& home, Propagator& p, PropCond pc) {
for (int i=0; i<n; i++)
xs[i].view.reschedule(home,p,pc);
}
template<class View>
forceinline void
IdxViewArray<View>::update(Space& home, IdxViewArray<View>& a) {
n = a.size();
if (n>0) {
xs = IdxView<View>::allocate(home,n);
for (int i=0; i<n; i++) {
xs[i].idx = a[i].idx;
xs[i].view.update(home,a[i].view);
}
}
}
template<class Char, class Traits, class View>
std::basic_ostream<Char,Traits>&
operator <<(std::basic_ostream<Char,Traits>& os,
const IdxViewArray<View>& x) {
std::basic_ostringstream<Char,Traits> s;
s.copyfmt(os); s.width(0);
s << '{';
if (x.size() > 0) {
s << x[0].idx << ':' << x[0].view;
for (int i=1; i<x.size(); i++)
s << ", " << x[i].idx << ':' << x[i].view;
}
s << '}';
return os << s.str();
}
}}
// STATISTICS: int-prop
Gecode::BoolVarArgs
Passing Boolean variables.
Definition int.hh:712
Gecode::FloatVal::size
FloatNum size(void) const
Return size of float value (distance between maximum and minimum).
Definition val.hpp:78
Gecode::IntVarArgs
Passing integer variables.
Definition int.hh:656
Gecode::Int::BoolView
Boolean view for Boolean variables.
Definition view.hpp:1380
Gecode::Int::IdxViewArray
An array of IdxView pairs.
Definition idx-view.hh:67
Gecode::Int::IdxViewArray::operator[]
IdxView< View > & operator[](int n)
Access element n.
Definition idx-view.hpp:117
Gecode::Int::IdxViewArray::subscribe
void subscribe(Space &home, Propagator &p, PropCond pc, bool process=true)
Definition idx-view.hpp:131
Gecode::Int::IdxViewArray::reschedule
void reschedule(Space &home, Propagator &p, PropCond pc)
Schedule propagator p.
Definition idx-view.hpp:146
Gecode::Int::IdxViewArray::IdxViewArray
IdxViewArray(void)
Default constructor.
Definition idx-view.hpp:73
Gecode::Int::IdxViewArray::update
void update(Space &home, IdxViewArray< View > &x)
Cloning.
Definition idx-view.hpp:153
Gecode::Int::IdxViewArray::cancel
void cancel(Space &home, Propagator &p, PropCond pc)
Definition idx-view.hpp:139
Gecode::Int::IdxViewArray::size
int size(void) const
Return the current size.
Definition idx-view.hpp:105
Gecode::Int::IdxView
Class for pair of index and view.
Definition idx-view.hh:48
Gecode::Int::IdxView::allocate
static IdxView * allocate(Space &home, int n)
Allocate memory for n index-view pairs.
Definition idx-view.hpp:67
Gecode::Int::IntView
Integer view for integer variables.
Definition view.hpp:129
Gecode::Int::MinusView
Minus integer view.
Definition view.hpp:282
Gecode::Int::NegBoolView
Negated Boolean view.
Definition view.hpp:1574
Gecode::Int::ViewToVarArg< BoolView >::argtype
BoolVarArgs argtype
Definition idx-view.hpp:56
Gecode::Int::ViewToVarArg< IntView >::argtype
IntVarArgs argtype
Definition idx-view.hpp:44
Gecode::Int::ViewToVarArg< MinusView >::argtype
IntVarArgs argtype
Definition idx-view.hpp:50
Gecode::Int::ViewToVarArg< NegBoolView >::argtype
BoolVarArgs argtype
Definition idx-view.hpp:62
Gecode::Int::ViewToVarArg
Class to map VarArg type to view.
Definition idx-view.hh:60
Gecode::Propagator
Base-class for propagators.
Definition core.hpp:1064
Gecode::Space
Computation spaces.
Definition core.hpp:1742
Gecode::Space::alloc
T * alloc(long unsigned int n)
Allocate block of n objects of type T from space heap.
Definition core.hpp:2837
Gecode::Int
Finite domain integers.
Gecode::Int::operator<<
std::basic_ostream< Char, Traits > & operator<<(std::basic_ostream< Char, Traits > &os, const IdxViewArray< View > &x)
Definition idx-view.hpp:167
Gecode
Gecode toplevel namespace
Gecode::PropCond
int PropCond
Type for propagation conditions.
Definition core.hpp:72
forceinline
#define forceinline
Definition config.hpp:187