Generated on Sat May 25 2013 18:00:33 for Gecode by doxygen 1.8.3.1
arithmetic.hh
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  * Guido Tack <tack@gecode.org>
6  *
7  * Copyright:
8  * Christian Schulte, 2002
9  * Guido Tack, 2004
10  *
11  * Last modified:
12  * $Date: 2013-02-14 16:29:11 +0100 (Thu, 14 Feb 2013) $ by $Author: schulte $
13  * $Revision: 13292 $
14  *
15  * This file is part of Gecode, the generic constraint
16  * development environment:
17  * http://www.gecode.org
18  *
19  * Permission is hereby granted, free of charge, to any person obtaining
20  * a copy of this software and associated documentation files (the
21  * "Software"), to deal in the Software without restriction, including
22  * without limitation the rights to use, copy, modify, merge, publish,
23  * distribute, sublicense, and/or sell copies of the Software, and to
24  * permit persons to whom the Software is furnished to do so, subject to
25  * the following conditions:
26  *
27  * The above copyright notice and this permission notice shall be
28  * included in all copies or substantial portions of the Software.
29  *
30  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
31  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
32  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
33  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
34  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
35  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
36  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37  *
38  */
39 
40 #ifndef __GECODE_INT_ARITHMETIC_HH__
41 #define __GECODE_INT_ARITHMETIC_HH__
42 
43 #include <gecode/int.hh>
44 
45 #include <gecode/int/rel.hh>
46 #include <gecode/int/linear.hh>
47 
53 namespace Gecode { namespace Int { namespace Arithmetic {
54 
61  template<class View>
62  class AbsBnd : public BinaryPropagator<View,PC_INT_BND> {
63  protected:
66 
68  AbsBnd(Space& home, bool share, AbsBnd& p);
70  AbsBnd(Home home, View x0, View x1);
71  public:
72 
74  virtual Actor* copy(Space& home, bool share);
81  virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
83  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
85  static ExecStatus post(Home home, View x0, View x1);
86  };
87 
94  template<class View>
95  class AbsDom : public BinaryPropagator<View,PC_INT_DOM> {
96  protected:
99 
101  AbsDom(Space& home, bool share, AbsDom& p);
103  AbsDom(Home home, View x0, View x1);
104  public:
106  virtual Actor* copy(Space& home, bool share);
114  virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
116  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
118  static ExecStatus post(Home home, View x0, View x1);
119  };
120 
121 }}}
122 
124 
125 namespace Gecode { namespace Int { namespace Arithmetic {
126 
133  template<class View>
134  class MaxBnd : public TernaryPropagator<View,PC_INT_BND> {
135  protected:
139 
141  MaxBnd(Space& home, bool share, MaxBnd& p);
143  MaxBnd(Home home, View x0, View x1, View x2);
144  public:
146  MaxBnd(Space& home, bool share, Propagator& p, View x0, View x1, View x2);
148  virtual Actor* copy(Space& home, bool share);
150  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
152  static ExecStatus post(Home home, View x0, View x1, View x2);
153  };
154 
161  template<class View>
162  class NaryMaxBnd : public NaryOnePropagator<View,PC_INT_BND> {
163  protected:
166 
168  NaryMaxBnd(Space& home, bool share, NaryMaxBnd& p);
170  NaryMaxBnd(Home home, ViewArray<View>& x, View y);
171  public:
173  virtual Actor* copy(Space& home, bool share);
175  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
177  static ExecStatus post(Home home, ViewArray<View>& x, View y);
178  };
179 
186  template<class View>
187  class MaxDom : public TernaryPropagator<View,PC_INT_DOM> {
188  protected:
192 
194  MaxDom(Space& home, bool share, MaxDom& p);
196  MaxDom(Home home, View x0, View x1, View x2);
197  public:
199  MaxDom(Space& home, bool share, Propagator& p, View x0, View x1, View x2);
201  virtual Actor* copy(Space& home, bool share);
208  virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
210  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
212  static ExecStatus post(Home home, View x0, View x1, View x2);
213  };
214 
221  template<class View>
222  class NaryMaxDom : public NaryOnePropagator<View,PC_INT_DOM> {
223  protected:
226 
228  NaryMaxDom(Space& home, bool share, NaryMaxDom& p);
230  NaryMaxDom(Home home, ViewArray<View>& x, View y);
231  public:
233  virtual Actor* copy(Space& home, bool share);
240  virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
242  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
244  static ExecStatus post(Home home, ViewArray<View>& x, View y);
245  };
246 
247 }}}
248 
250 
251 namespace Gecode { namespace Int { namespace Arithmetic {
252 
259  class SqrOps {
260  public:
262  bool even(void) const;
264  int exp(void) const;
266  void exp(int m);
268  template<class IntType>
269  IntType pow(IntType x) const;
271  int tpow(int x) const;
273  int fnroot(int x) const;
275  int cnroot(int x) const;
276  };
277 
284  class PowOps {
285  protected:
287  int n;
289  static bool even(int m);
291  bool powgr(long long int r, int x) const;
293  bool powle(long long int r, int x) const;
294  public:
296  PowOps(int n);
298  bool even(void) const;
300  int exp(void) const;
302  void exp(int m);
304  template<class IntType>
305  IntType pow(IntType x) const;
307  int tpow(int x) const;
309  int fnroot(int x) const;
311  int cnroot(int x) const;
312  };
313 
314 }}}
315 
317 
318 namespace Gecode { namespace Int { namespace Arithmetic {
319 
325  template<class VA, class VB, class Ops>
326  class PowPlusBnd : public MixBinaryPropagator<VA,PC_INT_BND,VB,PC_INT_BND> {
327  protected:
331  Ops ops;
333  PowPlusBnd(Home home, VA x0, VB x1, const Ops& ops);
335  PowPlusBnd(Space& home, bool share, PowPlusBnd<VA,VB,Ops>& p);
336  public:
338  virtual Actor* copy(Space& home, bool share);
340  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
342  static ExecStatus post(Home home, VA x0, VB x1, Ops ops);
343  };
344 
351  template<class Ops>
352  class PowBnd : public BinaryPropagator<IntView,PC_INT_BND> {
353  protected:
357  Ops ops;
359  PowBnd(Space& home, bool share, PowBnd& p);
361  PowBnd(Home home, IntView x0, IntView x1, const Ops& ops);
362  public:
364  virtual Actor* copy(Space& home, bool share);
366  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
368  static ExecStatus post(Home home, IntView x0, IntView x1, Ops ops);
369  };
370 
376  template<class VA, class VB, class Ops>
377  class PowPlusDom : public MixBinaryPropagator<VA,PC_INT_DOM,VB,PC_INT_DOM> {
378  protected:
382  Ops ops;
384  PowPlusDom(Home home, VA x0, VB x1, const Ops& ops);
386  PowPlusDom(Space& home, bool share, PowPlusDom<VA,VB,Ops>& p);
387  public:
389  virtual Actor* copy(Space& home, bool share);
397  virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
399  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
401  static ExecStatus post(Home home, VA x0, VB x1, Ops ops);
402  };
403 
410  template<class Ops>
411  class PowDom : public BinaryPropagator<IntView,PC_INT_DOM> {
412  protected:
416  Ops ops;
418  PowDom(Space& home, bool share, PowDom<Ops>& p);
420  PowDom(Home home, IntView x0, IntView x1, const Ops& ops);
421  public:
423  virtual Actor* copy(Space& home, bool share);
425  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
433  virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
435  static ExecStatus post(Home home, IntView x0, IntView x1, Ops ops);
436  };
437 
438 }}}
439 
441 
442 namespace Gecode { namespace Int { namespace Arithmetic {
443 
450  template<class Ops>
451  class NrootBnd : public BinaryPropagator<IntView,PC_INT_BND> {
452  protected:
456  Ops ops;
458  NrootBnd(Space& home, bool share, NrootBnd<Ops>& p);
460  NrootBnd(Home home, IntView x0, IntView x1, const Ops& ops);
461  public:
463  virtual Actor* copy(Space& home, bool share);
465  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
467  static ExecStatus post(Home home, IntView x0, IntView x1, Ops ops);
468  };
469 
476  template<class Ops>
477  class NrootDom : public BinaryPropagator<IntView,PC_INT_DOM> {
478  protected:
482  Ops ops;
484  NrootDom(Space& home, bool share, NrootDom<Ops>& p);
486  NrootDom(Home home, IntView x0, IntView x1, const Ops& ops);
487  public:
489  virtual Actor* copy(Space& home, bool share);
491  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
499  virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
501  static ExecStatus post(Home home, IntView x0, IntView x1, Ops ops);
502  };
503 
504 }}}
505 
507 
508 namespace Gecode { namespace Int { namespace Arithmetic {
509 
516  template<class View, PropCond pc>
517  class MultZeroOne : public BinaryPropagator<View,pc> {
518  protected:
521 
523  MultZeroOne(Space& home, bool share, MultZeroOne<View,pc>& p);
525  MultZeroOne(Home home, View x0, View x1);
527  static RelTest equal(View x, int n);
528  public:
530  virtual Actor* copy(Space& home, bool share);
532  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
534  static ExecStatus post(Home home, View x0, View x1);
535  };
536 
537 
538 
544  template<class VA, class VB, class VC>
545  class MultPlusBnd :
546  public MixTernaryPropagator<VA,PC_INT_BND,VB,PC_INT_BND,VC,PC_INT_BND> {
547  protected:
551  public:
553  MultPlusBnd(Home home, VA x0, VB x1, VC x2);
555  MultPlusBnd(Space& home, bool share, MultPlusBnd<VA,VB,VC>& p);
557  static ExecStatus post(Home home, VA x0, VB x1, VC x2);
559  virtual Actor* copy(Space& home, bool share);
561  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
562  };
563 
571  class MultBnd : public TernaryPropagator<IntView,PC_INT_BND> {
572  protected:
577  MultBnd(Space& home, bool share, MultBnd& p);
578  public:
583  static ExecStatus post(Home home, IntView x0, IntView x1, IntView x2);
586  virtual Actor* copy(Space& home, bool share);
589  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
590  };
591 
592 
593 
599  template<class VA, class VB, class VC>
600  class MultPlusDom :
601  public MixTernaryPropagator<VA,PC_INT_DOM,VB,PC_INT_DOM,VC,PC_INT_DOM> {
602  protected:
606  public:
608  MultPlusDom(Home home, VA x0, VB x1, VC x2);
610  MultPlusDom(Space& home, bool share, MultPlusDom<VA,VB,VC>& p);
612  static ExecStatus post(Home home, VA x0, VB x1, VC x2);
614  virtual Actor* copy(Space& home, bool share);
621  virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
623  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
624  };
625 
633  class MultDom : public TernaryPropagator<IntView,PC_INT_DOM> {
634  protected:
639  MultDom(Space& home, bool share, MultDom& p);
640  public:
645  static ExecStatus post(Home home, IntView x0, IntView x1, IntView x2);
648  virtual Actor* copy(Space& home, bool share);
656  virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
659  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
660  };
661 
662 }}}
663 
665 
666 namespace Gecode { namespace Int { namespace Arithmetic {
667 
673  template<class VA, class VB, class VC>
674  class DivPlusBnd :
675  public MixTernaryPropagator<VA,PC_INT_BND,VB,PC_INT_BND,VC,PC_INT_BND> {
676  protected:
680  public:
682  DivPlusBnd(Home home, VA x0, VB x1, VC x2);
684  DivPlusBnd(Space& home, bool share, DivPlusBnd<VA,VB,VC>& p);
686  static ExecStatus post(Home home, VA x0, VB x1, VC x2);
688  virtual Actor* copy(Space& home, bool share);
690  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
691  };
692 
700  template<class View>
701  class DivBnd : public TernaryPropagator<View,PC_INT_BND> {
702  protected:
706 
708  DivBnd(Space& home, bool share, DivBnd<View>& p);
709  public:
711  DivBnd(Home home, View x0, View x1, View x2);
713  static ExecStatus post(Home home, View x0, View x1, View x2);
715  virtual Actor* copy(Space& home, bool share);
717  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
718  };
719 
730  template<class View>
731  class DivMod : public TernaryPropagator<View,PC_INT_BND> {
732  protected:
736 
738  DivMod(Space& home, bool share, DivMod<View>& p);
739  public:
741  DivMod(Home home, View x0, View x1, View x2);
743  static ExecStatus post(Home home, View x0, View x1, View x2);
745  virtual Actor* copy(Space& home, bool share);
747  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
748  };
749 
750 }}}
751 
753 
754 #endif
755 
756 // STATISTICS: int-prop
757