This file is indexed.

/usr/include/gecode/int/rel/lex.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
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
 *  Main authors:
 *     Christian Schulte <schulte@gecode.org>
 *
 *  Copyright:
 *     Christian Schulte, 2003
 *
 *  Last modified:
 *     $Date: 2016-11-08 17:23:24 +0100 (Tue, 08 Nov 2016) $ by $Author: schulte $
 *     $Revision: 15253 $
 *
 *  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 { namespace Rel {

  /*
   * Lexical order propagator
   */
  template<class VX, class VY>
  inline
  LexLqLe<VX,VY>::LexLqLe(Home home,
                          ViewArray<VX>& x0, ViewArray<VY>& y0, bool s)
    : Propagator(home), x(x0), y(y0), strict(s) {
    x.subscribe(home, *this, PC_INT_BND);
    y.subscribe(home, *this, PC_INT_BND);
  }

  template<class VX, class VY>
  forceinline
  LexLqLe<VX,VY>::LexLqLe(Space& home, bool share, LexLqLe<VX,VY>& p)
    : Propagator(home,share,p), strict(p.strict) {
    x.update(home,share,p.x);
    y.update(home,share,p.y);
  }

  template<class VX, class VY>
  Actor*
  LexLqLe<VX,VY>::copy(Space& home, bool share) {
    return new (home) LexLqLe<VX,VY>(home,share,*this);
  }

  template<class VX, class VY>
  PropCost
  LexLqLe<VX,VY>::cost(const Space&, const ModEventDelta&) const {
    return PropCost::linear(PropCost::LO, x.size());
  }

  template<class VX, class VY>
  void
  LexLqLe<VX,VY>::reschedule(Space& home) {
    x.reschedule(home,*this,PC_INT_BND);
    y.reschedule(home,*this,PC_INT_BND);
  }

  template<class VX, class VY>
  forceinline size_t
  LexLqLe<VX,VY>::dispose(Space& home) {
    assert(!home.failed());
    x.cancel(home,*this,PC_INT_BND);
    y.cancel(home,*this,PC_INT_BND);
    (void) Propagator::dispose(home);
    return sizeof(*this);
  }

  template<class VX, class VY>
  ExecStatus
  LexLqLe<VX,VY>::propagate(Space& home, const ModEventDelta&) {
    /*
     * State 1
     *
     */
    {
      int i = 0;
      int n = x.size();

      while ((i < n) && (x[i].min() == y[i].max())) {
        // case: =, >=
        GECODE_ME_CHECK(x[i].lq(home,y[i].max()));
        GECODE_ME_CHECK(y[i].gq(home,x[i].min()));
        i++;
      }

      if (i == n) // case: $
        return strict ? ES_FAILED : home.ES_SUBSUMED(*this);

      // Possible cases left: <, <=, > (yields failure), ?
      GECODE_ME_CHECK(x[i].lq(home,y[i].max()));
      GECODE_ME_CHECK(y[i].gq(home,x[i].min()));

      if (x[i].max() < y[i].min()) // case: < (after tell)
        return home.ES_SUBSUMED(*this);

      // x[i] can never be equal to y[i] (otherwise: >=)
      assert(!(x[i].assigned() && y[i].assigned() &&
               x[i].val() == y[i].val()));
      // Remove all elements between 0...i-1 as they are assigned and equal
      x.drop_fst(i); y.drop_fst(i);
      // After this, execution continues at [1]
    }

    /*
     * State 2
     *   prefix: (?|<=)
     *
     */
    {
      int i = 1;
      int n = x.size();

      while ((i < n) &&
             (x[i].min() == y[i].max()) &&
             (x[i].max() == y[i].min())) { // case: =
        assert(x[i].assigned() && y[i].assigned() &&
               (x[i].val() == y[i].val()));
        i++;
      }

      if (i == n) { // case: $
        if (strict)
          goto rewrite_le;
        else
          goto rewrite_lq;
      }

      if (x[i].max() < y[i].min()) // case: <
        goto rewrite_lq;

      if (x[i].min() > y[i].max()) // case: >
        goto rewrite_le;

      if (i > 1) {
        // Remove equal elements [1...i-1], keep element [0]
        x[i-1]=x[0]; x.drop_fst(i-1);
        y[i-1]=y[0]; y.drop_fst(i-1);
      }
    }

    if (x[1].max() <= y[1].min()) {
      // case: <= (invariant: not =, <)
      /*
       * State 3
       *   prefix: (?|<=),<=
       *
       */
      int i = 2;
      int n = x.size();

      while ((i < n) && (x[i].max() == y[i].min())) // case: <=, =
        i++;

      if (i == n) { // case: $
        if (strict)
          return ES_FIX;
        else
          goto rewrite_lq;
      }

      if (x[i].max() < y[i].min()) // case: <
        goto rewrite_lq;

      if (x[i].min() > y[i].max()) { // case: >
        // Eliminate [i]...[n-1]
        for (int j=i; j<n; j++) {
          x[j].cancel(home,*this,PC_INT_BND);
          y[j].cancel(home,*this,PC_INT_BND);
        }
        x.size(i); y.size(i);
        strict = true;
      }

      return ES_FIX;
    }

    if (x[1].min() >= y[1].max()) {
      // case: >= (invariant: not =, >)
      /*
       * State 4
       *   prefix: (?|<=) >=
       *
       */
      int i = 2;
      int n = x.size();

      while ((i < n) && (x[i].min() == y[i].max()))
        // case: >=, =
        i++;

      if (i == n) { // case: $
        if (strict)
          goto rewrite_le;
        else
          return ES_FIX;
      }

      if (x[i].min() > y[i].max()) // case: >
        goto rewrite_le;

      if (x[i].max() < y[i].min()) { // case: <
        // Eliminate [i]...[n-1]
        for (int j=i; j<n; j++) {
          x[j].cancel(home,*this,PC_INT_BND);
          y[j].cancel(home,*this,PC_INT_BND);
        }
        x.size(i); y.size(i);
        strict = false;
      }

      return ES_FIX;
    }

    return ES_FIX;

  rewrite_le:
    GECODE_REWRITE(*this,(Le<VX,VY>::post(home(*this),x[0],y[0])));
  rewrite_lq:
    GECODE_REWRITE(*this,(Lq<VX,VY>::post(home(*this),x[0],y[0])));
  }

  template<class VX, class VY>
  ExecStatus
  LexLqLe<VX,VY>::post(Home home,
                      ViewArray<VX>& x, ViewArray<VY>& y, bool strict) {
    if (x.size() < y.size()) {
      y.size(x.size()); strict=false;
    } else if (x.size() > y.size()) {
      x.size(y.size()); strict=true;
    }
    if (x.size() == 0)
      return strict ? ES_FAILED : ES_OK;
    if (x.size() == 1) {
      if (strict)
        return Le<VX,VY>::post(home,x[0],y[0]);
      else
        return Lq<VX,VY>::post(home,x[0],y[0]);
    }
    (void) new (home) LexLqLe<VX,VY>(home,x,y,strict);
    return ES_OK;
  }


  /*
   * Lexical disequality propagator
   */
  template<class VX, class VY>
  forceinline
  LexNq<VX,VY>::LexNq(Home home, ViewArray<VX>& xv, ViewArray<VY>& yv)
    : Propagator(home),
      x0(xv[xv.size()-2]), y0(yv[xv.size()-2]),
      x1(xv[xv.size()-1]), y1(yv[xv.size()-1]),
      x(xv), y(yv) {
    int n = x.size();
    assert(n > 1);
    assert(n == y.size());
    x.size(n-2); y.size(n-2);
    x0.subscribe(home,*this,PC_INT_VAL); y0.subscribe(home,*this,PC_INT_VAL);
    x1.subscribe(home,*this,PC_INT_VAL); y1.subscribe(home,*this,PC_INT_VAL);
  }

  template<class VX, class VY>
  PropCost
  LexNq<VX,VY>::cost(const Space&, const ModEventDelta&) const {
    return PropCost::binary(PropCost::HI);
  }

  template<class VX, class VY>
  void
  LexNq<VX,VY>::reschedule(Space& home) {
    x0.reschedule(home,*this,PC_INT_VAL);
    y0.reschedule(home,*this,PC_INT_VAL);
    x1.reschedule(home,*this,PC_INT_VAL);
    y1.reschedule(home,*this,PC_INT_VAL);
  }

  template<class VX, class VY>
  forceinline
  LexNq<VX,VY>::LexNq(Space& home, bool share, LexNq<VX,VY>& p)
    : Propagator(home,share,p) {
    x0.update(home,share,p.x0); y0.update(home,share,p.y0);
    x1.update(home,share,p.x1); y1.update(home,share,p.y1);
    x.update(home,share,p.x); y.update(home,share,p.y);
  }

  template<class VX, class VY>
  Actor*
  LexNq<VX,VY>::copy(Space& home, bool share) {
    int n = x.size();
    if (n > 0) {
      // Eliminate all equal views and keep one disequal pair
      for (int i=n; i--; )
        switch (rtest_eq_bnd(x[i],y[i])) {
        case RT_TRUE:
          // Eliminate equal pair
          n--; x[i]=x[n]; y[i]=y[n];
          break;
        case RT_FALSE:
          // Just keep a single disequal pair
          n=1; x[0]=x[i]; y[0]=y[i];
          goto done;
        case RT_MAYBE:
          break;
        default:
          GECODE_NEVER;
        }
    done:
      x.size(n); y.size(n);
    }
    return new (home) LexNq<VX,VY>(home,share,*this);
  }

  template<class VX, class VY>
  inline ExecStatus
  LexNq<VX,VY>::post(Home home, ViewArray<VX>& x, ViewArray<VY>& y) {
    if (x.size() != y.size())
      return ES_OK;
    int n = x.size();
    if (n > 0) {
      // Eliminate all equal views
      for (int i=n; i--; )
        switch (rtest_eq_dom(x[i],y[i])) {
        case RT_TRUE:
          // Eliminate equal pair
          n--; x[i]=x[n]; y[i]=y[n];
          break;
        case RT_FALSE:
          return ES_OK;
        case RT_MAYBE:
          if (same(x[i],y[i])) {
            // Eliminate equal pair
            n--; x[i]=x[n]; y[i]=y[n];
          }
          break;
        default:
          GECODE_NEVER;
        }
      x.size(n); y.size(n);
    }
    if (n == 0)
      return ES_FAILED;
    if (n == 1)
      return Nq<VX,VY>::post(home,x[0],y[0]);
    (void) new (home) LexNq<VX,VY>(home,x,y);
    return ES_OK;
  }

  template<class VX, class VY>
  forceinline size_t
  LexNq<VX,VY>::dispose(Space& home) {
    x0.cancel(home,*this,PC_INT_VAL); y0.cancel(home,*this,PC_INT_VAL);
    x1.cancel(home,*this,PC_INT_VAL); y1.cancel(home,*this,PC_INT_VAL);
    (void) Propagator::dispose(home);
    return sizeof(*this);
  }

  template<class VX, class VY>
  forceinline ExecStatus
  LexNq<VX,VY>::resubscribe(Space& home,
                            RelTest rt, VX& x0, VY& y0, VX x1, VY y1) {
    if (rt == RT_TRUE) {
      assert(x0.assigned() && y0.assigned());
      assert(x0.val() == y0.val());
      int n = x.size();
      for (int i=n; i--; )
        switch (rtest_eq_dom(x[i],y[i])) {
        case RT_TRUE:
          // Eliminate equal pair
          n--; x[i]=x[n]; y[i]=y[n];
          break;
        case RT_FALSE:
          return home.ES_SUBSUMED(*this);
        case RT_MAYBE:
          // Move to x0, y0 and subscribe
          x0=x[i]; y0=y[i];
          n--; x[i]=x[n]; y[i]=y[n];
          x.size(n); y.size(n);
          x0.subscribe(home,*this,PC_INT_VAL,false);
          y0.subscribe(home,*this,PC_INT_VAL,false);
          return ES_FIX;
        default:
          GECODE_NEVER;
        }
      // No more views to subscribe to left
      GECODE_REWRITE(*this,(Nq<VX,VY>::post(home(*this),x1,y1)));
    }
    return ES_FIX;
  }

  template<class VX, class VY>
  ExecStatus
  LexNq<VX,VY>::propagate(Space& home, const ModEventDelta&) {
    RelTest rt0 = rtest_eq_dom(x0,y0);
    if (rt0 == RT_FALSE)
      return home.ES_SUBSUMED(*this);
    RelTest rt1 = rtest_eq_dom(x1,y1);
    if (rt1 == RT_FALSE)
      return home.ES_SUBSUMED(*this);
    GECODE_ES_CHECK(resubscribe(home,rt0,x0,y0,x1,y1));
    GECODE_ES_CHECK(resubscribe(home,rt1,x1,y1,x0,y0));
    return ES_FIX;
  }


}}}

// STATISTICS: int-prop