This file is indexed.

/usr/include/gecode/set/element/union.hpp is in libgecode-dev 5.1.0-2build1.

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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
 *  Main authors:
 *     Guido Tack <tack@gecode.org>
 *     Christian Schulte <schulte@gecode.org>
 *
 *  Copyright:
 *     Guido Tack, 2004,2006
 *     Christian Schulte, 2004
 *
 *  Last modified:
 *     $Date: 2016-06-29 17:28:17 +0200 (Wed, 29 Jun 2016) $ by $Author: schulte $
 *     $Revision: 15137 $
 *
 *  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 Set { namespace Element {

  template<class View, class View0, class View1>
  forceinline
  ElementUnion<View,View0,View1>::
  ElementUnion(Home home, IdxViewArray& iv0, View0 y0, View1 y1)
    : Propagator(home), iv(iv0), x0(y0), x1(y1) {
    home.notice(*this,AP_DISPOSE);
    x0.subscribe(home,*this, PC_SET_ANY);
    x1.subscribe(home,*this, PC_SET_ANY);
    iv.subscribe(home,*this, PC_SET_ANY);
  }

  template<class View, class View0, class View1>
  forceinline
  ElementUnion<View,View0,View1>::
  ElementUnion(Space& home, bool share, ElementUnion<View,View0,View1>& p)
    : Propagator(home,share,p) {
    x0.update(home,share,p.x0);
    x1.update(home,share,p.x1);
    iv.update(home,share,p.iv);
  }

  template<class View, class View0, class View1>
  PropCost
  ElementUnion<View,View0,View1>::cost(const Space&,
                                       const ModEventDelta&) const {
    return PropCost::linear(PropCost::HI, iv.size()+2);
  }

  template<class View, class View0, class View1>
  void
  ElementUnion<View,View0,View1>::reschedule(Space& home) {
    x0.reschedule(home,*this, PC_SET_ANY);
    x1.reschedule(home,*this, PC_SET_ANY);
    iv.reschedule(home,*this, PC_SET_ANY);
  }

  template<class View, class View0, class View1>
  forceinline size_t
  ElementUnion<View,View0,View1>::dispose(Space& home) {
    home.ignore(*this,AP_DISPOSE);
    if (!home.failed()) {
      x0.cancel(home,*this,PC_SET_ANY);
      x1.cancel(home,*this,PC_SET_ANY);
      iv.cancel(home,*this,PC_SET_ANY);
    }
    (void) Propagator::dispose(home);
    return sizeof(*this);
  }

  template<class View, class View0, class View1>
  ExecStatus
  ElementUnion<View,View0,View1>::
  post(Home home, IdxViewArray& xs, View0 x0, View1 x1) {
    int n = xs.size();

    // x0 \subseteq {1,...,n}
    Iter::Ranges::Singleton s(0, n-1);
    GECODE_ME_CHECK(x0.intersectI(home,s));
    (void) new (home)
      ElementUnion<View,View0,View1>(home,xs,x0,x1);
    return ES_OK;
  }

  template<class View, class View0, class View1>
  Actor*
  ElementUnion<View,View0,View1>::copy(Space& home, bool share) {
    return new (home) ElementUnion<View,View0,View1>(home,share,*this);
  }

  template<class View, class View0, class View1>
  ExecStatus
  ElementUnion<View,View0,View1>::propagate(Space& home, const ModEventDelta&) {
    Region r(home);
    int n = iv.size();

    bool loopVar;
    do {
      loopVar = false;

      // Cache the upper bound iterator, as we have to
      // modify the upper bound while iterating
      LubRanges<View0> x0ub(x0);
      Iter::Ranges::Cache x0ubc(r,x0ub);
      Iter::Ranges::ToValues<Iter::Ranges::Cache> vx0ub(x0ubc);

      GlbRanges<View0> x0lb(x0);
      Iter::Ranges::Cache x0lbc(r,x0lb);
      Iter::Ranges::ToValues<Iter::Ranges::Cache> vx0(x0lbc);

      // In the first iteration, compute in before[i] the union
      // of all the upper bounds of the x_i. At the same time,
      // exclude inconsistent x_i from x0 and remove them from
      // the list, cancel their dependencies.

      GLBndSet sofarBefore(home);
      LUBndSet selectedInter(home, IntSet (Limits::min,
                                   Limits::max));
      GLBndSet* before =
        static_cast<GLBndSet*>(r.ralloc(sizeof(GLBndSet)*n));

      int j = 0;
      int i = 0;

      unsigned int maxCard = 0;
      unsigned int minCard = Limits::card;

      while ( vx0ub() ) {

        // Remove vars at indices not in the upper bound
        if (iv[i].idx < vx0ub.val()) {
          iv[i].view.cancel(home,*this, PC_SET_ANY);
          ++i;
          continue;
        }
        assert(iv[i].idx == vx0ub.val());
        iv[j] = iv[i];

        View candidate = iv[j].view;
        int candidateInd = iv[j].idx;

        // inter = glb(candidate) & complement(lub(x1))
        GlbRanges<View> candlb(candidate);
        LubRanges<View1> x1ub(x1);
        Iter::Ranges::Diff<GlbRanges<View>, LubRanges<View1> >
          diff(candlb, x1ub);

        bool selectSingleInconsistent = false;
        if (x0.cardMax() <= 1) {
          GlbRanges<View1> x1lb(x1);
          LubRanges<View> candub(candidate);
          Iter::Ranges::Diff<GlbRanges<View1>,
                             LubRanges<View> > diff2(x1lb, candub);
          selectSingleInconsistent =
            diff2() || candidate.cardMax() < x1.cardMin();
        }

        // exclude inconsistent x_i
        // an x_i is inconsistent if
        //  * at most one x_i can be selected and there are
        //    elements in x_0 that can't be in x_i
        //    (selectSingleInconsistent)
        //  * its min cardinality is greater than maxCard of x1
        //  * inter is not empty (there are elements in x_i
        //    that can't be in x_0)
        if (selectSingleInconsistent ||
            candidate.cardMin() > x1.cardMax() ||
            diff()) {
          ModEvent me = (x0.exclude(home,candidateInd));
          loopVar |= me_modified(me);
          GECODE_ME_CHECK(me);

          iv[j].view.cancel(home,*this, PC_SET_ANY);
          ++i;
          ++vx0ub;
          continue;
        } else {
          // if x_i is consistent, check whether we know
          // that its index is in x0
          if (vx0() && vx0.val()==candidateInd) {
            // x1 >= candidate, candidate <= x1
            GlbRanges<View> candlb(candidate);
            ModEvent me = x1.includeI(home,candlb);
            loopVar |= me_modified(me);
            GECODE_ME_CHECK(me);

            LubRanges<View1> x1ub(x1);
            me = candidate.intersectI(home,x1ub);
            loopVar |= me_modified(me);
            GECODE_ME_CHECK(me);
            ++vx0;
          }
          new (&before[j]) GLBndSet(home);
          before[j].update(home,sofarBefore);
          LubRanges<View> cub(candidate);
          sofarBefore.includeI(home,cub);
          GlbRanges<View> clb(candidate);
          selectedInter.intersectI(home,clb);
          maxCard = std::max(maxCard, candidate.cardMax());
          minCard = std::min(minCard, candidate.cardMin());
        }

        ++vx0ub;
        ++i; ++j;
      }

      // cancel the variables with index greater than
      // max of lub(x0)
      for (int k=i; k<n; k++) {
        iv[k].view.cancel(home,*this, PC_SET_ANY);
      }
      n = j;
      iv.size(n);

      if (x0.cardMax()==0) {
        // Selector is empty, hence the result must be empty
        {
          GECODE_ME_CHECK(x1.cardMax(home,0));
        }
        for (int i=n; i--;)
          before[i].dispose(home);
        return home.ES_SUBSUMED(*this);
      }

      if (x0.cardMin() > 0) {
        // Selector is not empty, hence the intersection of the
        // possibly selected lower bounds is contained in x1
        BndSetRanges si(selectedInter);
        ModEvent me = x1.includeI(home, si);
        loopVar |= me_modified(me);
        GECODE_ME_CHECK(me);
        me = x1.cardMin(home, minCard);
        loopVar |= me_modified(me);
        GECODE_ME_CHECK(me);
      }
      selectedInter.dispose(home);

      if (x0.cardMax() <= 1) {
        ModEvent me = x1.cardMax(home, maxCard);
        loopVar |= me_modified(me);
        GECODE_ME_CHECK(me);
      }

      {
        // x1 <= sofarBefore
        BndSetRanges sfB(sofarBefore);
        ModEvent me = x1.intersectI(home,sfB);
        loopVar |= me_modified(me);
        GECODE_ME_CHECK(me);
      }

      sofarBefore.dispose(home);

      GLBndSet sofarAfter(home);

      // In the second iteration, this time backwards, compute
      // sofarAfter as the union of all lub(x_j) with j>i
      for (int i=n; i--;) {
        // TODO: check for size of universe here?
        // if (sofarAfter.size() == 0) break;

        // extra = inter(before[i], sofarAfter) - lub(x1)
        BndSetRanges b(before[i]);
        BndSetRanges s(sofarAfter);
        GlbRanges<View1> x1lb(x1);
        Iter::Ranges::Union<BndSetRanges, BndSetRanges> inter(b,s);
        Iter::Ranges::Diff<GlbRanges<View1>,
          Iter::Ranges::Union<BndSetRanges,BndSetRanges> > diff(x1lb, inter);
        if (diff()) {
          ModEvent me = (x0.include(home,iv[i].idx));
          loopVar |= me_modified(me);
          GECODE_ME_CHECK(me);

          // candidate != extra
          me = iv[i].view.includeI(home,diff);
          loopVar |= me_modified(me);
          GECODE_ME_CHECK(me);
        }

        LubRanges<View> iviub(iv[i].view);
        sofarAfter.includeI(home,iviub);
        before[i].dispose(home);
      }
      sofarAfter.dispose(home);

    } while (loopVar);

    // Test whether we determined x0 without determining x1
    if (x0.assigned() && !x1.assigned()) {
      int ubsize = static_cast<int>(x0.lubSize());
      if (ubsize > 2) {
        assert(ubsize==n);
        ViewArray<View> is(home,ubsize);
        for (int i=n; i--;)
          is[i]=iv[i].view;
        GECODE_REWRITE(*this,(RelOp::UnionN<View, View1>
                        ::post(home(*this),is,x1)));
      } else if (ubsize == 2) {
        assert(n==2);
        View a = iv[0].view;
        View b = iv[1].view;
        GECODE_REWRITE(*this,(RelOp::Union<View,View,View1>
                       ::post(home(*this),a,b,x1)));
      } else if (ubsize == 1) {
        assert(n==1);
        GECODE_REWRITE(*this,
          (Rel::Eq<View1,View>::post(home(*this),x1,iv[0].view)));
      } else {
        GECODE_ME_CHECK(x1.cardMax(home, 0));
        return home.ES_SUBSUMED(*this);
      }
    }

    bool allAssigned = true;
    for (int i=iv.size(); i--;) {
      if (!iv[i].view.assigned()) {
        allAssigned = false;
        break;
      }
    }
    if (x1.assigned() && x0.assigned() && allAssigned) {
      return home.ES_SUBSUMED(*this);
    }

    return ES_FIX;
  }

}}}

// STATISTICS: set-prop