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