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, 2016
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
33namespace Gecode {
34
35 /// Iterator over subscribed propagators
36 class SubscribedPropagators {
37 protected:
38 /// Pointing at the current subscription (either propagator or advisor)
39 ActorLink** c;
40 /// End of propagator subscriptions
41 ActorLink** ep;
42 /// End of advisor subscriptions
43 ActorLink** ea;
44 public:
45 /// Initialize
46 template<class VIC>
47 SubscribedPropagators(VarImp<VIC>& x);
48 /// Initialize
49 template<class View>
50 SubscribedPropagators(ConstView<View>& x);
51 /// Initialize
52 template<class Var>
53 SubscribedPropagators(VarImpView<Var>& x);
54 /// Initialize
55 template<class View>
56 SubscribedPropagators(DerivedView<View>& x);
57 /// Initialize
58 template<class VIC>
59 void init(VarImp<VIC>& x);
60 /// Initialize
61 template<class View>
62 void init(ConstView<View>& x);
63 /// Initialize
64 template<class Var>
65 void init(VarImpView<Var>& x);
66 /// Initialize
67 template<class View>
68 void init(DerivedView<View>& x);
69 /// Test whether there are propagators left
70 bool operator ()(void) const;
71 /// Move iterator to next propagator
72 void operator ++(void);
73 /// Return propagator
74 Propagator& propagator(void) const;
75 };
76
77 template<class VIC>
78 forceinline void
79 SubscribedPropagators::init(VarImp<VIC>& x) {
80 c = x.actor(0);
81 ep = x.actorNonZero(x.pc_max+1); ea = x.b.base+x.entries;
82 }
83 template<class VIC>
84 forceinline
85 SubscribedPropagators::SubscribedPropagators(VarImp<VIC>& x) {
86 init(x);
87 }
88 template<class View>
89 forceinline void
90 SubscribedPropagators::init(ConstView<View>&) {
91 c = ep = ea = nullptr;
92 }
93 template<class View>
94 forceinline
95 SubscribedPropagators::SubscribedPropagators(ConstView<View>& x) {
96 init(x);
97 }
98 template<class Var>
99 forceinline
100 SubscribedPropagators::SubscribedPropagators(VarImpView<Var>& x) {
101 init(*x.varimp());
102 }
103 template<class Var>
104 forceinline void
105 SubscribedPropagators::init(VarImpView<Var>& x) {
106 init(*x.varimp());
107 }
108 template<class View>
109 forceinline
110 SubscribedPropagators::SubscribedPropagators(DerivedView<View>& x) {
111 init(*x.varimp());
112 }
113 template<class View>
114 forceinline void
115 SubscribedPropagators::init(DerivedView<View>& x) {
116 init(*x.varimp());
117 }
118
119 forceinline bool
120 SubscribedPropagators::operator ()(void) const {
121 return c<ea;
122 }
123 forceinline void
124 SubscribedPropagators::operator ++(void) {
125 c++;
126 }
127 forceinline Propagator&
128 SubscribedPropagators::propagator(void) const {
129 return (c < ep) ? *Propagator::cast(*c) : Advisor::cast(*c)->propagator();
130 }
131
132}
133
134// STATISTICS: kernel-prop