MCPcopy Create free account
hub / github.com/Gecode/gecode / propagate

Method propagate

gecode/int/channel/link-multi.cpp:121–231  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

119 }
120
121 ExecStatus
122 LinkMulti::propagate(Space& home, const ModEventDelta& med) {
123 int n = x.size();
124
125 // Always maintain the invariant that y lies inside the x-array
126 assert((y.min()-o >= 0) && (y.max()-o < n));
127
128 if (y.assigned()) {
129 status = S_RUN;
130 int j=y.val()-o;
131 GECODE_ME_CHECK(x[j].one(home));
132 for (int i=0; i<j; i++)
133 GECODE_ME_CHECK(x[i].zero(home));
134 for (int i=j+1; i<n; i++)
135 GECODE_ME_CHECK(x[i].zero(home));
136 return home.ES_SUBSUMED(*this);
137 }
138
139 // Check whether there is a one
140 if (status == S_ONE) {
141 status = S_RUN;
142 for (int i=0; true; i++)
143 if (x[i].one()) {
144 for (int j=0; j<i; j++)
145 GECODE_ME_CHECK(x[j].zero(home));
146 for (int j=i+1; j<n; j++)
147 GECODE_ME_CHECK(x[j].zero(home));
148 GECODE_ME_CHECK(y.eq(home,i+o));
149 return home.ES_SUBSUMED(*this);
150 }
151 GECODE_NEVER;
152 }
153
154 status = S_RUN;
155
156 redo:
157
158 // Assign all Boolean views to zero that are outside bounds
159 {
160 int min=y.min()-o;
161 for (int i=0; i<min; i++)
162 GECODE_ME_CHECK(x[i].zero(home));
163 x.drop_fst(min); o += min; n = x.size();
164
165 int max=y.max()-o;
166 for (int i=max+1; i<n; i++)
167 GECODE_ME_CHECK(x[i].zero(home));
168 x.drop_lst(max); n = x.size();
169 }
170
171 {
172 // Remove zeros on the left
173 int i=0;
174 while ((i < n) && x[i].zero()) i++;
175 if (i >= n)
176 return ES_FAILED;
177 x.drop_fst(i); o += i; n = x.size();
178 }

Callers

nothing calls this directly

Calls 15

ES_SUBSUMEDMethod · 0.80
drop_fstMethod · 0.80
drop_lstMethod · 0.80
sizeMethod · 0.45
minMethod · 0.45
maxMethod · 0.45
assignedMethod · 0.45
valMethod · 0.45
oneMethod · 0.45
zeroMethod · 0.45
eqMethod · 0.45
gqMethod · 0.45

Tested by

no test coverage detected