Generated on Sat Feb 7 2015 02:01:14 for Gecode by doxygen 1.8.9.1
pow-nroot.hpp
Go to the documentation of this file.
1 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2 /*
3  * Main authors:
4  * Vincent Barichard <Vincent.Barichard@univ-angers.fr>
5  *
6  * Copyright:
7  * Vincent Barichard, 2012
8  *
9  * Last modified:
10  * $Date: 2013-01-30 10:22:34 +0100 (Wed, 30 Jan 2013) $ by $Author: vbarichard $
11  * $Revision: 13250 $
12  *
13  * This file is part of Gecode, the generic constraint
14  * development environment:
15  * http://www.gecode.org
16  *
17  * Permission is hereby granted, free of charge, to any person obtaining
18  * a copy of this software and associated documentation files (the
19  * "Software"), to deal in the Software without restriction, including
20  * without limitation the rights to use, copy, modify, merge, publish,
21  * distribute, sublicense, and/or sell copies of the Software, and to
22  * permit persons to whom the Software is furnished to do so, subject to
23  * the following conditions:
24  *
25  * The above copyright notice and this permission notice shall be
26  * included in all copies or substantial portions of the Software.
27  *
28  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35  *
36  */
37 
38 namespace Gecode { namespace Float { namespace Arithmetic {
39 
40 
41  /*
42  * Bounds consistent square operator
43  *
44  */
45 
46  template<class A, class B>
48  Pow<A,B>::Pow(Home home, A x0, B x1, int n)
49  : MixBinaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND>(home,x0,x1), m_n(n) {}
50 
51  template<class A, class B>
53  Pow<A,B>::post(Home home, A x0, B x1, int n) {
54  if (n == 0) {
55  if ((x0.min() == 0.0) && (x0.max() == 0.0)) return ES_FAILED;
56  GECODE_ME_CHECK(x1.eq(home,1.0));
57  return ES_OK;
58  }
59 
60  GECODE_ME_CHECK(x1.eq(home,pow(x0.domain(),n)));
61  if ((x1.min() == 0.0) && (x1.max() == 0.0)) {
62  GECODE_ME_CHECK(x1.eq(home,0.0));
63  return ES_OK;
64  }
65 
66  if ((n % 2) == 0)
67  {
68  if (x0.min() >= 0)
69  GECODE_ME_CHECK(x0.eq(home,nroot(x1.domain(),n)));
70  else if (x0.max() <= 0)
71  GECODE_ME_CHECK(x0.eq(home,-nroot(x1.domain(),n)));
72  else
73  GECODE_ME_CHECK(x0.eq(home,
74  hull(
75  nroot(x1.domain(),n),
76  -nroot(x1.domain(),n)
77  )
78  ));
79  } else
80  GECODE_ME_CHECK(x0.eq(home,nroot(x1.domain(),n)));
81 
82  if (!x0.assigned()) (void) new (home) Pow<A,B>(home,x0,x1,n);
83  return ES_OK;
84  }
85 
86  template<class A, class B>
88  Pow<A,B>::Pow(Space& home, bool share, Pow<A,B>& p)
89  : MixBinaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND>(home,share,p), m_n(p.m_n) {}
90 
91  template<class A, class B>
92  Actor*
93  Pow<A,B>::copy(Space& home, bool share) {
94  return new (home) Pow<A,B>(home,share,*this);
95  }
96 
97  template<class A, class B>
100  if ((x0.min() == 0.0) && (x0.max() == 0.0)) return ES_FAILED;
101  GECODE_ME_CHECK(x1.eq(home,pow(x0.domain(),m_n)));
102 
103  if ((x1.min() == 0.0) && (x1.max() == 0.0)) {
104  GECODE_ME_CHECK(x1.eq(home,0.0));
105  return home.ES_SUBSUMED(*this);
106  }
107 
108  if ((m_n % 2) == 0)
109  {
110  if (x0.min() >= 0)
111  GECODE_ME_CHECK(x0.eq(home,nroot(x1.domain(),m_n)));
112  else if (x0.max() <= 0)
113  GECODE_ME_CHECK(x0.eq(home,-nroot(x1.domain(),m_n)));
114  else
115  GECODE_ME_CHECK(x0.eq(home,
116  hull(
117  nroot(x1.domain(),m_n),
118  -nroot(x1.domain(),m_n)
119  )
120  ));
121  } else
122  GECODE_ME_CHECK(x0.eq(home,nroot(x1.domain(),m_n)));
123  return x0.assigned() ? home.ES_SUBSUMED(*this) : ES_FIX;
124  }
125 
126  /*
127  * Bounds consistent square root operator
128  *
129  */
130 
131  template<class A, class B>
133  NthRoot<A,B>::NthRoot(Home home, A x0, B x1, int n)
134  : MixBinaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND>(home,x0,x1), m_n(n) {}
135 
136  template<class A, class B>
137  ExecStatus
138  NthRoot<A,B>::post(Home home, A x0, B x1, int n) {
139  if (n == 0) return ES_FAILED;
140  GECODE_ME_CHECK(x0.gq(home,0.0));
141  (void) new (home) NthRoot<A,B>(home,x0,x1,n);
142  return ES_OK;
143  }
144 
145  template<class A, class B>
148  : MixBinaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND>(home,share,p), m_n(p.m_n) {}
149 
150  template<class A, class B>
151  Actor*
152  NthRoot<A,B>::copy(Space& home, bool share) {
153  return new (home) NthRoot<A,B>(home,share,*this);
154  }
155 
156  template<class A, class B>
157  ExecStatus
159  GECODE_ME_CHECK(x1.eq(home,nroot(x0.domain(),m_n)));
160  GECODE_ME_CHECK(x0.eq(home,pow(x1.domain(),m_n)));
161  return x0.assigned() ? home.ES_SUBSUMED(*this) : ES_FIX;
162  }
163 
164 
165 }}}
166 
167 // STATISTICS: float-prop
168 
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: pow-nroot.hpp:158
ExecStatus ES_SUBSUMED(Propagator &p)
Definition: core.hpp:2973
void nroot(Home home, FloatVar x0, int n, FloatVar x1)
Post propagator for for $n 0$.
Definition: arithmetic.cpp:126
void pow(Home home, FloatVar x0, int n, FloatVar x1)
Post propagator for for $n 0$.
Definition: arithmetic.cpp:117
FloatVal hull(const FloatVal &x, const FloatVal &y)
Definition: val.hpp:511
Pow(Space &home, bool share, Pow &p)
Constructor for cloning p.
Definition: pow-nroot.hpp:88
Propagation has computed fixpoint.
Definition: core.hpp:528
Computation spaces.
Definition: core.hpp:1362
Base-class for both propagators and branchers.
Definition: core.hpp:666
NthRoot(Space &home, bool share, NthRoot &p)
Constructor for cloning p.
Definition: pow-nroot.hpp:147
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:236
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
Propagator for bounds consistent pow operator
Definition: arithmetic.hh:169
Execution has resulted in failure.
Definition: core.hpp:525
static ExecStatus post(Home home, A x0, B x1, int n)
Post propagator for .
Definition: pow-nroot.hpp:138
static ExecStatus post(Home home, A x0, B x1, int n)
Post propagator for .
Definition: pow-nroot.hpp:53
virtual Actor * copy(Space &home, bool share)
Create copy during cloning.
Definition: pow-nroot.hpp:152
#define GECODE_ME_CHECK(me)
Check whether modification event me is failed, and forward failure.
Definition: macros.hpp:45
Mixed binary propagator.
Definition: propagator.hpp:203
ExecStatus
Definition: core.hpp:523
#define forceinline
Definition: config.hpp:132
virtual Actor * copy(Space &home, bool share)
Create copy during cloning.
Definition: pow-nroot.hpp:93
Execution is okay.
Definition: core.hpp:527
const Gecode::PropCond PC_FLOAT_BND
Propagate when minimum or maximum of a view changes.
Definition: var-type.hpp:292
Gecode toplevel namespace
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: pow-nroot.hpp:99
int ModEventDelta
Modification event deltas.
Definition: core.hpp:173
Home class for posting propagators
Definition: core.hpp:717
Propagator for bounds consistent nth root operator
Definition: arithmetic.hh:197