Generated on Sat Nov 9 2013 19:18:25 for Gecode by doxygen 1.8.4
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-08-29 16:05:54 +0200 (Thu, 29 Aug 2013) $ by $Author: schulte $
13  * $Revision: 13993 $
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, bool minus>
451  class NrootPlusBnd : public BinaryPropagator<IntView,PC_INT_BND> {
452  protected:
456  Ops ops;
458  NrootPlusBnd(Space& home, bool share, NrootPlusBnd<Ops,minus>& p);
460  NrootPlusBnd(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 NrootBnd : public BinaryPropagator<IntView,PC_INT_BND> {
478  protected:
482  Ops ops;
484  NrootBnd(Space& home, bool share, NrootBnd<Ops>& p);
486  NrootBnd(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);
493  static ExecStatus post(Home home, IntView x0, IntView x1, Ops ops);
494  };
495 
502  template<class Ops, bool minus>
503  class NrootPlusDom : public BinaryPropagator<IntView,PC_INT_DOM> {
504  protected:
508  Ops ops;
510  NrootPlusDom(Space& home, bool share, NrootPlusDom<Ops,minus>& p);
512  NrootPlusDom(Home home, IntView x0, IntView x1, const Ops& ops);
513  public:
515  virtual Actor* copy(Space& home, bool share);
517  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
525  virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
527  static ExecStatus post(Home home, IntView x0, IntView x1, Ops ops);
528  };
529 
536  template<class Ops>
537  class NrootDom : public BinaryPropagator<IntView,PC_INT_DOM> {
538  protected:
542  Ops ops;
544  NrootDom(Space& home, bool share, NrootDom<Ops>& p);
546  NrootDom(Home home, IntView x0, IntView x1, const Ops& ops);
547  public:
549  virtual Actor* copy(Space& home, bool share);
551  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
559  virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
561  static ExecStatus post(Home home, IntView x0, IntView x1, Ops ops);
562  };
563 
564 }}}
565 
567 
568 namespace Gecode { namespace Int { namespace Arithmetic {
569 
576  template<class View, PropCond pc>
577  class MultZeroOne : public BinaryPropagator<View,pc> {
578  protected:
581 
583  MultZeroOne(Space& home, bool share, MultZeroOne<View,pc>& p);
585  MultZeroOne(Home home, View x0, View x1);
587  static RelTest equal(View x, int n);
588  public:
590  virtual Actor* copy(Space& home, bool share);
592  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
594  static ExecStatus post(Home home, View x0, View x1);
595  };
596 
597 
598 
604  template<class VA, class VB, class VC>
605  class MultPlusBnd :
606  public MixTernaryPropagator<VA,PC_INT_BND,VB,PC_INT_BND,VC,PC_INT_BND> {
607  protected:
611  public:
613  MultPlusBnd(Home home, VA x0, VB x1, VC x2);
615  MultPlusBnd(Space& home, bool share, MultPlusBnd<VA,VB,VC>& p);
617  static ExecStatus post(Home home, VA x0, VB x1, VC x2);
619  virtual Actor* copy(Space& home, bool share);
621  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
622  };
623 
631  class MultBnd : public TernaryPropagator<IntView,PC_INT_BND> {
632  protected:
637  MultBnd(Space& home, bool share, MultBnd& p);
638  public:
643  static ExecStatus post(Home home, IntView x0, IntView x1, IntView x2);
646  virtual Actor* copy(Space& home, bool share);
649  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
650  };
651 
652 
653 
659  template<class VA, class VB, class VC>
660  class MultPlusDom :
661  public MixTernaryPropagator<VA,PC_INT_DOM,VB,PC_INT_DOM,VC,PC_INT_DOM> {
662  protected:
666  public:
668  MultPlusDom(Home home, VA x0, VB x1, VC x2);
670  MultPlusDom(Space& home, bool share, MultPlusDom<VA,VB,VC>& p);
672  static ExecStatus post(Home home, VA x0, VB x1, VC x2);
674  virtual Actor* copy(Space& home, bool share);
681  virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
683  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
684  };
685 
693  class MultDom : public TernaryPropagator<IntView,PC_INT_DOM> {
694  protected:
699  MultDom(Space& home, bool share, MultDom& p);
700  public:
705  static ExecStatus post(Home home, IntView x0, IntView x1, IntView x2);
708  virtual Actor* copy(Space& home, bool share);
716  virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
719  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
720  };
721 
722 }}}
723 
725 
726 namespace Gecode { namespace Int { namespace Arithmetic {
727 
733  template<class VA, class VB, class VC>
734  class DivPlusBnd :
735  public MixTernaryPropagator<VA,PC_INT_BND,VB,PC_INT_BND,VC,PC_INT_BND> {
736  protected:
740  public:
742  DivPlusBnd(Home home, VA x0, VB x1, VC x2);
744  DivPlusBnd(Space& home, bool share, DivPlusBnd<VA,VB,VC>& p);
746  static ExecStatus post(Home home, VA x0, VB x1, VC x2);
748  virtual Actor* copy(Space& home, bool share);
750  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
751  };
752 
760  template<class View>
761  class DivBnd : public TernaryPropagator<View,PC_INT_BND> {
762  protected:
766 
768  DivBnd(Space& home, bool share, DivBnd<View>& p);
769  public:
771  DivBnd(Home home, View x0, View x1, View x2);
773  static ExecStatus post(Home home, View x0, View x1, View x2);
775  virtual Actor* copy(Space& home, bool share);
777  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
778  };
779 
790  template<class View>
791  class DivMod : public TernaryPropagator<View,PC_INT_BND> {
792  protected:
796 
798  DivMod(Space& home, bool share, DivMod<View>& p);
799  public:
801  DivMod(Home home, View x0, View x1, View x2);
803  static ExecStatus post(Home home, View x0, View x1, View x2);
805  virtual Actor* copy(Space& home, bool share);
807  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
808  };
809 
810 }}}
811 
813 
814 #endif
815 
816 // STATISTICS: int-prop
817