Generated on Thu Mar 16 2017 03:24:16 for Gecode by doxygen 1.8.13
var-imp.hpp
Go to the documentation of this file.
1 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2 /*
3  * Main authors:
4  * Christian Schulte <schulte@gecode.org>
5  *
6  * Contributing authors:
7  * Guido Tack <tack@gecode.org>
8  *
9  * Copyright:
10  * Christian Schulte, 2002
11  * Guido Tack, 2004
12  *
13  * Last modified:
14  * $Date: 2016-06-29 17:28:17 +0200 (Wed, 29 Jun 2016) $ by $Author: schulte $
15  * $Revision: 15137 $
16  *
17  * This file is part of Gecode, the generic constraint
18  * development environment:
19  * http://www.gecode.org
20  *
21  * Permission is hereby granted, free of charge, to any person obtaining
22  * a copy of this software and associated documentation files (the
23  * "Software"), to deal in the Software without restriction, including
24  * without limitation the rights to use, copy, modify, merge, publish,
25  * distribute, sublicense, and/or sell copies of the Software, and to
26  * permit persons to whom the Software is furnished to do so, subject to
27  * the following conditions:
28  *
29  * The above copyright notice and this permission notice shall be
30  * included in all copies or substantial portions of the Software.
31  *
32  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
33  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
34  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
35  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
36  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
37  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
38  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
39  *
40  */
41 
42 #include <cmath>
43 
44 namespace Gecode { namespace Int {
45 
46  class IntVarImp;
47  class BoolVarImp;
48 
55  class IntDelta : public Delta {
56  friend class IntVarImp;
57  friend class BoolVarImp;
58  private:
59  int _min;
60  int _max;
61  public:
63  IntDelta(void);
65  IntDelta(int min, int max);
67  IntDelta(int min);
68  private:
70  int min(void) const;
72  int max(void) const;
74  bool any(void) const;
75  };
76 
77 }}
78 
80 
81 namespace Gecode { namespace Int {
82 
83  class IntVarImpFwd;
84  class IntVarImpBwd;
85 
91  class IntVarImp : public IntVarImpBase {
92  friend class IntVarImpFwd;
93  friend class IntVarImpBwd;
94  protected:
104  class RangeList : public FreeList {
105  protected:
107  int _min;
109  int _max;
110  public:
112 
113  RangeList(void);
116  RangeList(int min, int max);
118  RangeList(int min, int max, RangeList* p, RangeList* n);
120 
122 
123  int min(void) const;
126  int max(void) const;
128  unsigned int width(void) const;
129 
131  RangeList* next(const RangeList* p) const;
133  RangeList* prev(const RangeList* n) const;
135 
137 
138  void min(int n);
141  void max(int n);
142 
144  void prevnext(RangeList* p, RangeList* n);
146  void next(RangeList* o, RangeList* n);
148  void prev(RangeList* o, RangeList* n);
150  void fix(RangeList* n);
152 
154 
155 
160  void dispose(Space& home, RangeList* p, RangeList* l);
166  void dispose(Space& home, RangeList* l);
168  void dispose(Space& home);
169 
171  static void* operator new(size_t s, Space& home);
173  static void* operator new(size_t s, void* p);
175  static void operator delete(void*);
177  static void operator delete(void*, Space&);
179  static void operator delete(void*, void*);
181  };
182 
194  RangeList* fst(void) const;
196  void fst(RangeList* f);
198  RangeList* lst(void) const;
200  void lst(RangeList* l);
202  unsigned int holes;
203 
204  protected:
206  IntVarImp(Space& home, bool share, IntVarImp& x);
207  public:
209  IntVarImp(Space& home, int min, int max);
211  IntVarImp(Space& home, const IntSet& d);
212 
214 
215  int min(void) const;
218  int max(void) const;
220  int val(void) const;
222  GECODE_INT_EXPORT int med(void) const;
223 
225  unsigned int size(void) const;
227  unsigned int width(void) const;
229  unsigned int regret_min(void) const;
231  unsigned int regret_max(void) const;
233 
234  private:
236  GECODE_INT_EXPORT bool in_full(int n) const;
237 
238  public:
240 
241  bool range(void) const;
244  bool assigned(void) const;
245 
247  bool in(int n) const;
249  bool in(long long int n) const;
251 
252  protected:
254 
255  const RangeList* ranges_fwd(void) const;
258  const RangeList* ranges_bwd(void) const;
260 
261  private:
263  bool closer_min(int b) const;
265 
266  GECODE_INT_EXPORT ModEvent lq_full(Space& home, int n);
269  GECODE_INT_EXPORT ModEvent gq_full(Space& home, int n);
271  GECODE_INT_EXPORT ModEvent eq_full(Space& home, int n);
273  GECODE_INT_EXPORT ModEvent nq_full(Space& home, int n);
275  public:
277 
278  ModEvent lq(Space& home, int n);
281  ModEvent lq(Space& home, long long int n);
282 
284  ModEvent gq(Space& home, int n);
286  ModEvent gq(Space& home, long long int n);
287 
289  ModEvent nq(Space& home, int n);
291  ModEvent nq(Space& home, long long int n);
292 
294  ModEvent eq(Space& home, int n);
296  ModEvent eq(Space& home, long long int n);
298 
315  template<class I>
317  ModEvent narrow_r(Space& home, I& i, bool depends=true);
319  template<class I>
320  ModEvent inter_r(Space& home, I& i, bool depends=true);
322  template<class I>
323  ModEvent minus_r(Space& home, I& i, bool depends=true);
325  template<class I>
326  ModEvent narrow_v(Space& home, I& i, bool depends=true);
328  template<class I>
329  ModEvent inter_v(Space& home, I& i, bool depends=true);
331  template<class I>
332  ModEvent minus_v(Space& home, I& i, bool depends=true);
334 
336 
337 
345  void subscribe(Space& home, Propagator& p, PropCond pc, bool schedule=true);
347  void cancel(Space& home, Propagator& p, PropCond pc);
349  void reschedule(Space& home, Propagator& p, PropCond pc);
351  void subscribe(Space& home, Advisor& a);
353  void cancel(Space& home, Advisor& a);
355 
357 
358  static ModEventDelta med(ModEvent me);
361 
362 
363  private:
365  GECODE_INT_EXPORT IntVarImp* perform_copy(Space& home, bool share);
366  public:
368 
369  IntVarImp* copy(Space& home, bool share);
372 
374 
375  static int min(const Delta& d);
378  static int max(const Delta& d);
380  static bool any(const Delta& d);
382  };
383 
384 
389  class IntVarImpFwd {
390  private:
392  const IntVarImp::RangeList* p;
394  const IntVarImp::RangeList* c;
395  public:
397 
398  IntVarImpFwd(void);
401  IntVarImpFwd(const IntVarImp* x);
403  void init(const IntVarImp* x);
405 
407 
408  bool operator ()(void) const;
411  void operator ++(void);
413 
415 
416  int min(void) const;
419  int max(void) const;
421  unsigned int width(void) const;
423  };
424 
432  class IntVarImpBwd {
433  private:
435  const IntVarImp::RangeList* n;
437  const IntVarImp::RangeList* c;
438  public:
440 
441  IntVarImpBwd(void);
444  IntVarImpBwd(const IntVarImp* x);
446  void init(const IntVarImp* x);
448 
450 
451  bool operator ()(void) const;
454  void operator ++(void);
456 
458 
459  int min(void) const;
462  int max(void) const;
464  unsigned int width(void) const;
466  };
467 
468 }}
469 
471 
472 namespace Gecode {
473 
474  class IntVar;
475  class BoolVar;
476 }
477 
478 namespace Gecode { namespace Int {
479 
481  typedef unsigned int BoolStatus;
482 
488  class BoolVarImp : public BoolVarImpBase {
489  friend class ::Gecode::BoolVar;
490  private:
502  GECODE_INT_EXPORT static BoolVarImp s_one;
503  GECODE_INT_EXPORT static BoolVarImp s_zero;
504 
506  BoolVarImp(Space& home, bool share, BoolVarImp& x);
508  BoolVarImp(int n);
509  public:
511  BoolVarImp(Space& home, int min, int max);
512 
514 
515  static const int BITS = 2;
518  static const BoolStatus ZERO = 0;
520  static const BoolStatus ONE = 3;
522  static const BoolStatus NONE = 2;
524  BoolStatus status(void) const;
526 
528 
529  int min(void) const;
532  int max(void) const;
534  int val(void) const;
536  int med(void) const;
537 
539  unsigned int size(void) const;
541  unsigned int width(void) const;
543  unsigned int regret_min(void) const;
545  unsigned int regret_max(void) const;
547 
549 
550  bool zero(void) const;
553  bool one(void) const;
555  bool none(void) const;
557 
559 
560  bool range(void) const;
563  bool assigned(void) const;
564 
566  bool in(int n) const;
568  bool in(long long int n) const;
570 
572 
573  ModEvent lq(Space& home, int n);
576  ModEvent lq(Space& home, long long int n);
577 
579  ModEvent gq(Space& home, int n);
581  ModEvent gq(Space& home, long long int n);
582 
584  ModEvent nq(Space& home, int n);
586  ModEvent nq(Space& home, long long int n);
587 
589  ModEvent eq(Space& home, int n);
591  ModEvent eq(Space& home, long long int n);
593 
610  template<class I>
612  ModEvent narrow_r(Space& home, I& i, bool depends=true);
614  template<class I>
615  ModEvent inter_r(Space& home, I& i, bool depends=true);
617  template<class I>
618  ModEvent minus_r(Space& home, I& i, bool depends=true);
620  template<class I>
621  ModEvent narrow_v(Space& home, I& i, bool depends=true);
623  template<class I>
624  ModEvent inter_v(Space& home, I& i, bool depends=true);
626  template<class I>
627  ModEvent minus_v(Space& home, I& i, bool depends=true);
629 
631 
632  ModEvent zero(Space& home);
635  ModEvent one(Space& home);
637  GECODE_INT_EXPORT ModEvent zero_none(Space& home);
639  GECODE_INT_EXPORT ModEvent one_none(Space& home);
641 
642  public:
644 
645 
655  void subscribe(Space& home, Propagator& p, PropCond pc, bool schedule=true);
662  void cancel(Space& home, Propagator& p, PropCond pc);
664  void subscribe(Space& home, Advisor& a);
666  void cancel(Space& home, Advisor& a);
668 
670 
671 
678  static void schedule(Space& home, Propagator& p, ModEvent me);
680  void reschedule(Space& home, Propagator& p, PropCond pc);
682  static ModEventDelta med(ModEvent me);
684 
686 
687  static ModEvent modevent(const Delta& d);
690  static int min(const Delta& d);
692  static int max(const Delta& d);
694  static bool any(const Delta& d);
696  static bool zero(const Delta& d);
698  static bool one(const Delta& d);
700 
702 
703  BoolVarImp* copy(Space& home, bool share);
706 
707  };
708 
709 }}
710 
712 
713 // STATISTICS: int-var
714 
NNF * l
Left subtree.
Definition: bool-expr.cpp:244
const FloatNum max
Largest allowed float value.
Definition: float.hh:846
bool one(const Gecode::FloatValArgs &a)
Check whether has only one coefficients.
Definition: linear.cpp:50
void cancel(Space &home, Propagator &p, IntSet &y)
Definition: rel.hpp:85
unsigned int BoolStatus
Type for status of a Boolean variable.
Definition: var-imp.hpp:481
RangeList * _lst
Link the last element.
Definition: var-imp.hpp:192
bool any(const View &x)
Test whether x is neither positive nor negative.
Definition: mult.hpp:57
int ModEvent
Type for modification events.
Definition: core.hpp:142
Base-class for propagators.
Definition: core.hpp:1012
Base-class for advisors.
Definition: core.hpp:1212
Base-class for Int-variable implementations.
Definition: var-imp.hpp:47
Computation spaces.
Definition: core.hpp:1672
Min _min("Int::Min")
Boolean variable implementation.
Definition: var-imp.hpp:488
Gecode::IntSet d(v, 7)
Gecode::FloatVal c(-8, 8)
int _max
Maximum of range.
Definition: var-imp.hpp:109
struct Gecode::@554::NNF::@60::@62 a
For atomic nodes.
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:236
const FloatNum min
Smallest allowed float value.
Definition: float.hh:848
Gecode::IntArgs i(4, 1, 2, 3, 4)
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
Max _max("Int::Max")
int PropCond
Type for propagation conditions.
Definition: core.hpp:152
void subscribe(Space &home, Propagator &p, IntSet &y)
Definition: rel.hpp:75
unsigned int size(I &i)
Size of all ranges of range iterator i.
void range(Home home, const IntVarArgs &x, SetVar y, SetVar z)
Post constraint .
Definition: minimodel.hh:1901
Range iterator for ranges of integer variable implementation.
Definition: var-imp.hpp:389
Backward iterator for ranges of integer variable implementations.
Definition: var-imp.hpp:432
Integer sets.
Definition: int.hh:172
unsigned int holes
Size of holes in the domain.
Definition: var-imp.hpp:202
Boolean integer variables.
Definition: int.hh:492
Integer delta information for advisors.
Definition: var-imp.hpp:55
Integer variable implementation.
Definition: var-imp.hpp:91
RangeList dom
Domain information.
Definition: var-imp.hpp:190
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:253
Generic domain change information to be supplied to advisors.
Definition: core.hpp:277
Lists of ranges (intervals)
Definition: var-imp.hpp:104
Integer variables.
Definition: int.hh:351
bool assigned(View x, int v)
Whether x is assigned to value v.
Definition: single.hpp:47
IntDelta(void)
Create integer delta as providing no information.
Definition: delta.hpp:41
Base-class for Bool-variable implementations.
Definition: var-imp.hpp:93
Base-class for freelist-managed objects.
friend class BoolVarImp
Definition: var-imp.hpp:57
Gecode toplevel namespace
friend class IntVarImp
Definition: var-imp.hpp:56
int _min
Minimum of range.
Definition: var-imp.hpp:107
#define GECODE_INT_EXPORT
Definition: int.hh:79
void reschedule(Space &home, Propagator &p, IntSet &y)
Definition: rel.hpp:96
struct Gecode::@554::NNF::@60::@61 b
For binary nodes (and, or, eqv)
int ModEventDelta
Modification event deltas.
Definition: core.hpp:169