array.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>
* Guido Tack <tack@gecode.org>
*
* Contributing authors:
* Gregory Crosswhite <gcross@phys.washington.edu>
*
* Copyright:
* Gregory Crosswhite, 2011
* Christian Schulte, 2003
* 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.
*
*/
#include <iostream>
#include <iterator>
#include <vector>
#include <sstream>
#include <initializer_list>
namespace Gecode { namespace Kernel {
template<class View>
class ViewOcc {
public:
View x;
int i;
bool operator <(const ViewOcc& y) const;
};
template<class View>
forceinline bool
ViewOcc<View>::operator <(const ViewOcc& y) const {
return x < y.x;
}
GECODE_KERNEL_EXPORT
bool duplicates(void** p, int n);
GECODE_KERNEL_EXPORT
bool duplicates(void** p, int n, void** q, int m);
}}
namespace Gecode {
template<class Var> class VarArray;
template<class Var> class VarArgArray;
template<class A>
class ArrayTraits {};
template<class Var>
class VarArray {
protected:
int n;
Var* x;
public:
typedef Var value_type;
typedef Var& reference;
typedef const Var& const_reference;
typedef Var* pointer;
typedef const Var* const_pointer;
typedef Var* iterator;
typedef const Var* const_iterator;
typedef std::reverse_iterator<Var*> reverse_iterator;
typedef std::reverse_iterator<const Var*> const_reverse_iterator;
VarArray(void);
VarArray(Space& home, int m);
VarArray(Space& home, const VarArgArray<Var>&);
VarArray(const VarArray<Var>& a);
const VarArray<Var>& operator =(const VarArray<Var>& a);
int size(void) const;
Var& operator [](int i);
const Var& operator [](int i) const;
typename ArrayTraits<VarArgArray<Var>>::ArgsType
slice(int start, int inc=1, int n=-1);
iterator begin(void);
const_iterator begin(void) const;
iterator end(void);
const_iterator end(void) const;
reverse_iterator rbegin(void);
const_reverse_iterator rbegin(void) const;
reverse_iterator rend(void);
const_reverse_iterator rend(void) const;
bool assigned(void) const;
void update(Space& home, VarArray<Var>& a);
private:
static void* operator new(size_t) throw();
static void operator delete(void*,size_t);
};
template<class T>
typename ArrayTraits<VarArray<T>>::ArgsType
operator +(const VarArray<T>& x, const VarArgArray<T>& y);
template<class T>
typename ArrayTraits<VarArray<T>>::ArgsType
operator +(const VarArray<T>& x, const VarArray<T>& y);
template<class T>
typename ArrayTraits<VarArray<T>>::ArgsType
operator +(const VarArgArray<T>& x, const VarArray<T>& y);
template<class T>
typename ArrayTraits<VarArray<T>>::ArgsType
operator +(const VarArray<T>& x, const T& y);
template<class T>
typename ArrayTraits<VarArray<T>>::ArgsType
operator +(const T& x, const VarArray<T>& y);
template<class View>
class ViewArray {
private:
int n;
View* x;
public:
typedef View value_type;
typedef View& reference;
typedef const View& const_reference;
typedef View* pointer;
typedef const View* const_pointer;
typedef View* iterator;
typedef const View* const_iterator;
typedef std::reverse_iterator<View*> reverse_iterator;
typedef std::reverse_iterator<const View*> const_reverse_iterator;
ViewArray(void);
ViewArray(Space& home, int m);
ViewArray(Region& r, int m);
ViewArray(const ViewArray<View>& a);
ViewArray(Space& home, const ViewArray<View>& a);
ViewArray(Region& r, const ViewArray<View>& a);
const ViewArray<View>& operator =(const ViewArray<View>& a);
template<class Var>
ViewArray(Space& home, const VarArgArray<Var>& a)
: n(a.size()) {
// This may not be in the hpp file (to satisfy the MS compiler)
if (n>0) {
x = home.alloc<View>(n);
for (int i=0; i<n; i++)
x[i]=a[i];
} else {
x = nullptr;
}
}
template<class Var>
ViewArray(Region& r, const VarArgArray<Var>& a)
: n(a.size()) {
// This may not be in the hpp file (to satisfy the MS compiler)
if (n>0) {
x = r.alloc<View>(n);
for (int i=0; i<n; i++)
x[i]=a[i];
} else {
x = nullptr;
}
}
int size(void) const;
void size(int n);
View& operator [](int i);
const View& operator [](int i) const;
iterator begin(void);
const_iterator begin(void) const;
iterator end(void);
const_iterator end(void) const;
reverse_iterator rbegin(void);
const_reverse_iterator rbegin(void) const;
reverse_iterator rend(void);
const_reverse_iterator rend(void) const;
void subscribe(Space& home, Propagator& p, PropCond pc,
bool schedule=true);
void cancel(Space& home, Propagator& p, PropCond pc);
void subscribe(Space& home, Advisor& a);
void cancel(Space& home, Advisor& a);
void reschedule(Space& home, Propagator& p, PropCond pc);
void update(Space& home, ViewArray<View>& a);
void move_fst(int i);
void move_lst(int i);
void move_fst(int i, Space& home, Propagator& p, PropCond pc);
void move_lst(int i, Space& home, Propagator& p, PropCond pc);
void move_fst(int i, Space& home, Advisor& a);
void move_lst(int i, Space& home, Advisor& a);
void drop_fst(int i);
void drop_lst(int i);
void drop_fst(int i, Space& home, Propagator& p, PropCond pc);
void drop_lst(int i, Space& home, Propagator& p, PropCond pc);
void drop_fst(int i, Space& home, Advisor& a);
void drop_lst(int i, Space& home, Advisor& a);
bool assigned(void) const;
bool same(void) const;
bool same(const View& y) const;
void unique(void);
private:
static void* operator new(size_t) throw();
static void operator delete(void*,size_t);
};
template<class ViewX, class ViewY>
bool shared(ViewArray<ViewX> x, ViewArray<ViewY> y);
template<class ViewX, class ViewY>
bool shared(ViewArray<ViewX> x, ViewY y);
template<class ViewX, class ViewY>
bool shared(ViewX x, ViewArray<ViewY> y);
template<class View>
bool shared(ViewArray<View> x);
template<class T>
class ArgArrayBase {
protected:
int n;
int capacity;
T* a;
static const int onstack_size = 16;
T onstack[onstack_size];
T* allocate(int n);
void resize(int i);
template<class A>
A concat(const ArgArrayBase<T>& x) const;
template<class A>
A concat(const T& x) const;
template<class A>
A& append(const T& x);
template<class A>
A& append(const ArgArrayBase<T>& x);
template<class A>
A slice(int start, int inc=1, int n=-1);
public:
typedef T value_type;
typedef T& reference;
typedef const T& const_reference;
typedef T* pointer;
typedef const T* const_pointer;
typedef T* iterator;
typedef const T* const_iterator;
typedef std::reverse_iterator<T*> reverse_iterator;
typedef std::reverse_iterator<const T*> const_reverse_iterator;
ArgArrayBase(void);
explicit ArgArrayBase(int n);
ArgArrayBase(const ArgArrayBase<T>& a);
const ArgArrayBase<T>& operator =(const ArgArrayBase<T>& a);
ArgArrayBase(const std::vector<T>& a);
ArgArrayBase(std::initializer_list<T> a);
template<class InputIterator>
ArgArrayBase(InputIterator first, InputIterator last);
int size(void) const;
T& operator [](int i);
const T& operator [](int i) const;
iterator begin(void);
const_iterator begin(void) const;
iterator end(void);
const_iterator end(void) const;
reverse_iterator rbegin(void);
const_reverse_iterator rbegin(void) const;
reverse_iterator rend(void);
const_reverse_iterator rend(void) const;
~ArgArrayBase(void);
};
template<class> class ArgArray;
template<class T>
typename ArrayTraits<ArgArray<T>>::ArgsType
operator +(const ArgArray<T>& x, const ArgArray<T>& y);
template<class T>
typename ArrayTraits<ArgArray<T>>::ArgsType
operator +(const ArgArray<T>& x, const T& y);
template<class T>
typename ArrayTraits<ArgArray<T>>::ArgsType
operator +(const T& x, const ArgArray<T>& y);
template<class T>
class ArgArray : public ArgArrayBase<T> {
protected:
using ArgArrayBase<T>::a;
public:
using ArgArrayBase<T>::size;
ArgArray(void);
explicit ArgArray(int n);
ArgArray(int n, const T* e);
ArgArray(const ArgArray<T>& a);
ArgArray(const std::vector<T>& a);
ArgArray(std::initializer_list<T> a);
template<class InputIterator>
ArgArray(InputIterator first, InputIterator last);
typename ArrayTraits<ArgArray<T>>::ArgsType
slice(int start, int inc=1, int n=-1);
typename ArrayTraits<ArgArray<T>>::ArgsType&
operator <<(const T& x);
typename ArrayTraits<ArgArray<T>>::ArgsType&
operator <<(const ArgArray<T>& x);
friend typename ArrayTraits<ArgArray<T>>::ArgsType
operator + <>(const ArgArray<T>& x, const ArgArray<T>& y);
friend typename ArrayTraits<ArgArray<T>>::ArgsType
operator + <>(const ArgArray<T>& x, const T& y);
friend
typename ArrayTraits<ArgArray<T>>::ArgsType
operator + <>(const T& x, const ArgArray<T>& y);
};
template<class> class VarArgArray;
template<class Var>
typename ArrayTraits<VarArgArray<Var>>::ArgsType
operator +(const VarArgArray<Var>& x, const VarArgArray<Var>& y);
template<class Var>
typename ArrayTraits<VarArgArray<Var>>::ArgsType
operator +(const VarArgArray<Var>& x, const Var& y);
template<class Var>
typename ArrayTraits<VarArgArray<Var>>::ArgsType
operator +(const Var& x, const VarArgArray<Var>& y);
template<class Var>
class VarArgArray : public ArgArrayBase<Var> {
protected:
using ArgArrayBase<Var>::a;
using ArgArrayBase<Var>::n;
public:
using ArgArrayBase<Var>::size;
VarArgArray(void);
explicit VarArgArray(int n);
VarArgArray(const VarArgArray<Var>& a);
VarArgArray(const VarArray<Var>& a);
VarArgArray(const std::vector<Var>& a);
VarArgArray(std::initializer_list<Var> a);
template<class InputIterator>
VarArgArray(InputIterator first, InputIterator last);
typename ArrayTraits<VarArgArray<Var>>::ArgsType
slice(int start, int inc=1, int n=-1);
typename ArrayTraits<VarArgArray<Var>>::ArgsType&
operator <<(const Var& x);
typename ArrayTraits<VarArgArray<Var>>::ArgsType&
operator <<(const VarArgArray<Var>& x);
bool assigned(void) const;
friend typename ArrayTraits<VarArgArray<Var>>::ArgsType
operator + <>(const VarArgArray<Var>& x, const VarArgArray<Var>& y);
friend typename ArrayTraits<VarArgArray<Var>>::ArgsType
operator + <>(const VarArgArray<Var>& x, const Var& y);
friend
typename ArrayTraits<VarArgArray<Var>>::ArgsType
operator + <>(const Var& x, const VarArgArray<Var>& y);
};
template<class Var>
bool same(VarArgArray<Var> x, VarArgArray<Var> y);
template<class Var>
bool same(VarArgArray<Var> x, Var y);
template<class Var>
bool same(Var x, VarArgArray<Var> y);
template<class Var>
bool same(VarArgArray<Var> x);
template<class Char, class Traits, class Var>
std::basic_ostream<Char,Traits>&
operator <<(std::basic_ostream<Char,Traits>& os,
const VarArray<Var>& x);
template<class Char, class Traits, class View>
std::basic_ostream<Char,Traits>&
operator <<(std::basic_ostream<Char,Traits>& os, const ViewArray<View>& x);
template<class Char, class Traits, class T>
std::basic_ostream<Char,Traits>&
operator <<(std::basic_ostream<Char,Traits>& os, const ArgArrayBase<T>& x);
/*
* Implementation
*
*/
/*
* Variable arrays
*
* These arrays are allocated in the space.
*
*/
template<class Var>
forceinline
VarArray<Var>::VarArray(void) : n(0), x(nullptr) {}
template<class Var>
forceinline
VarArray<Var>::VarArray(Space& home, int n0)
: n(n0) {
// Allocate from space
x = (n>0) ? home.alloc<Var>(n) : nullptr;
}
template<class Var>
forceinline
VarArray<Var>::VarArray(const VarArray<Var>& a) {
n = a.n; x = a.x;
}
template<class Var>
inline const VarArray<Var>&
VarArray<Var>::operator =(const VarArray<Var>& a) {
n = a.n; x = a.x;
return *this;
}
template<class Var>
forceinline int
VarArray<Var>::size(void) const {
return n;
}
template<class Var>
forceinline Var&
VarArray<Var>::operator [](int i) {
assert((i >= 0) && (i < size()));
return x[i];
}
template<class Var>
forceinline const Var&
VarArray<Var>::operator [](int i) const {
assert((i >= 0) && (i < size()));
return x[i];
}
template<class Var>
typename ArrayTraits<VarArgArray<Var>>::ArgsType
VarArray<Var>::slice(int start, int inc, int maxN) {
assert(n==0 || start < n);
if (n==0 || maxN<0)
maxN = n;
int s;
if (inc == 0)
s = n-start;
else if (inc > 0)
s = (n-start)/inc + ((n-start) % inc == 0 ? 0 : 1);
else
s = (start+1)/-inc + ((start+1) % -inc == 0 ? 0 : 1);
typename ArrayTraits<VarArgArray<Var>>::ArgsType r(std::min(maxN,s));
for (int i=0; i<r.size(); i++, start+=inc)
r[i] = x[start];
return r;
}
template<class Var>
forceinline typename VarArray<Var>::iterator
VarArray<Var>::begin(void) {
return x;
}
template<class Var>
forceinline typename VarArray<Var>::const_iterator
VarArray<Var>::begin(void) const {
return x;
}
template<class Var>
forceinline typename VarArray<Var>::iterator
VarArray<Var>::end(void) {
return x+n;
}
template<class Var>
forceinline typename VarArray<Var>::const_iterator
VarArray<Var>::end(void) const {
return x+n;
}
template<class Var>
forceinline typename VarArray<Var>::reverse_iterator
VarArray<Var>::rbegin(void) {
return reverse_iterator(x+n);
}
template<class Var>
forceinline typename VarArray<Var>::const_reverse_iterator
VarArray<Var>::rbegin(void) const {
return const_reverse_iterator(x+n);
}
template<class Var>
forceinline typename VarArray<Var>::reverse_iterator
VarArray<Var>::rend(void) {
return reverse_iterator(x);
}
template<class Var>
forceinline typename VarArray<Var>::const_reverse_iterator
VarArray<Var>::rend(void) const {
return const_reverse_iterator(x);
}
template<class Var>
forceinline void
VarArray<Var>::update(Space& home, VarArray<Var>& a) {
n = a.n;
if (n > 0) {
x = home.alloc<Var>(n);
for (int i=0; i<n; i++)
x[i].update(home, a.x[i]);
} else {
x = nullptr;
}
}
template<class Var>
forceinline bool
VarArray<Var>::assigned(void) const {
for (int i=0; i<n; i++)
if (!x[i].assigned())
return false;
return true;
}
template<class Var>
forceinline void*
VarArray<Var>::operator new(size_t) throw() {
return nullptr;
}
template<class Var>
forceinline void
VarArray<Var>::operator delete(void*,size_t) {
}
template<class Var>
typename ArrayTraits<VarArray<Var>>::ArgsType
operator +(const VarArray<Var>& x, const VarArray<Var>& y) {
typename ArrayTraits<VarArray<Var>>::ArgsType r(x.size()+y.size());
for (int i=0; i<x.size(); i++)
r[i] = x[i];
for (int i=0; i<y.size(); i++)
r[x.size()+i] = y[i];
return r;
}
template<class Var>
typename ArrayTraits<VarArray<Var>>::ArgsType
operator +(const VarArray<Var>& x, const VarArgArray<Var>& y) {
typename ArrayTraits<VarArray<Var>>::ArgsType r(x.size()+y.size());
for (int i=0; i<x.size(); i++)
r[i] = x[i];
for (int i=0; i<y.size(); i++)
r[x.size()+i] = y[i];
return r;
}
template<class Var>
typename ArrayTraits<VarArray<Var>>::ArgsType
operator +(const VarArgArray<Var>& x, const VarArray<Var>& y) {
typename ArrayTraits<VarArray<Var>>::ArgsType r(x.size()+y.size());
for (int i=0; i<x.size(); i++)
r[i] = x[i];
for (int i=0; i<y.size(); i++)
r[x.size()+i] = y[i];
return r;
}
template<class Var>
typename ArrayTraits<VarArray<Var>>::ArgsType
operator +(const VarArray<Var>& x, const Var& y) {
typename ArrayTraits<VarArray<Var>>::ArgsType r(x.size()+1);
for (int i=0; i<x.size(); i++)
r[i] = x[i];
r[x.size()] = y;
return r;
}
template<class Var>
typename ArrayTraits<VarArray<Var>>::ArgsType
operator +(const Var& x, const VarArray<Var>& y) {
typename ArrayTraits<VarArray<Var>>::ArgsType r(y.size()+1);
r[0] = x;
for (int i=0; i<y.size(); i++)
r[1+i] = y[i];
return r;
}
/*
* View arrays
*
*/
template<class View>
forceinline
ViewArray<View>::ViewArray(void) : n(0), x(nullptr) {}
template<class View>
forceinline
ViewArray<View>::ViewArray(Space& home, int n0)
: n(n0) {
x = (n>0) ? home.alloc<View>(n) : nullptr;
}
template<class View>
forceinline
ViewArray<View>::ViewArray(Region& r, int n0)
: n(n0) {
x = (n>0) ? r.alloc<View>(n) : nullptr;
}
template<class View>
ViewArray<View>::ViewArray(Space& home, const ViewArray<View>& a)
: n(a.size()) {
if (n>0) {
x = home.alloc<View>(n);
for (int i=0; i<n; i++)
x[i] = a[i];
} else {
x = nullptr;
}
}
template<class View>
ViewArray<View>::ViewArray(Region& r, const ViewArray<View>& a)
: n(a.size()) {
if (n>0) {
x = r.alloc<View>(n);
for (int i=0; i<n; i++)
x[i] = a[i];
} else {
x = nullptr;
}
}
template<class View>
forceinline
ViewArray<View>::ViewArray(const ViewArray<View>& a)
: n(a.n), x(a.x) {}
template<class View>
forceinline const ViewArray<View>&
ViewArray<View>::operator =(const ViewArray<View>& a) {
n = a.n; x = a.x;
return *this;
}
template<class View>
forceinline int
ViewArray<View>::size(void) const {
return n;
}
template<class View>
forceinline void
ViewArray<View>::size(int n0) {
n = n0;
}
template<class View>
forceinline View&
ViewArray<View>::operator [](int i) {
assert((i >= 0) && (i < size()));
return x[i];
}
template<class View>
forceinline const View&
ViewArray<View>::operator [](int i) const {
assert((i >= 0) && (i < size()));
return x[i];
}
template<class View>
forceinline typename ViewArray<View>::iterator
ViewArray<View>::begin(void) {
return x;
}
template<class View>
forceinline typename ViewArray<View>::const_iterator
ViewArray<View>::begin(void) const {
return x;
}
template<class View>
forceinline typename ViewArray<View>::iterator
ViewArray<View>::end(void) {
return x+n;
}
template<class View>
forceinline typename ViewArray<View>::const_iterator
ViewArray<View>::end(void) const {
return x+n;
}
template<class View>
forceinline typename ViewArray<View>::reverse_iterator
ViewArray<View>::rbegin(void) {
return reverse_iterator(x+n);
}
template<class View>
forceinline typename ViewArray<View>::const_reverse_iterator
ViewArray<View>::rbegin(void) const {
return const_reverse_iterator(x+n);
}
template<class View>
forceinline typename ViewArray<View>::reverse_iterator
ViewArray<View>::rend(void) {
return reverse_iterator(x);
}
template<class View>
forceinline typename ViewArray<View>::const_reverse_iterator
ViewArray<View>::rend(void) const {
return const_reverse_iterator(x);
}
template<class View>
forceinline void
ViewArray<View>::move_fst(int i) {
x[i]=x[0]; x++; n--;
}
template<class View>
forceinline void
ViewArray<View>::move_lst(int i) {
n--; x[i]=x[n];
}
template<class View>
forceinline void
ViewArray<View>::drop_fst(int i) {
assert(i>=0);
x += i; n -= i;
}
template<class View>
forceinline void
ViewArray<View>::drop_lst(int i) {
assert(i<n);
n = i+1;
}
template<class View>
forceinline void
ViewArray<View>::move_fst(int i, Space& home, Propagator& p, PropCond pc) {
// Move x[0] to x[i]
x[i].cancel(home,p,pc);
x[i]=x[0]; x++; n--;
}
template<class View>
forceinline void
ViewArray<View>::move_lst(int i, Space& home, Propagator& p, PropCond pc) {
// Move x[n-1] to x[i]
x[i].cancel(home,p,pc);
n--; x[i]=x[n];
}
template<class View>
void
ViewArray<View>::drop_fst(int i, Space& home, Propagator& p, PropCond pc) {
// Drop elements from 0..i-1
assert(i>=0);
for (int j=0; j<i; j++)
x[j].cancel(home,p,pc);
x += i; n -= i;
}
template<class View>
void
ViewArray<View>::drop_lst(int i, Space& home, Propagator& p, PropCond pc) {
// Drop elements from i+1..n-1
assert(i<n);
for (int j=i+1; j<n; j++)
x[j].cancel(home,p,pc);
n = i+1;
}
template<class View>
forceinline void
ViewArray<View>::move_fst(int i, Space& home, Advisor& a) {
// Move x[0] to x[i]
x[i].cancel(home,a);
x[i]=x[0]; x++; n--;
}
template<class View>
forceinline void
ViewArray<View>::move_lst(int i, Space& home, Advisor& a) {
// Move x[n-1] to x[i]
x[i].cancel(home,a);
n--; x[i]=x[n];
}
template<class View>
void
ViewArray<View>::drop_fst(int i, Space& home, Advisor& a) {
// Drop elements from 0..i-1
assert(i>=0);
for (int j=0; j<i; j++)
x[j].cancel(home,a);
x += i; n -= i;
}
template<class View>
void
ViewArray<View>::drop_lst(int i, Space& home, Advisor& a) {
// Drop elements from i+1..n-1
assert(i<n);
for (int j=i+1; j<n; j++)
x[j].cancel(home,a);
n = i+1;
}
template<class View>
void
ViewArray<View>::update(Space& home, ViewArray<View>& y) {
n = y.n;
if (n > 0) {
x = home.alloc<View>(n);
for (int i=0; i<n; i++)
x[i].update(home, y.x[i]);
} else {
x = nullptr;
}
}
template<class View>
void
ViewArray<View>::subscribe(Space& home, Propagator& p, PropCond pc,
bool schedule) {
for (int i=0; i<n; i++)
x[i].subscribe(home,p,pc,schedule);
}
template<class View>
void
ViewArray<View>::cancel(Space& home, Propagator& p, PropCond pc) {
for (int i=0; i<n; i++)
x[i].cancel(home,p,pc);
}
template<class View>
void
ViewArray<View>::subscribe(Space& home, Advisor& a) {
for (int i=0; i<n; i++)
x[i].subscribe(home,a);
}
template<class View>
void
ViewArray<View>::cancel(Space& home, Advisor& a) {
for (int i=0; i<n; i++)
x[i].cancel(home,a);
}
template<class View>
void
ViewArray<View>::reschedule(Space& home, Propagator& p, PropCond pc) {
for (int i=0; i<n; i++)
x[i].reschedule(home,p,pc);
}
template<class View>
forceinline bool
ViewArray<View>::assigned(void) const {
for (int i=0; i<n; i++)
if (!x[i].assigned())
return false;
return true;
}
template<class View>
bool
ViewArray<View>::same(void) const {
if (n < 2)
return false;
Region r;
View* y = r.alloc<View>(n);
int j=0;
for (int i=0; i<n; i++)
if (!x[i].assigned())
y[j++] = x[i];
if (j < 2)
return false;
Support::quicksort<View>(y,j);
for (int i=1; i<j; i++)
if (y[i-1] == y[i])
return true;
return false;
}
template<class View>
bool
ViewArray<View>::same(const View& y) const {
if (y.assigned())
return false;
for (int i=0; i<n; i++)
if (x[i] == y)
return true;
return false;
}
template<class View>
void
ViewArray<View>::unique(void) {
if (n < 2)
return;
Region r;
Kernel::ViewOcc<View>* o = r.alloc<Kernel::ViewOcc<View>>(n);
for (int i=0; i<n; i++) {
o[i].x = x[i]; o[i].i = i;
}
Support::quicksort<Kernel::ViewOcc<View>>(o,n);
// Assign bucket numbers
int* bkt = r.alloc<int>(n);
int b = 0;
bkt[o[0].i] = b;
for (int i=1; i<n; i++) {
if (o[i-1].x != o[i].x)
b++;
bkt[o[i].i] = b;
}
// Eliminate duplicate elements
Support::BitSet<Region> seen(r,static_cast<unsigned int>(b+1));
int j=0;
for (int i=0; i<n; i++)
if (!seen.get(bkt[i])) {
x[j++]=x[i]; seen.set(bkt[i]);
} else {
x[j]=x[i];
}
assert(j == b+1);
n = j;
}
template<class View>
forceinline void*
ViewArray<View>::operator new(size_t) throw() {
return nullptr;
}
template<class View>
forceinline void
ViewArray<View>::operator delete(void*,size_t) {
}
/*
* Sharing for view arrays
*
*/
template<class ViewX, class ViewY>
bool
shared(ViewArray<ViewX> x, ViewArray<ViewY> y) {
if ((x.size() == 0) || (y.size() == 0))
return false;
Region r;
void** px = r.alloc<void*>(x.size());
int j=0;
for (int i=0; i<x.size(); i++)
if (!x[i].assigned() && x[i].varimp())
px[j++] = x[i].varimp();
if (j == 0)
return false;
void** py = r.alloc<void*>(y.size());
int k=0;
for (int i=0; i<y.size(); i++)
if (!y[i].assigned() && y[i].varimp())
py[k++] = y[i].varimp();
if (k == 0)
return false;
return Kernel::duplicates(px,j,py,k);
}
template<class ViewX, class ViewY>
bool
shared(ViewArray<ViewX> x, ViewY y) {
if (y.assigned() || !y.varimp())
return false;
for (int i=0; i<x.size(); i++)
if (!x[i].assigned() && x[i].varimp() && (x[i].varimp() == y.varimp()))
return true;
return false;
}
template<class ViewX, class ViewY>
forceinline bool
shared(ViewX x, ViewArray<ViewY> y) {
return shared(y,x);
}
template<class View>
bool
shared(ViewArray<View> x) {
if (x.size() < 2)
return false;
Region r;
void** px = r.alloc<void*>(x.size());
int j=0;
for (int i=0; i<x.size(); i++)
if (!x[i].assigned() && x[i].varimp())
px[j++] = x[i].varimp();
return (j > 2) && Kernel::duplicates(px,j);
}
/*
* Argument arrays: base class
*
*/
template<class T>
forceinline T*
ArgArrayBase<T>::allocate(int n) {
return (n > onstack_size) ?
heap.alloc<T>(static_cast<unsigned int>(n)) : &onstack[0];
}
template<class T>
forceinline void
ArgArrayBase<T>::resize(int i) {
if (n+i >= capacity) {
assert(n+i >= onstack_size);
int newCapacity = (3*capacity)/2;
if (newCapacity <= n+i)
newCapacity = n+i;
T* newA = allocate(newCapacity);
heap.copy<T>(newA,a,n);
if (capacity > onstack_size)
heap.free(a,capacity);
capacity = newCapacity;
a = newA;
}
}
template<class T>
forceinline
ArgArrayBase<T>::ArgArrayBase(void)
: n(0), capacity(onstack_size), a(allocate(0)) {}
template<class T>
forceinline
ArgArrayBase<T>::ArgArrayBase(int n0)
: n(n0), capacity(n < onstack_size ? onstack_size : n), a(allocate(n)) {}
template<class T>
inline
ArgArrayBase<T>::ArgArrayBase(const ArgArrayBase<T>& aa)
: n(aa.n), capacity(n < onstack_size ? onstack_size : n), a(allocate(n)) {
heap.copy<T>(a,aa.a,n);
}
template<class T>
inline
ArgArrayBase<T>::ArgArrayBase(const std::vector<T>& aa)
: n(static_cast<int>(aa.size())),
capacity(n < onstack_size ? onstack_size : n), a(allocate(n)) {
heap.copy<T>(a,&aa[0],n);
}
template<class T>
inline
ArgArrayBase<T>::ArgArrayBase(std::initializer_list<T> aa)
: n(static_cast<int>(aa.size())),
capacity(n < onstack_size ? onstack_size : n), a(allocate(n)) {
int i=0;
for (const T& x : aa)
a[i++]=x;
}
template<class T>
forceinline
ArgArrayBase<T>::~ArgArrayBase(void) {
if (capacity > onstack_size)
heap.free(a,capacity);
}
template<class T>
forceinline const ArgArrayBase<T>&
ArgArrayBase<T>::operator =(const ArgArrayBase<T>& aa) {
if (&aa != this) {
if (capacity > onstack_size)
heap.free(a,capacity);
n = aa.n;
capacity = (n < onstack_size ? onstack_size : n);
a = allocate(aa.n);
heap.copy<T>(a,aa.a,n);
}
return *this;
}
template<class T>
forceinline int
ArgArrayBase<T>::size(void) const {
return n;
}
template<class T>
forceinline T&
ArgArrayBase<T>::operator [](int i) {
assert((i>=0) && (i < n));
return a[i];
}
template<class T>
forceinline const T&
ArgArrayBase<T>::operator [](int i) const {
assert((i>=0) && (i < n));
return a[i];
}
template<class T>
forceinline typename ArgArrayBase<T>::iterator
ArgArrayBase<T>::begin(void) {
return a;
}
template<class T>
forceinline typename ArgArrayBase<T>::const_iterator
ArgArrayBase<T>::begin(void) const {
return a;
}
template<class T>
forceinline typename ArgArrayBase<T>::iterator
ArgArrayBase<T>::end(void) {
return a+n;
}
template<class T>
forceinline typename ArgArrayBase<T>::const_iterator
ArgArrayBase<T>::end(void) const {
return a+n;
}
template<class T>
forceinline typename ArgArrayBase<T>::reverse_iterator
ArgArrayBase<T>::rbegin(void) {
return reverse_iterator(a+n);
}
template<class T>
forceinline typename ArgArrayBase<T>::const_reverse_iterator
ArgArrayBase<T>::rbegin(void) const {
return const_reverse_iterator(a+n);
}
template<class T>
forceinline typename ArgArrayBase<T>::reverse_iterator
ArgArrayBase<T>::rend(void) {
return reverse_iterator(a);
}
template<class T>
forceinline typename ArgArrayBase<T>::const_reverse_iterator
ArgArrayBase<T>::rend(void) const {
return const_reverse_iterator(a);
}
template<class T> template<class A>
A
ArgArrayBase<T>::slice(int start, int inc, int maxN) {
assert(n==0 || start < n);
if (n==0 || maxN<0)
maxN = n;
int s;
if (inc == 0)
s = n-start;
else if (inc > 0)
s = (n-start)/inc + ((n-start) % inc == 0 ? 0 : 1);
else
s = (start+1)/-inc + ((start+1) % -inc == 0 ? 0 : 1);
A r(std::min(maxN,s));
for (int i=0; i<r.size(); i++, start+=inc)
new (&r[i]) T(a[start]);
return r;
}
template<class T> template<class A>
inline A&
ArgArrayBase<T>::append(const T& x) {
resize(1);
new (&a[n++]) T(x);
return static_cast<A&>(*this);
}
template<class T>
template<class InputIterator>
inline
ArgArrayBase<T>::ArgArrayBase(InputIterator first, InputIterator last)
: n(0), capacity(onstack_size), a(allocate(0)) {
while (first != last) {
(void) append<ArgArrayBase<T>>(*first);
++first;
}
}
template<class T> template<class A>
inline A&
ArgArrayBase<T>::append(const ArgArrayBase<T>& x) {
resize(x.size());
for (int i=0; i<x.size(); i++)
new (&a[n++]) T(x[i]);
return static_cast<A&>(*this);
}
template<class T> template<class A>
inline A
ArgArrayBase<T>::concat(const ArgArrayBase<T>& x) const {
A r(n+x.n);
for (int i=0; i<n; i++)
new (&r[i]) T(a[i]);
for (int i=0; i<x.n; i++)
new (&r[n+i]) T(x.a[i]);
return r;
}
template<class T> template<class A>
inline A
ArgArrayBase<T>::concat(const T& x) const {
A r(n+1);
for (int i=0; i<n; i++)
new (&r[i]) T(a[i]);
new (&r[n]) T(x);
return r;
}
/*
* Argument arrays
*
*/
template<class T>
forceinline
ArgArray<T>::ArgArray(void) {}
template<class T>
forceinline
ArgArray<T>::ArgArray(int n)
: ArgArrayBase<T>(n) {}
template<class T>
ArgArray<T>::ArgArray(int n, const T* a0)
: ArgArrayBase<T>(n) {
for (int i=0; i<n; i++)
a[i] = a0[i];
}
template<class T>
forceinline
ArgArray<T>::ArgArray(const ArgArray<T>& aa)
: ArgArrayBase<T>(aa) {}
template<class T>
forceinline
ArgArray<T>::ArgArray(const std::vector<T>& aa)
: ArgArrayBase<T>(aa) {}
template<class T>
forceinline
ArgArray<T>::ArgArray(std::initializer_list<T> aa)
: ArgArrayBase<T>(aa) {}
template<class T>
template<class InputIterator>
forceinline
ArgArray<T>::ArgArray(InputIterator first, InputIterator last)
: ArgArrayBase<T>(first,last) {}
template<class T>
forceinline typename ArrayTraits<ArgArray<T>>::ArgsType
ArgArray<T>::slice(int start, int inc, int maxN) {
return ArgArrayBase<T>::template slice
<typename ArrayTraits<ArgArray<T>>::ArgsType>
(start,inc,maxN);
}
template<class T>
forceinline typename ArrayTraits<ArgArray<T>>::ArgsType&
ArgArray<T>::operator <<(const T& x) {
return
ArgArrayBase<T>::template append
<typename ArrayTraits<ArgArray<T>>::ArgsType>(x);
}
template<class T>
forceinline typename ArrayTraits<ArgArray<T>>::ArgsType&
ArgArray<T>::operator <<(const ArgArray<T>& x) {
return
ArgArrayBase<T>::template append
<typename ArrayTraits<ArgArray<T>>::ArgsType>(x);
}
template<class T>
typename ArrayTraits<ArgArray<T>>::ArgsType
operator +(const ArgArray<T>& x, const ArgArray<T>& y) {
return x.template concat
<typename ArrayTraits<ArgArray<T>>::ArgsType>(y);
}
template<class T>
typename ArrayTraits<ArgArray<T>>::ArgsType
operator +(const ArgArray<T>& x, const T& y) {
return x.template concat
<typename ArrayTraits<ArgArray<T>>::ArgsType>(y);
}
template<class T>
typename ArrayTraits<ArgArray<T>>::ArgsType
operator +(const T& x, const ArgArray<T>& y) {
ArgArray<T> xa(1);
xa[0] = x;
return xa.template concat
<typename ArrayTraits<ArgArray<T>>::ArgsType>(y);
}
/*
* Argument arrays for variables
*
*/
template<class Var>
forceinline
VarArgArray<Var>::VarArgArray(void) {}
template<class Var>
forceinline
VarArgArray<Var>::VarArgArray(int n) : ArgArrayBase<Var>(n) {}
template<class Var>
forceinline
VarArgArray<Var>::VarArgArray(const VarArgArray<Var>& aa)
: ArgArrayBase<Var>(aa) {}
template<class Var>
forceinline
VarArgArray<Var>::VarArgArray(const std::vector<Var>& aa)
: ArgArrayBase<Var>(aa) {}
template<class Var>
forceinline
VarArgArray<Var>::VarArgArray(std::initializer_list<Var> aa)
: ArgArrayBase<Var>(aa) {}
template<class Var>
template<class InputIterator>
forceinline
VarArgArray<Var>::VarArgArray(InputIterator first, InputIterator last)
: ArgArrayBase<Var>(first,last) {}
template<class Var>
inline
VarArgArray<Var>::VarArgArray(const VarArray<Var>& x)
: ArgArrayBase<Var>(x.size()) {
for (int i=0; i<x.size(); i++)
a[i]=x[i];
}
template<class Var>
forceinline typename ArrayTraits<VarArgArray<Var>>::ArgsType
VarArgArray<Var>::slice(int start, int inc, int maxN) {
return ArgArrayBase<Var>::template slice
<typename ArrayTraits<VarArgArray<Var>>::ArgsType>
(start,inc,maxN);
}
template<class Var>
forceinline typename ArrayTraits<VarArgArray<Var>>::ArgsType&
VarArgArray<Var>::operator <<(const Var& x) {
return
ArgArrayBase<Var>::template append
<typename ArrayTraits<VarArgArray<Var>>::ArgsType>(x);
}
template<class Var>
forceinline typename ArrayTraits<VarArgArray<Var>>::ArgsType&
VarArgArray<Var>::operator <<(const VarArgArray<Var>& x) {
return
ArgArrayBase<Var>::template append
<typename ArrayTraits<VarArgArray<Var>>::ArgsType>(x);
}
template<class Var>
typename ArrayTraits<VarArgArray<Var>>::ArgsType
operator +(const VarArgArray<Var>& x, const VarArgArray<Var>& y) {
return x.template concat
<typename ArrayTraits<VarArgArray<Var>>::ArgsType>(y);
}
template<class Var>
typename ArrayTraits<VarArgArray<Var>>::ArgsType
operator +(const VarArgArray<Var>& x, const Var& y) {
return x.template concat
<typename ArrayTraits<VarArgArray<Var>>::ArgsType>(y);
}
template<class Var>
typename ArrayTraits<VarArgArray<Var>>::ArgsType
operator +(const Var& x, const VarArgArray<Var>& y) {
VarArgArray<Var> xa(1);
xa[0] = x;
return xa.template concat
<typename ArrayTraits<VarArgArray<Var>>::ArgsType>(y);
}
template<class Var>
forceinline bool
VarArgArray<Var>::assigned(void) const {
for (int i=0; i<n; i++)
if (!a[i].assigned())
return false;
return true;
}
/*
* Checking for multiple occurences of the same variable
*
*/
template<class Var>
bool
same(VarArgArray<Var> x, VarArgArray<Var> y) {
if ((x.size() == 0) || (y.size() == 0))
return false;
Region r;
void** px = r.alloc<void*>(x.size());
int j=0;
for (int i=0; i<x.size(); i++)
if (!x[i].assigned())
px[j++] = x[i].varimp();
if (j == 0)
return false;
void** py = r.alloc<void*>(y.size());
int k=0;
for (int i=0; i<y.size(); i++)
if (!y[i].assigned())
py[k++] = y[i].varimp();
if (k == 0)
return false;
return Kernel::duplicates(px,j,py,k);
}
template<class Var>
bool
same(VarArgArray<Var> x, Var y) {
if (y.assigned())
return false;
for (int i=0; i<x.size(); i++)
if (x[i].varimp() == y.varimp())
return true;
return false;
}
template<class Var>
forceinline bool
same(Var x, VarArgArray<Var> y) {
return same(y,x);
}
template<class Var>
bool
same(VarArgArray<Var> x) {
if (x.size() < 2)
return false;
Region r;
void** px = r.alloc<void*>(x.size());
int j=0;
for (int i=0; i<x.size(); i++)
if (!x[i].assigned())
px[j++] = x[i].varimp();
return (j > 1) && Kernel::duplicates(px,j);
}
/*
* Interdependent code
*
*/
template<class Var>
inline
VarArray<Var>::VarArray(Space& home, const VarArgArray<Var>& a)
: n(a.size()) {
if (n>0) {
x = home.alloc<Var>(n);
for (int i=0; i<n; i++)
x[i] = a[i];
} else {
x = nullptr;
}
}
/*
* Printing of arrays
*
*/
template<class Char, class Traits, class Var>
std::basic_ostream<Char,Traits>&
operator <<(std::basic_ostream<Char,Traits>& os,
const VarArray<Var>& x) {
std::basic_ostringstream<Char,Traits> s;
s.copyfmt(os); s.width(0);
s << '{';
if (x.size() > 0) {
s << x[0];
for (int i=1; i<x.size(); i++)
s << ", " << x[i];
}
s << '}';
return os << s.str();
}
template<class Char, class Traits, class View>
std::basic_ostream<Char,Traits>&
operator <<(std::basic_ostream<Char,Traits>& os,
const ViewArray<View>& x) {
std::basic_ostringstream<Char,Traits> s;
s.copyfmt(os); s.width(0);
s << '{';
if (x.size() > 0) {
s << x[0];
for (int i=1; i<x.size(); i++)
s << ", " << x[i];
}
s << '}';
return os << s.str();
}
template<class Char, class Traits, class T>
std::basic_ostream<Char,Traits>&
operator <<(std::basic_ostream<Char,Traits>& os,
const ArgArrayBase<T>& x) {
std::basic_ostringstream<Char,Traits> s;
s.copyfmt(os); s.width(0);
s << '{';
if (x.size() > 0) {
s << x[0];
for (int i=1; i<x.size(); i++)
s << ", " << x[i];
}
s << '}';
return os << s.str();
}
}
// STATISTICS: kernel-other
Gecode::Advisor
Base-class for advisors.
Definition core.hpp:1292
Gecode::ArgArrayBase
Base-class for argument arrays.
Definition array.hpp:537
Gecode::ArgArrayBase::const_reference
const T & const_reference
Type of a constant reference to the value type.
Definition array.hpp:580
Gecode::ArgArrayBase::allocate
T * allocate(int n)
Allocate memory for n elements.
Definition array.hpp:1527
Gecode::ArgArrayBase< int >::onstack_size
static const int onstack_size
Definition array.hpp:546
Gecode::ArgArrayBase::operator=
const ArgArrayBase< T > & operator=(const ArgArrayBase< T > &a)
Initialize from view array a (copy elements).
Definition array.hpp:1593
Gecode::ArgArrayBase< int >::onstack
int onstack[onstack_size]
Definition array.hpp:548
Gecode::ArgArrayBase::const_pointer
const T * const_pointer
Type of a read-only pointer to the value type.
Definition array.hpp:584
Gecode::ArgArrayBase::rend
const_reverse_iterator rend(void) const
Return a reverse and read-only iterator past the beginning of the array.
Definition array.hpp:1669
Gecode::ArgArrayBase::rbegin
const_reverse_iterator rbegin(void) const
Return a reverse and read-only iterator at the end of the array.
Definition array.hpp:1657
Gecode::ArgArrayBase::value_type
T value_type
Type of the view stored in this array.
Definition array.hpp:576
Gecode::ArgArrayBase::ArgArrayBase
ArgArrayBase(int n)
Allocate array with n elements.
Definition array.hpp:1556
Gecode::ArgArrayBase< int >::a
int * a
Definition array.hpp:544
Gecode::ArgArrayBase::rbegin
reverse_iterator rbegin(void)
Return a reverse iterator at the end of the array.
Definition array.hpp:1651
Gecode::ArgArrayBase::end
const_iterator end(void) const
Return a read-only iterator past the end of the array.
Definition array.hpp:1645
Gecode::ArgArrayBase::resize
void resize(int i)
Resize to hold at least i additional elements.
Definition array.hpp:1534
Gecode::ArgArrayBase::~ArgArrayBase
~ArgArrayBase(void)
Destructor.
Definition array.hpp:1586
Gecode::ArgArrayBase::reverse_iterator
std::reverse_iterator< T * > reverse_iterator
Type of the iterator used to iterate backwards through this array's elements.
Definition array.hpp:590
Gecode::ArgArrayBase::ArgArrayBase
ArgArrayBase(std::initializer_list< T > a)
Initialize from initializer list a.
Definition array.hpp:1576
Gecode::ArgArrayBase::concat
A concat(const ArgArrayBase< T > &x) const
Return this array concatenated with x.
Definition array.hpp:1723
Gecode::ArgArrayBase::concat
A concat(const T &x) const
Return this array concatenated with x.
Definition array.hpp:1734
Gecode::ArgArrayBase::append
A & append(const ArgArrayBase< T > &x)
Append x to the end of the array.
Definition array.hpp:1714
Gecode::ArgArrayBase::ArgArrayBase
ArgArrayBase(InputIterator first, InputIterator last)
Initialize from InputIterator begin and end.
Definition array.hpp:1703
Gecode::ArgArrayBase::rend
reverse_iterator rend(void)
Return a reverse iterator past the beginning of the array.
Definition array.hpp:1663
Gecode::ArgArrayBase::iterator
T * iterator
Type of the iterator used to iterate through this array's elements.
Definition array.hpp:586
Gecode::ArgArrayBase::ArgArrayBase
ArgArrayBase(const std::vector< T > &a)
Initialize from vector a.
Definition array.hpp:1568
Gecode::ArgArrayBase::slice
A slice(int start, int inc=1, int n=-1)
Definition array.hpp:1675
Gecode::ArgArrayBase::begin
const_iterator begin(void) const
Return a read-only iterator at the beginning of the array.
Definition array.hpp:1633
Gecode::ArgArrayBase::operator[]
T & operator[](int i)
Return element at position i.
Definition array.hpp:1613
Gecode::ArgArrayBase::pointer
T * pointer
Type of a pointer to the value type.
Definition array.hpp:582
Gecode::ArgArrayBase< int >::capacity
int capacity
Definition array.hpp:542
Gecode::ArgArrayBase< int >::n
int n
Definition array.hpp:540
Gecode::ArgArrayBase::append
A & append(const T &x)
Insert a new element x at the end of the array (increase size by 1).
Definition array.hpp:1694
Gecode::ArgArrayBase::reference
T & reference
Type of a reference to the value type.
Definition array.hpp:578
Gecode::ArgArrayBase::end
iterator end(void)
Return an iterator past the end of the array.
Definition array.hpp:1639
Gecode::ArgArrayBase::const_iterator
const T * const_iterator
Type of the iterator used to iterate read-only through this array's elements.
Definition array.hpp:588
Gecode::ArgArrayBase::begin
iterator begin(void)
Return an iterator at the beginning of the array.
Definition array.hpp:1627
Gecode::ArgArrayBase::ArgArrayBase
ArgArrayBase(const ArgArrayBase< T > &a)
Initialize from argument array a (copy elements).
Definition array.hpp:1561
Gecode::ArgArrayBase::ArgArrayBase
ArgArrayBase(void)
Allocate empty array.
Definition array.hpp:1551
Gecode::ArgArrayBase::size
int size(void) const
Return size of array (number of elements).
Definition array.hpp:1607
Gecode::ArgArrayBase::const_reverse_iterator
std::reverse_iterator< const T * > const_reverse_iterator
Type of the iterator used to iterate backwards and read-only through this array's elements.
Definition array.hpp:592
Gecode::ArgArray
Argument array for non-primitive types.
Definition array.hpp:691
Gecode::ArgArray::ArgArray
ArgArray(InputIterator first, InputIterator last)
Initialize from InputIterator first and last.
Definition array.hpp:1782
Gecode::ArgArray::ArgArray
ArgArray(const ArgArray< T > &a)
Initialize from argument array a (copy elements).
Definition array.hpp:1766
Gecode::ArgArray< IntSet >::ArgArray
ArgArray(void)
Gecode::ArgArray::slice
ArrayTraits< ArgArray< T > >::ArgsType slice(int start, int inc=1, int n=-1)
Return slice of length n such that forall , .
Definition array.hpp:1787
Gecode::ArgArray::ArgArray
ArgArray(int n)
Allocate array with n elements.
Definition array.hpp:1754
Gecode::ArgArray::ArgArray
ArgArray(std::initializer_list< T > a)
Initialize from initializer list a.
Definition array.hpp:1776
Gecode::ArgArray::ArgArray
ArgArray(int n, const T *e)
Allocate array with n elements and initialize with elements from array e.
Definition array.hpp:1758
Gecode::ArgArray::operator+
friend ArrayTraits< ArgArray< T > >::ArgsType operator+(const ArgArray< T > &x, const ArgArray< T > &y)
Insert a new element x at the end of the array (increase size by 1).
Definition array.hpp:1811
Gecode::ArgArray::ArgArray
ArgArray(const std::vector< T > &a)
Initialize from vector a.
Definition array.hpp:1771
Gecode::ArgArray::operator<<
ArrayTraits< ArgArray< T > >::ArgsType & operator<<(const T &x)
Insert a new element x at the end of the array (increase size by 1).
Definition array.hpp:1795
Gecode::ArrayTraits
Traits of arrays in Gecode.
Definition array.hpp:94
Gecode::FloatVal::x
FloatValImpType x
Implementation of float value.
Definition float.hh:425
Gecode::Kernel::ViewOcc
Occurence information for a view.
Definition array.hpp:50
Gecode::Kernel::ViewOcc::operator<
bool operator<(const ViewOcc &y) const
Sorting order.
Definition array.hpp:62
Gecode::Kernel::ViewOcc::x
View x
The view.
Definition array.hpp:53
Gecode::Kernel::ViewOcc::i
int i
The original index in the array.
Definition array.hpp:55
Gecode::Propagator
Base-class for propagators.
Definition core.hpp:1064
Gecode::Region
Handle to region.
Definition region.hpp:55
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::Support::BitSetBase::get
bool get(unsigned int i) const
Access value at bit i.
Definition bitset-base.hpp:590
Gecode::Support::BitSetBase::set
void set(unsigned int i)
Set bit i.
Definition bitset-base.hpp:595
Gecode::Support::BitSet
Simple bitsets.
Definition bitset.hpp:45
Gecode::View
Gecode::VarArgArray
Argument array for variables.
Definition array.hpp:774
Gecode::VarArgArray::same
bool same(VarArgArray< Var > x, VarArgArray< Var > y)
Test whether array x together with array y contains at least one variable being the same.
Definition array.hpp:1937
Gecode::VarArgArray::slice
ArrayTraits< VarArgArray< Var > >::ArgsType slice(int start, int inc=1, int n=-1)
Return slice of length n such that forall , .
Definition array.hpp:1876
Gecode::VarArgArray::assigned
bool assigned(void) const
Test if all variables are assigned.
Definition array.hpp:1923
Gecode::VarArgArray::operator<<
ArrayTraits< VarArgArray< Var > >::ArgsType & operator<<(const Var &x)
Insert a new element x at the end of the array (increase size by 1).
Definition array.hpp:1884
Gecode::VarArgArray::operator+
friend ArrayTraits< VarArgArray< Var > >::ArgsType operator+(const VarArgArray< Var > &x, const VarArgArray< Var > &y)
Insert a new element x at the end of the array (increase size by 1).
Definition array.hpp:1900
Gecode::VarArgArray::same
bool same(Var x, VarArgArray< Var > y)
Test whether array y contains variable x.
Definition array.hpp:1971
Gecode::VarArgArray::same
bool same(VarArgArray< Var > x, Var y)
Test whether array x contains variable y.
Definition array.hpp:1960
Gecode::VarArgArray::VarArgArray
VarArgArray(void)
Allocate empty array.
Definition array.hpp:1839
Gecode::VarArray
Variable arrays
Definition array.hpp:112
Gecode::VarArray::assigned
bool assigned(void) const
Test if all variables are assigned.
Definition array.hpp:1026
Gecode::VarArray::rbegin
reverse_iterator rbegin(void)
Return a reverse iterator at the end of the array.
Definition array.hpp:989
Gecode::VarArray::const_reference
const Var & const_reference
Type of a constant reference to the value type.
Definition array.hpp:126
Gecode::VarArray::operator=
const VarArray< Var > & operator=(const VarArray< Var > &a)
Initialize from variable array a (share elements).
Definition array.hpp:919
Gecode::VarArray::slice
ArrayTraits< VarArgArray< Var > >::ArgsType slice(int start, int inc=1, int n=-1)
Definition array.hpp:946
Gecode::VarArray::rend
const_reverse_iterator rend(void) const
Return a reverse and read-only iterator past the beginning of the array.
Definition array.hpp:1007
Gecode::VarArray::begin
const_iterator begin(void) const
Return a read-only iterator at the beginning of the array.
Definition array.hpp:971
Gecode::VarArray< Gecode::IntVar >::n
int n
Definition array.hpp:115
Gecode::VarArray::VarArray
VarArray(void)
Default constructor (array of size 0).
Definition array.hpp:901
Gecode::VarArray::reverse_iterator
std::reverse_iterator< Var * > reverse_iterator
Type of the iterator used to iterate backwards through this array's elements.
Definition array.hpp:136
Gecode::VarArray::end
const_iterator end(void) const
Return a read-only iterator past the end of the array.
Definition array.hpp:983
Gecode::VarArray::size
int size(void) const
Return size of array (number of elements).
Definition array.hpp:926
Gecode::VarArray::value_type
Var value_type
Type of the variable stored in this array.
Definition array.hpp:122
Gecode::VarArray::update
void update(Space &home, VarArray< Var > &a)
Update array to be a clone of array a.
Definition array.hpp:1013
Gecode::VarArray::begin
iterator begin(void)
Return an iterator at the beginning of the array.
Definition array.hpp:965
Gecode::VarArray::const_iterator
const Var * const_iterator
Type of the iterator used to iterate read-only through this array's elements.
Definition array.hpp:134
Gecode::VarArray::pointer
Var * pointer
Type of a pointer to the value type.
Definition array.hpp:128
Gecode::VarArray::VarArray
VarArray(Space &home, int m)
Allocate array with m variables.
Definition array.hpp:905
Gecode::VarArray::reference
Var & reference
Type of a reference to the value type.
Definition array.hpp:124
Gecode::VarArray::const_reverse_iterator
std::reverse_iterator< const Var * > const_reverse_iterator
Type of the iterator used to iterate backwards and read-only through this array's elements.
Definition array.hpp:138
Gecode::VarArray::operator[]
Var & operator[](int i)
Return variable at position i.
Definition array.hpp:932
Gecode::VarArray::VarArray
VarArray(Space &home, const VarArgArray< Var > &)
Initialize from variable argument array a (copy elements).
Definition array.hpp:1998
Gecode::VarArray< Gecode::IntVar >::x
Gecode::IntVar * x
Definition array.hpp:117
Gecode::VarArray::end
iterator end(void)
Return an iterator past the end of the array.
Definition array.hpp:977
Gecode::VarArray::rend
reverse_iterator rend(void)
Return a reverse iterator past the beginning of the array.
Definition array.hpp:1001
Gecode::VarArray::const_pointer
const Var * const_pointer
Type of a read-only pointer to the value type.
Definition array.hpp:130
Gecode::VarArray::iterator
Var * iterator
Type of the iterator used to iterate through this array's elements.
Definition array.hpp:132
Gecode::VarArray::VarArray
VarArray(const VarArray< Var > &a)
Initialize from variable array a (share elements).
Definition array.hpp:913
Gecode::VarArray::rbegin
const_reverse_iterator rbegin(void) const
Return a reverse and read-only iterator at the end of the array.
Definition array.hpp:995
Gecode::Var
Base class for variables.
Definition var.hpp:40
Gecode::ViewArray
View arrays.
Definition array.hpp:253
Gecode::ViewArray::cancel
void cancel(Space &home, Advisor &a)
Cancel subscription of advisor a.
Definition array.hpp:1363
Gecode::ViewArray::update
void update(Space &home, ViewArray< View > &a)
Update array to be a clone of array a.
Definition array.hpp:1328
Gecode::ViewArray::same
bool same(const View &y) const
Test whether array contains a view being the same as y.
Definition array.hpp:1406
Gecode::ViewArray::drop_fst
void drop_fst(int i, Space &home, Propagator &p, PropCond pc)
Drop views from positions 0 to i-1 from array.
Definition array.hpp:1272
Gecode::ViewArray::const_reference
const View & const_reference
Type of a constant reference to the value type.
Definition array.hpp:267
Gecode::ViewArray::move_fst
void move_fst(int i, Space &home, Propagator &p, PropCond pc)
Move view from position 0 to position i (shift elements to the left).
Definition array.hpp:1256
Gecode::ViewArray::begin
const_iterator begin(void) const
Return a read-only iterator at the beginning of the array.
Definition array.hpp:1188
Gecode::ViewArray::shared
bool shared(ViewArray< ViewX > x, ViewArray< ViewY > y)
Test whether array x together with array y contains shared views.
Definition array.hpp:1466
Gecode::ViewArray::iterator
View * iterator
Type of the iterator used to iterate through this array's elements.
Definition array.hpp:273
Gecode::ViewArray::subscribe
void subscribe(Space &home, Advisor &a)
Subscribe advisor a to variable.
Definition array.hpp:1356
Gecode::ViewArray::reference
View & reference
Type of a reference to the value type.
Definition array.hpp:265
Gecode::ViewArray::reschedule
void reschedule(Space &home, Propagator &p, PropCond pc)
Re-schedule propagator p with propagation condition pc.
Definition array.hpp:1370
Gecode::ViewArray::value_type
View value_type
Type of the view stored in this array.
Definition array.hpp:263
Gecode::ViewArray::operator[]
View & operator[](int i)
Return view at position i.
Definition array.hpp:1168
Gecode::ViewArray::rend
const_reverse_iterator rend(void) const
Return a reverse and read-only iterator past the beginning of the array.
Definition array.hpp:1224
Gecode::ViewArray::const_iterator
const View * const_iterator
Type of the iterator used to iterate read-only through this array's elements.
Definition array.hpp:275
Gecode::ViewArray::drop_lst
void drop_lst(int i, Space &home, Propagator &p, PropCond pc)
Drop assigned views from positions i+1 to size()-1 from array.
Definition array.hpp:1282
Gecode::ViewArray::ViewArray
ViewArray(Space &home, const ViewArray< View > &a)
Initialize from view array a (copy elements).
Definition array.hpp:1120
Gecode::ViewArray::drop_fst
void drop_fst(int i)
Drop views from positions 0 to i-1 from array.
Definition array.hpp:1242
Gecode::ViewArray::rend
reverse_iterator rend(void)
Return a reverse iterator past the beginning of the array.
Definition array.hpp:1218
Gecode::ViewArray::shared
bool shared(ViewArray< ViewX > x, ViewY y)
Test whether array x contains a view shared with y.
Definition array.hpp:1489
Gecode::ViewArray::drop_fst
void drop_fst(int i, Space &home, Advisor &a)
Drop views from positions 0 to i-1 from array.
Definition array.hpp:1308
Gecode::ViewArray::reverse_iterator
std::reverse_iterator< View * > reverse_iterator
Type of the iterator used to iterate backwards through this array's elements.
Definition array.hpp:277
Gecode::ViewArray::move_fst
void move_fst(int i, Space &home, Advisor &a)
Move view from position 0 to position i (shift elements to the left).
Definition array.hpp:1292
Gecode::ViewArray::move_lst
void move_lst(int i, Space &home, Advisor &a)
Move view from position size()-1 to position i (truncate array by one).
Definition array.hpp:1300
Gecode::ViewArray::ViewArray
ViewArray(const ViewArray< View > &a)
Initialize from view array a (share elements).
Definition array.hpp:1144
Gecode::ViewArray::rbegin
reverse_iterator rbegin(void)
Return a reverse iterator at the end of the array.
Definition array.hpp:1206
Gecode::ViewArray::operator=
const ViewArray< View > & operator=(const ViewArray< View > &a)
Initialize from view array a (share elements).
Definition array.hpp:1149
Gecode::ViewArray::const_pointer
const View * const_pointer
Type of a read-only pointer to the value type.
Definition array.hpp:271
Gecode::ViewArray::begin
iterator begin(void)
Return an iterator at the beginning of the array.
Definition array.hpp:1182
Gecode::ViewArray::const_reverse_iterator
std::reverse_iterator< const View * > const_reverse_iterator
Type of the iterator used to iterate backwards and read-only through this array's elements.
Definition array.hpp:279
Gecode::ViewArray::ViewArray
ViewArray(Region &r, const VarArgArray< Var > &a)
Initialize from variable argument array a (copy elements).
Definition array.hpp:323
Gecode::ViewArray::unique
void unique(void)
Remove all duplicate views from array (changes element order).
Definition array.hpp:1417
Gecode::ViewArray::cancel
void cancel(Space &home, Propagator &p, PropCond pc)
Cancel subscription of propagator p with propagation condition pc to all views.
Definition array.hpp:1349
Gecode::ViewArray::drop_lst
void drop_lst(int i)
Drop views from positions i+1 to size()-1 from array.
Definition array.hpp:1249
Gecode::ViewArray::rbegin
const_reverse_iterator rbegin(void) const
Return a reverse and read-only iterator at the end of the array.
Definition array.hpp:1212
Gecode::ViewArray::drop_lst
void drop_lst(int i, Space &home, Advisor &a)
Drop assigned views from positions i+1 to size()-1 from array.
Definition array.hpp:1318
Gecode::ViewArray::move_lst
void move_lst(int i)
Move view from position size()-1 to position i (truncate array by one).
Definition array.hpp:1236
Gecode::ViewArray::end
const_iterator end(void) const
Return a read-only iterator past the end of the array.
Definition array.hpp:1200
Gecode::ViewArray::subscribe
void subscribe(Space &home, Propagator &p, PropCond pc, bool schedule=true)
Subscribe propagator p with propagation condition pc to variable.
Definition array.hpp:1341
Gecode::ViewArray::assigned
bool assigned(void) const
Test if all variables are assigned.
Definition array.hpp:1377
Gecode::ViewArray::ViewArray
ViewArray(void)
Default constructor (array of size 0).
Definition array.hpp:1104
Gecode::ViewArray::move_lst
void move_lst(int i, Space &home, Propagator &p, PropCond pc)
Move view from position size()-1 to position i (truncate array by one).
Definition array.hpp:1264
Gecode::ViewArray::end
iterator end(void)
Return an iterator past the end of the array.
Definition array.hpp:1194
Gecode::ViewArray::ViewArray
ViewArray(Region &r, const ViewArray< View > &a)
Initialize from view array a (copy elements).
Definition array.hpp:1131
Gecode::ViewArray::same
bool same(void) const
Test whether array has multiple occurence of the same view.
Definition array.hpp:1386
Gecode::ViewArray::ViewArray
ViewArray(Region &r, int m)
Allocate array with m views.
Definition array.hpp:1114
Gecode::ViewArray::ViewArray
ViewArray(Space &home, const VarArgArray< Var > &a)
Initialize from variable argument array a (copy elements).
Definition array.hpp:305
Gecode::ViewArray::ViewArray
ViewArray(Space &home, int m)
Allocate array with m views.
Definition array.hpp:1108
Gecode::ViewArray::move_fst
void move_fst(int i)
Move view from position 0 to position i (shift elements to the left).
Definition array.hpp:1230
Gecode::ViewArray::shared
bool shared(ViewX x, ViewArray< ViewY > y)
Test whether array y contains a view shared with x.
Definition array.hpp:1500
Gecode::ViewArray::pointer
View * pointer
Type of a pointer to the value type.
Definition array.hpp:269
Gecode::ViewArray::shared
bool shared(ViewArray< View > x)
Test whether array x contains shared views.
Definition array.hpp:1506
Gecode::ViewArray::size
void size(int n)
Decrease size of array (number of elements).
Definition array.hpp:1162
Gecode::ViewArray< Gecode::IntVar >::size
int size(void) const
Gecode::heap
Heap heap
The single global heap.
Definition heap.cpp:44
Gecode::Int::OffsetView::update
void update(const NoOffset &)
Integer-precision integer scale view.
Definition view.hpp:638
GECODE_KERNEL_EXPORT
#define GECODE_KERNEL_EXPORT
Definition kernel.hh:70
Gecode::Kernel
Kernel functionality
Gecode::Kernel::duplicates
bool duplicates(void **p, int n)
Check whether p has duplicates among its n elements (changes p).
Definition array.cpp:39
Gecode::Support::quicksort
void quicksort(Type *l, Type *r, Less &less)
Standard quick sort.
Definition sort.hpp:130
Gecode
Gecode toplevel namespace
Gecode::operator+
FloatVal operator+(const FloatVal &x)
Definition val.hpp:164
Gecode::operator<<
Archive & operator<<(Archive &e, FloatNumBranch nl)
Definition val-sel.hpp:39
Gecode::same
bool same(VarArgArray< Var > x, VarArgArray< Var > y)
Definition array.hpp:1937
Gecode::shared
bool shared(ViewArray< ViewX > x, ViewArray< ViewY > y)
Definition array.hpp:1466
Gecode::PropCond
int PropCond
Type for propagation conditions.
Definition core.hpp:72
Test::Int::Basic::i
Gecode::IntArgs i({1, 2, 3, 4})
forceinline
#define forceinline
Definition config.hpp:187