Generated on Tue Jan 28 2020 00:00:00 for Gecode by doxygen 1.8.17
eqite.cpp
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  * Copyright:
7  * Christian Schulte, 2015
8  *
9  * Last modified:
10  * $Date: 2016-04-19 17:19:45 +0200 (Tue, 19 Apr 2016) $ by $Author: schulte $
11  * $Revision: 14967 $
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 #include <gecode/int/distinct.hh>
39 
40 #include <algorithm>
41 
42 namespace Gecode { namespace Int { namespace Distinct {
43 
44  PropCost
45  EqIte::cost(const Space&, const ModEventDelta&) const {
47  }
48 
49  Actor*
50  EqIte::copy(Space& home, bool share) {
51  return new (home) EqIte(home,share,*this);
52  }
53 
56  switch (rtest_eq_dom(x0,c0)) {
57  case RT_TRUE:
58  GECODE_ME_CHECK(x1.eq(home,c1));
59  return home.ES_SUBSUMED(*this);
60  case RT_FALSE:
62  ::post(home(*this),x0,x1)));
64  case RT_MAYBE:
65  break;
66  default: GECODE_NEVER;
67  }
68 
69  GECODE_ME_CHECK(x1.lq(home,std::max(x0.max(),c1)));
70  GECODE_ME_CHECK(x1.gq(home,std::min(x0.min(),c1)));
71 
72  RelTest eq_then = rtest_eq_dom(x1,c1);
73  RelTest eq_else = rtest_eq_dom(x1,x0);
74 
75  if ((eq_then == RT_FALSE) && (eq_else == RT_FALSE))
76  return ES_FAILED;
77 
78  if (eq_then == RT_FALSE) {
79  // x1 and c1 are not equal
80  GECODE_ME_CHECK(x0.nq(home,c0));
81  if (eq_else == RT_TRUE)
82  return home.ES_SUBSUMED(*this);
83  else
84  GECODE_REWRITE(*this,
85  (Rel::EqDom<IntView,IntView>::post(home(*this),x0,x1)));
86  }
87 
88  if (eq_else == RT_FALSE) {
89  // x0 and x1 are not equal
90  GECODE_ME_CHECK(x0.eq(home,c0));
91  GECODE_ME_CHECK(x1.eq(home,c1));
92  return home.ES_SUBSUMED(*this);
93  }
94 
95 
96  assert((eq_then != RT_TRUE) || (eq_else != RT_TRUE));
97 
101  Iter::Ranges::Singleton > u(r0,r1);
102 
103  GECODE_ME_CHECK(x1.inter_r(home,u,true));
104 
105  return ES_FIX;
106  }
107 
108 }}}
109 
110 // STATISTICS: int-prop
int c1
Definition: distinct.hh:317
ExecStatus ES_SUBSUMED(Propagator &p)
Definition: core.hpp:3614
int min(void) const
Return minimum of domain.
Definition: int.hpp:58
static PropCost binary(PropCost::Mod m)
Two variables for modifier pcm.
Definition: core.hpp:4854
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function (defined as high ternary)
Definition: eqite.cpp:45
const FloatNum min
Smallest allowed float value.
Definition: float.hh:850
Computation spaces.
Definition: core.hpp:1748
Base-class for both propagators and branchers.
Definition: core.hpp:696
static ExecStatus post(Home home, IntView x0, IntView x1, int c0, int c1)
Post if-then-else propagator.
Definition: eqite.hpp:53
@ RT_TRUE
Relation does hold.
Definition: view.hpp:1617
union Gecode::@579::NNF::@61 u
Union depending on nodetype t.
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: eqite.cpp:55
virtual Actor * copy(Space &home, bool share)
Copy propagator during cloning.
Definition: eqite.cpp:50
Gecode toplevel namespace
int max(void) const
Return maximum of domain.
Definition: int.hpp:62
@ RT_MAYBE
Relation may hold or not.
Definition: view.hpp:1616
ModEvent inter_r(Space &home, I &i, bool depends=true)
Intersect domain with ranges described by i.
Definition: int.hpp:180
Binary domain consistent equality propagator.
Definition: rel.hh:71
RelTest rtest_eq_dom(VX x, VY y)
Test whether views x and y are equal (use full domain information)
Definition: rel-test.hpp:69
@ RT_FALSE
Relation does not hold.
Definition: view.hpp:1615
EqIte(Space &home, bool share, EqIte &p)
Constructor for cloning p.
Definition: eqite.hpp:47
IntView x1
Definition: propagator.hpp:92
ModEvent nq(Space &home, int n)
Restrict domain values to be different from n.
Definition: int.hpp:151
int c0
The integer constant.
Definition: distinct.hh:317
#define GECODE_NEVER
Assert that this command is never executed.
Definition: macros.hpp:60
Range iterator for computing union (binary)
@ ES_FIX
Propagation has computed fixpoint.
Definition: core.hpp:545
Range iterator for integer variable views
Definition: int.hpp:236
RelTest
Result of testing relation.
Definition: view.hpp:1614
Range iterator for singleton range.
#define GECODE_ME_CHECK(me)
Check whether modification event me is failed, and forward failure.
Definition: macros.hpp:56
@ HI
Expensive.
Definition: core.hpp:582
ModEvent lq(Space &home, int n)
Restrict domain values to be less or equal than n.
Definition: int.hpp:115
ModEvent gq(Space &home, int n)
Restrict domain values to be greater or equal than n.
Definition: int.hpp:133
@ ES_FAILED
Execution has resulted in failure.
Definition: core.hpp:542
int ModEventDelta
Modification event deltas.
Definition: core.hpp:169
#define GECODE_REWRITE(prop, post)
Rewrite propagator by executing post function.
Definition: macros.hpp:120
IntView x0
Two views.
Definition: propagator.hpp:92
const FloatNum max
Largest allowed float value.
Definition: float.hh:848
ModEvent eq(Space &home, int n)
Restrict domain values to be equal to n.
Definition: int.hpp:160
ExecStatus
Definition: core.hpp:540