this repo has no description
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, 2011
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
34namespace Gecode { namespace Int { namespace NValues {
35
36 template<class VY>
37 forceinline
38 BoolBase<VY>::BoolBase(Home home,
39 int status0, ViewArray<BoolView>& x, VY y0)
40 : Propagator(home), status(status0), c(home), y(y0) {
41 y.subscribe(home,*this,PC_INT_BND);
42 for (int i=0; i<x.size(); i++) {
43 assert(!x[i].assigned());
44 (void) new (home) ViewAdvisor<BoolView>(home, *this, c, x[i]);
45 }
46 }
47
48 template<class VY>
49 forceinline
50 BoolBase<VY>::BoolBase(Space& home, BoolBase<VY>& p)
51 : Propagator(home,p), status(p.status) {
52 c.update(home,p.c);
53 y.update(home,p.y);
54 }
55
56 template<class VY>
57 PropCost
58 BoolBase<VY>::cost(const Space&, const ModEventDelta&) const {
59 return PropCost::unary(PropCost::LO);
60 }
61
62 template<class VY>
63 void
64 BoolBase<VY>::reschedule(Space& home) {
65 y.reschedule(home,*this,PC_INT_BND);
66 }
67
68 template<class VY>
69 ExecStatus
70 BoolBase<VY>::advise(Space& home, Advisor& _a, const Delta&) {
71 ViewAdvisor<BoolView>& a(static_cast<ViewAdvisor<BoolView>&>(_a));
72 ExecStatus es;
73 if (status == (VS_ZERO | VS_ONE)) {
74 // Everything is already decided
75 es = ES_FIX;
76 } else {
77 if (a.view().zero())
78 status |= VS_ZERO;
79 else
80 status |= VS_ONE;
81 es = ES_NOFIX;
82 }
83 a.dispose(home,c);
84 if (c.empty())
85 es = ES_NOFIX;
86 return es;
87 }
88
89 template<class VY>
90 forceinline size_t
91 BoolBase<VY>::dispose(Space& home) {
92 c.dispose(home);
93 y.cancel(home,*this,PC_INT_BND);
94 (void) Propagator::dispose(home);
95 return sizeof(*this);
96 }
97
98}}}
99
100// STATISTICS: int-prop