This file is indexed.

/usr/include/gecode/int/linear/int-dom.hpp is in libgecode-dev 4.2.1-1.

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
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
 *  Main authors:
 *     Christian Schulte <schulte@gecode.org>
 *
 *  Copyright:
 *     Christian Schulte, 2006
 *
 *  Last modified:
 *     $Date: 2012-09-07 17:31:22 +0200 (Fri, 07 Sep 2012) $ by $Author: schulte $
 *     $Revision: 13068 $
 *
 *  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 Linear {

  /**
   * \brief %Set for support information
   *
   * Records supported positions of values such that with iteration
   * the supported values can be reconstructed.
   *
   */
  class SupportSet {
  private:
    /// Bitset for storing support information
    Support::BitSetBase bs;
  public:
    /// Default constructor
    SupportSet(void);
    /// Initialize support set with cardinality \a n
    void init(Region& r, unsigned int n);
    /// Record that there is support at position \a i
    void support(unsigned int i);
    /// Check whether position \arg i has support
    bool supported(unsigned int i) const;

  private:
    /// Support-based iterator: iterates values to be removed
    class ResultIter : public ViewValues<IntView> {
    protected:
      /// The support set used
      const SupportSet& s;
      /// The current position of the value
      unsigned int p;
    public:
      /// Initialize iterator
      ResultIter(const SupportSet& s0, const IntView& x);
      /// Increment to next supported value
      void operator ++(void);
    };

  public:
    /// Perform tell according to recorded support information on \arg x
    ModEvent tell(Space& home, IntView& x) const;
  };

  /**
   * \brief Base-class for support-based iterator
   *
   */
  template<class Val>
  class SupportIter {
  protected:
    /// Integer coefficient for view
    int           a;
    /// Integer view
    IntView       x;
    /// Set of support for values in x
    SupportSet    s;
    /// Current value
    int           c;
    /// Position of current value
    unsigned int  p;
    /// Lower bound information for value
    Val           l;
    /// Upper bound information for value
    Val           u;
  public:
    /// Initialize view
    void init(Region& r, int a, const IntView& x, Val l, Val u);
    /// Record value at current position as supported
    void support(void);
    /// Tell back new variable domain according to support found
    ModEvent tell(Space& home);
  };


  /**
   * \brief Support-based iterator for positive view
   *
   */
  template<class Val>
  class PosSupportIter : public SupportIter<Val> {
  private:
    /// Iterate ranges of integer view in increasing order
    IntVarImpFwd i;
    // Using-declarations for dependant names
    using SupportIter<Val>::a;
    using SupportIter<Val>::x;
    using SupportIter<Val>::s;
    using SupportIter<Val>::c;
    using SupportIter<Val>::p;
    using SupportIter<Val>::l;
    using SupportIter<Val>::u;
  public:
    /// Reset iterator to beginning and adjust \arg d accordingly
    bool reset(Val& d);
    /// Adjust \arg d and return true if next value still works
    bool adjust(Val& d);
  };


  /**
   * \brief Support-based iterator for negative view
   *
   */
  template<class Val>
  class NegSupportIter : public SupportIter<Val> {
  private:
    /// Iterate ranges of integer view in decreasing order
    IntVarImpBwd i;
    // Using-declarations for dependant names
    using SupportIter<Val>::a;
    using SupportIter<Val>::x;
    using SupportIter<Val>::s;
    using SupportIter<Val>::c;
    using SupportIter<Val>::p;
    using SupportIter<Val>::l;
    using SupportIter<Val>::u;
  public:
    /// Reset iterator to beginning and adjust \arg d accordingly
    bool reset(Val& d);
    /// Adjust \arg d and return true if next value still works
    bool adjust(Val& d);
  };


  /*
   * Support set
   *
   */
  forceinline
  SupportSet::SupportSet(void) {}
  forceinline void
  SupportSet::init(Region& r, unsigned int n) {
    bs.init(r,n);
  }
  forceinline void
  SupportSet::support(unsigned int i) {
    bs.set(i);
  }
  forceinline bool
  SupportSet::supported(unsigned int i) const {
    return bs.get(i);
  }

  forceinline
  SupportSet::ResultIter::ResultIter(const SupportSet& s0, const IntView& x)
    : ViewValues<IntView>(x), s(s0), p(0) {
    while (ViewValues<IntView>::operator ()() && s.supported(p)) {
      ViewValues<IntView>::operator ++(); ++p;
    }
  }
  forceinline void
  SupportSet::ResultIter::operator ++(void) {
    do {
      ViewValues<IntView>::operator ++(); ++p;
    } while (ViewValues<IntView>::operator ()() && s.supported(p));
  }


  forceinline ModEvent
  SupportSet::tell(Space& home, IntView& x) const {
    switch (bs.status()) {
    case Support::BSS_NONE:
      return ME_INT_FAILED;
    case Support::BSS_ALL:
      return ME_INT_NONE;
    case Support::BSS_SOME:
      {
        ResultIter i(*this,x);
        return x.minus_v(home,i);
      }
    default:
      GECODE_NEVER;
    }
    return ME_INT_NONE;
  }


  /*
   * Base-class for support-based iterator
   *
   */
  template<class Val>
  forceinline void
  SupportIter<Val>::init(Region& r,
                         int a0, const IntView& x0, Val l0, Val u0) {
    a=a0; x=x0; l=l0; u=u0;
    s.init(r,x.size());
  }
  template<class Val>
  forceinline void
  SupportIter<Val>::support(void) {
    s.support(p);
  }
  template<class Val>
  forceinline ModEvent
  SupportIter<Val>::tell(Space& home) {
    return s.tell(home,x);
  }


  /*
   * Support-based iterator for positive view
   *
   */
  template<class Val>
  forceinline bool
  PosSupportIter<Val>::reset(Val& d) {
    // Way too small, no value can make it big enough
    if (d + static_cast<Val>(a)*x.max() < u)
      return false;
    // Restart iterator and position of values
    i.init(x.varimp()); p = 0;
    // Skip all ranges which are too small
    while (d + static_cast<Val>(a)*i.max() < u) {
      p += i.width(); ++i;
    }
    // There is at least one range left (check of max)
    assert(i());
    // Initialize current range and adjust value
    c = i.min();
    // Skip all values which are too small
    while (d + static_cast<Val>(a)*c < u) {
      p++; c++;
    }
    // Adjust to new value
    d += static_cast<Val>(a) * c;
    return true;
  }
  template<class Val>
  forceinline bool
  PosSupportIter<Val>::adjust(Val& d) {
    // Current value
    Val v = static_cast<Val>(a) * c;
    // Subtract current value from d
    d -= v;
    // Move to next position (number of value)
    p++;
    // Still in the same range
    if (c < i.max()) {
      // Decrement current values
      c += 1; v += a;
    } else {
      // Go to next range
      ++i;
      if (!i())
        return false;
      c = i.min(); v = static_cast<Val>(a) * c;
    }
    // Is d with the current value too large?
    if (d + v > l)
      return false;
    // Update d
    d += v;
    return true;
  }


  /*
   * Support-based iterator for negative view
   *
   */
  template<class Val>
  forceinline bool
  NegSupportIter<Val>::reset(Val& d) {
    // Way too small, no value can make it big enough
    if (d + static_cast<Val>(a)*x.min() < u)
      return false;
    // Restart iterator and position of values
    i.init(x.varimp()); p = x.size()-1;
    // Skip all ranges which are too small
    while (d + static_cast<Val>(a)*i.min() < u) {
      p -= i.width(); ++i;
    }
    // There is at least one range left (check of max)
    assert(i());
    // Initialize current range
    c = i.max();
    // Skip all values which are too small
    while (d + static_cast<Val>(a)*c < u) {
      p--; c--;
    }
    // Adjust to new value
    d += static_cast<Val>(a) * c;
    return true;
  }
  template<class Val>
  forceinline bool
  NegSupportIter<Val>::adjust(Val& d) {
    // Current value
    Val v = static_cast<Val>(a) * c;
    // Subtract current value from d
    d -= v;
    // Move to next position (number of value)
    p--;
    // Still in the same range
    if (c > i.min()) {
      // Decrement current values
      c -= 1; v -= a;
    } else {
      // Go to next range
      ++i;
      if (!i())
        return false;
      c = i.max(); v = static_cast<Val>(a) * c;
    }
    // Is d with the current value too large?
    if (d + v > l)
      return false;
    // Update d
    d += v;
    return true;
  }



  /*
   * The domain consisten equality propagator
   *
   */
  template<class Val, class View>
  forceinline
  DomEq<Val,View>::DomEq(Home home,
                         ViewArray<View >& x, ViewArray<View >& y,
                         Val c)
    : Lin<Val,View,View,PC_INT_DOM>(home,x,y,c) {}

  template<class Val, class View>
  ExecStatus
  DomEq<Val,View>::post(Home home,
                        ViewArray<View>& x, ViewArray<View>& y,
                        Val c) {
    (void) new (home) DomEq<Val,View>(home,x,y,c);
    return ES_OK;
  }

  template<class Val, class View>
  forceinline
  DomEq<Val,View>::DomEq(Space& home, bool share, DomEq<Val,View>& p)
    : Lin<Val,View,View,PC_INT_DOM>(home,share,p) {}

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

  template<class Val, class View>
  PropCost
  DomEq<Val,View>::cost(const Space&, const ModEventDelta& med) const {
    if (View::me(med) != ME_INT_DOM)
      return PropCost::linear(PropCost::LO, x.size()+y.size());
    else
      return PropCost::crazy(PropCost::HI, x.size()+y.size());
  }

  template<class Val, class View>
  ExecStatus
  DomEq<Val,View>::propagate(Space& home, const ModEventDelta& med) {
    if (View::me(med) != ME_INT_DOM) {
      ExecStatus es = prop_bnd<Val,View,View>(home,med,*this,x,y,c);
      GECODE_ES_CHECK(es);
      return home.ES_FIX_PARTIAL(*this,View::med(ME_INT_DOM));
    }

    // Value of equation for partial assignment
    Val d = -c;

    int n = x.size();
    int m = y.size();

    Region r(home);
    // Create support-base iterators
    PosSupportIter<Val>* xp = r.alloc<PosSupportIter<Val> >(n);
    NegSupportIter<Val>* yp = r.alloc<NegSupportIter<Val> >(m);

    // Initialize views for assignments
    {
      Val l = 0;
      Val u = 0;
      for (int j=m; j--; ) {
        yp[j].init(r,-y[j].scale(),y[j].base(),l,u);
        l += y[j].max(); u += y[j].min();
      }
      for (int i=n; i--; ) {
        xp[i].init(r,x[i].scale(),x[i].base(),l,u);
        l -= x[i].min(); u -= x[i].max();
      }
    }

    // Collect support information by iterating assignments
    {
      // Force reset of all iterators in first round
      int i = 0;
      int j = 0;

    next_i:
      // Reset all iterators for positive views and update d
      while (i<n) {
        if (!xp[i].reset(d)) goto prev_i;
        i++;
      }
    next_j:
      // Reset all iterators for negative views and update d
      while (j<m) {
        if (!yp[j].reset(d)) goto prev_j;
        j++;
      }
      // Check whether current assignment is solution
      if (d == 0) {
        // Record support
        for (int is=n; is--; ) xp[is].support();
        for (int js=m; js--; ) yp[js].support();
      }
    prev_j:
      // Try iterating to next assignment: negative views
      while (j>0) {
        if (yp[j-1].adjust(d)) goto next_j;
        j--;
      }
    prev_i:
      // Try iterating to next assignment: positive views
      while (i>0) {
        if (xp[i-1].adjust(d)) goto next_i;
        i--;
      }
    }

    // Tell back new variable domains
    bool assigned = true;
    for (int i=n; i--; ) {
      GECODE_ME_CHECK(xp[i].tell(home));
      if (!x[i].assigned())
        assigned = false;
    }
    for (int j=m; j--; ) {
      GECODE_ME_CHECK(yp[j].tell(home));
      if (!y[j].assigned())
        assigned = false;
    }
    if (assigned)
      return home.ES_SUBSUMED(*this);
    return ES_FIX;
  }

}}}

// STATISTICS: int-prop