Generated on Tue Feb 11 2025 17:33:26 for Gecode by doxygen 1.12.0
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 * 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
35
36#include <algorithm>
37
38namespace Gecode { namespace Int { namespace Distinct {
39
40 PropCost
41 EqIte::cost(const Space&, const ModEventDelta&) const {
43 }
44
45 Actor*
47 return new (home) EqIte(home,*this);
48 }
49
52 switch (rtest_eq_dom(x0,c0)) {
53 case RT_TRUE:
54 GECODE_ME_CHECK(x1.eq(home,c1));
55 return home.ES_SUBSUMED(*this);
56 case RT_FALSE:
58 ::post(home(*this),x0,x1)));
60 case RT_MAYBE:
61 break;
62 default: GECODE_NEVER;
63 }
64
65 GECODE_ME_CHECK(x1.lq(home,std::max(x0.max(),c1)));
66 GECODE_ME_CHECK(x1.gq(home,std::min(x0.min(),c1)));
67
68 RelTest eq_then = rtest_eq_dom(x1,c1);
69 RelTest eq_else = rtest_eq_dom(x1,x0);
70
71 if ((eq_then == RT_FALSE) && (eq_else == RT_FALSE))
72 return ES_FAILED;
73
74 if (eq_then == RT_FALSE) {
75 // x1 and c1 are not equal
76 GECODE_ME_CHECK(x0.nq(home,c0));
77 if (eq_else == RT_TRUE)
78 return home.ES_SUBSUMED(*this);
79 else
80 GECODE_REWRITE(*this,
82 }
83
84 if (eq_else == RT_FALSE) {
85 // x0 and x1 are not equal
86 GECODE_ME_CHECK(x0.eq(home,c0));
87 GECODE_ME_CHECK(x1.eq(home,c1));
88 return home.ES_SUBSUMED(*this);
89 }
90
91
92 assert((eq_then != RT_TRUE) || (eq_else != RT_TRUE));
93
98
99 GECODE_ME_CHECK(x1.inter_r(home,u,true));
100
101 return ES_FIX;
102 }
103
104}}}
105
106// STATISTICS: int-prop
union Gecode::@603::NNF::@65 u
Union depending on nodetype t.
Base-class for both propagators and branchers.
Definition core.hpp:628
EqIte(Space &home, EqIte &p)
Constructor for cloning p.
Definition eqite.hpp:43
virtual Actor * copy(Space &home)
Copy propagator during cloning.
Definition eqite.cpp:46
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function (defined as high ternary)
Definition eqite.cpp:41
static ExecStatus post(Home home, IntView x0, IntView x1, int c0, int c1)
Post if-then-else propagator.
Definition eqite.hpp:49
int c0
The integer constant.
Definition distinct.hh:354
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition eqite.cpp:51
ModEvent inter_r(Space &home, I &i, bool depends=true)
Intersect domain with ranges described by i.
Definition int.hpp:186
int min(void) const
Return minimum of domain.
Definition int.hpp:58
ModEvent lq(Space &home, int n)
Restrict domain values to be less or equal than n.
Definition int.hpp:121
ModEvent gq(Space &home, int n)
Restrict domain values to be greater or equal than n.
Definition int.hpp:139
int max(void) const
Return maximum of domain.
Definition int.hpp:62
ModEvent nq(Space &home, int n)
Restrict domain values to be different from n.
Definition int.hpp:157
ModEvent eq(Space &home, int n)
Restrict domain values to be equal to n.
Definition int.hpp:166
Binary domain consistent equality propagator.
Definition rel.hh:68
Range iterator for integer views.
Definition view.hpp:54
Range iterator for singleton range.
Range iterator for computing union (binary)
static PropCost binary(PropCost::Mod m)
Two variables for modifier pcm.
Definition core.hpp:4809
@ HI
Expensive.
Definition core.hpp:514
Computation spaces.
Definition core.hpp:1742
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
#define GECODE_REWRITE(prop, post)
Rewrite propagator by executing post function.
Definition macros.hpp:116
RelTest rtest_eq_dom(VX x, VY y)
Test whether views x and y are equal (use full domain information)
Definition rel-test.hpp:65
RelTest
Result of testing relation.
Definition view.hpp:1734
@ RT_TRUE
Relation does hold.
Definition view.hpp:1737
@ RT_MAYBE
Relation may hold or not.
Definition view.hpp:1736
@ RT_FALSE
Relation does not hold.
Definition view.hpp:1735
Gecode toplevel namespace
ExecStatus
Definition core.hpp:472
@ ES_FIX
Propagation has computed fixpoint.
Definition core.hpp:477
@ ES_FAILED
Execution has resulted in failure.
Definition core.hpp:474
#define GECODE_NEVER
Assert that this command is never executed.
Definition macros.hpp:56