/usr/include/gecode/int/gcc/post.hpp is in libgecode-dev 3.7.1-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
* Main authors:
* Patrick Pekczynski <pekczynski@ps.uni-sb.de>
*
* Contributing authors:
* Christian Schulte <schulte@gecode.org>
* Guido Tack <tack@gecode.org>
*
* Copyright:
* Patrick Pekczynski, 2004/2005
* Christian Schulte, 2009
* Guido Tack, 2009
*
* Last modified:
* $Date: 2011-08-08 18:04:53 +0200 (Mon, 08 Aug 2011) $ by $Author: schulte $
* $Revision: 12253 $
*
* 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>
#include <gecode/int/distinct.hh>
namespace Gecode { namespace Int { namespace GCC {
template<class Card>
/// %Sort by increasing cardinality
class CardLess : public Support::Less<Card> {
public:
bool operator ()(const Card& x, const Card& y) {
return x.card() < y.card();
}
};
/**
* \brief Post side constraints for the GCC
*
*/
template<class Card>
ExecStatus
postSideConstraints(Home home, ViewArray<IntView>& x, ViewArray<Card>& k) {
CardLess<Card> cl;
Support::quicksort(&k[0], k.size(), cl);
Region r(home);
{
int smin = 0;
int smax = 0;
for (int i = k.size(); i--; ) {
GECODE_ME_CHECK((k[i].gq(home, 0)));
GECODE_ME_CHECK((k[i].lq(home, x.size())));
smin += k[i].min();
smax += k[i].max();
}
// not enough variables to satisfy min req
if ((x.size() < smin) || (smax < x.size()))
return ES_FAILED;
}
// Remove all values from the x that are not in v
{
int* v = r.alloc<int>(k.size());
for (int i=k.size(); i--;)
v[i]=k[i].card();
Support::quicksort(v,k.size());
for (int i=x.size(); i--; ) {
Iter::Values::Array iv(v,k.size());
GECODE_ME_CHECK(x[i].inter_v(home, iv, false));
}
}
// Remove all values with 0 max occurrence
// and remove corresponding occurrence variables from k
{
// The number of zeroes
int n_z = 0;
for (int i=k.size(); i--;)
if (k[i].max() == 0)
n_z++;
if (n_z > 0) {
int* z = r.alloc<int>(n_z);
n_z = 0;
int n_k = 0;
for (int i=0; i<k.size(); i++)
if (k[i].max() == 0) {
z[n_z++] = k[i].card();
} else {
k[n_k++] = k[i];
}
k.size(n_k);
Support::quicksort(z,n_z);
for (int i=x.size(); i--;) {
Iter::Values::Array zi(z,n_z);
GECODE_ME_CHECK(x[i].minus_v(home,zi,false));
}
}
}
if (Card::propagate) {
Linear::Term<IntView>* t = r.alloc<Linear::Term<IntView> >(k.size());
for (int i = k.size(); i--; ) {
t[i].a=1; t[i].x=k[i].base();
}
Linear::post(home,t,k.size(),IRT_EQ,x.size(),ICL_BND);
}
return ES_OK;
}
/**
* \brief Check if GCC is equivalent to distinct
*
*/
template<class Card>
inline bool
isDistinct(Home home, ViewArray<IntView>& x, ViewArray<Card>& k) {
if (Card::propagate) {
Region r(home);
ViewRanges<IntView>* xrange = r.alloc<ViewRanges<IntView> >(x.size());
for (int i = x.size(); i--; ){
ViewRanges<IntView> iter(x[i]);
xrange[i] = iter;
}
Iter::Ranges::NaryUnion drl(r, &xrange[0], x.size());
if (static_cast<unsigned int>(k.size()) == Iter::Ranges::size(drl)) {
for (int i=k.size(); i--;)
if (k[i].min() != 1 || k[i].max() != 1)
return false;
return true;
} else {
return false;
}
} else {
for (int i=k.size(); i--;)
if (k[i].min() != 0 || k[i].max() != 1)
return false;
return true;
}
}
}}}
// STATISTICS: int-prop
|