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

Method choice

gecode/int/branch/cbs.hpp:139–206  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

137
138 template<class View>
139 const Choice* CBSBrancher<View>::choice(Space& home) {
140 // Structure for keeping the maximum solution density assignment
141 struct {
142 unsigned int var_id;
143 int val;
144 double dens;
145 } maxSD{0, 0, -1};
146
147 // Lambda we pass to propagators via solndistrib to query solution densities
148 auto SendMarginal = [this](unsigned int prop_id, unsigned int var_id,
149 int val, double dens) {
150 if (logProp[prop_id].dens < dens) {
151 logProp[prop_id].var_id = var_id;
152 logProp[prop_id].val = val;
153 logProp[prop_id].dens = dens;
154 }
155 };
156
157 for (auto& kv : logProp)
158 kv.second.visited = false;
159
160 for (Propagators p(home, PropagatorGroup::all); p(); ++p) {
161 unsigned int prop_id = p.propagator().id();
162 unsigned int domsum;
163 unsigned int domsum_b;
164
165 p.propagator().domainsizesum([this](unsigned int var_id)
166 { return inbrancher(var_id); },
167 domsum, domsum_b);
168
169 // If the propagator doesn't share any unasigned variables with this
170 // brancher, we continue and it will be deleted from the log afterwards.
171 if (domsum_b == 0)
172 continue;
173
174 // New propagators can be created as we solve the problem. If this is the
175 // case we create a new entry in the log.
176 if (logProp.find(prop_id) == logProp.end())
177 logProp.insert(std::make_pair(prop_id, PropInfo{0, 0, 0, -1, true}));
178 else
179 logProp[prop_id].visited = true;
180
181 // If the domain size sum of all variables in the propagator has changed
182 // since the last time we called this function, we need to recompute
183 // solution densities. Otherwise, we can reuse them.
184 if (logProp[prop_id].domsum != domsum) {
185 logProp[prop_id].dens = -1;
186 // Solution density computation
187 p.propagator().solndistrib(home, SendMarginal);
188 logProp[prop_id].domsum = domsum;
189 }
190 }
191
192 // We delete unvisited propagators from the log and look for the highest
193 // solution density across all propagators.
194 for (const auto& kv : logProp) {
195 unsigned int prop_id = kv.first;
196 const PropInfo& info = kv.second;

Callers

nothing calls this directly

Calls 9

propagatorMethod · 0.80
pFunction · 0.50
idMethod · 0.45
domainsizesumMethod · 0.45
findMethod · 0.45
endMethod · 0.45
insertMethod · 0.45
solndistribMethod · 0.45
assignedMethod · 0.45

Tested by

no test coverage detected