36 namespace Gecode {
namespace Int {
namespace Branch {
40 CBSBrancher<View>::VarIdToPos::init() {
41 assert(
object() ==
nullptr);
42 object(
new VarIdToPosO());
47 CBSBrancher<View>::VarIdToPos::isIn(
unsigned int var_id)
const {
48 auto *hm = &
static_cast<VarIdToPosO*
>(object())->_varIdToPos;
49 return hm->find(var_id) != hm->end();
54 CBSBrancher<View>::VarIdToPos::operator[](
unsigned int i)
const {
55 return static_cast<VarIdToPosO*
>(object())->_varIdToPos.at(i);
60 CBSBrancher<View>::VarIdToPos::insert(
unsigned int var_id,
62 static_cast<VarIdToPosO*
>(object())
63 ->_varIdToPos.insert(std::make_pair(var_id, pos));
67 CBSBrancher<View>::CBSBrancher(Home home, ViewArray<View>& x0)
68 : Brancher(home),
x(x0),
69 logProp(typename decltype(logProp)::size_type(),
70 typename decltype(logProp)::hasher(),
71 typename decltype(logProp)::key_equal(),
72 typename decltype(logProp)::allocator_type(home)) {
75 varIdToPos.insert(
x[
i].id(),
i);
81 (void)
new (home) CBSBrancher(home,x);
86 return new (home) CBSBrancher(home,*
this);
91 CBSBrancher<View>::dispose(
Space& home) {
98 CBSBrancher<View>::CBSBrancher(
Space& home, CBSBrancher&
b)
100 varIdToPos(b.varIdToPos),
101 logProp(b.logProp.begin(), b.logProp.end(),
102 typename decltype(logProp)::size_type(),
103 typename decltype(logProp)::hasher(),
104 typename decltype(logProp)::key_equal(),
105 typename decltype(logProp)::allocator_type(home)) {
110 bool CBSBrancher<View>::status(
const Space& home)
const {
115 unsigned int domsum_b;
119 p.propagator().domainsizesum([
this](
unsigned int var_id)
120 {
return inbrancher(var_id); },
132 CBSBrancher<View>::inbrancher(
unsigned int varId)
const {
133 return varIdToPos.isIn(varId);
137 const Choice* CBSBrancher<View>::choice(
Space& home) {
146 auto SendMarginal = [
this](
unsigned int prop_id,
unsigned int var_id,
147 int val,
double dens) {
148 if (logProp[prop_id].dens < dens) {
149 logProp[prop_id].var_id = var_id;
150 logProp[prop_id].val = val;
151 logProp[prop_id].dens = dens;
155 for (
auto& kv : logProp)
156 kv.second.visited =
false;
159 unsigned int prop_id =
p.propagator().id();
161 unsigned int domsum_b;
163 p.propagator().domainsizesum([
this](
unsigned int var_id)
164 {
return inbrancher(var_id); },
174 if (logProp.find(prop_id) == logProp.end())
175 logProp.insert(std::make_pair(prop_id, PropInfo{0, 0, 0, -1, true}));
177 logProp[prop_id].visited =
true;
182 if (logProp[prop_id].domsum != domsum) {
183 logProp[prop_id].dens = -1;
185 p.propagator().solndistrib(home, SendMarginal);
186 logProp[prop_id].domsum = domsum;
192 for (
const auto& kv : logProp) {
193 unsigned int prop_id = kv.first;
194 const PropInfo& info = kv.second;
196 logProp.erase(prop_id);
197 else if (info.dens > maxSD.dens)
198 maxSD = {info.var_id, info.val, info.dens};
201 assert(maxSD.dens != -1);
202 assert(!x[varIdToPos[maxSD.var_id]].assigned());
203 return new PosValChoice<int>(*
this, 2, varIdToPos[maxSD.var_id], maxSD.val);
208 CBSBrancher<View>::choice(
const Space&, Archive& e) {
211 return new PosValChoice<int>(*
this, 2,
pos, val);
216 CBSBrancher<View>::commit(
Space& home,
const Choice&
c,
unsigned int a) {
217 const auto& pvc =
static_cast<const PosValChoice<int>&
>(
c);
218 int pos = pvc.pos().pos;
229 std::ostream& o)
const {
230 const auto& pvc =
static_cast<const PosValChoice<int>&
>(
c);
231 int pos=pvc.pos().pos, val=pvc.val();
233 o <<
"x[" << pos <<
"] = " << val;
235 o <<
"x[" << pos <<
"] != " << val;
void post(Home home, Term *t, int n, FloatRelType frt, FloatVal c)
Post propagator for linear constraint over floats.
Actor must always be disposed.
static PropagatorGroup all
Group of all propagators.
bool pos(const View &x)
Test whether x is postive.
ViewArray< VX > x
Array of views.
int p
Number of positive literals for node type.
Gecode::IntArgs i({1, 2, 3, 4})
Execution has resulted in failure.
Council< Advisor > c
The advisor council.
struct Gecode::@593::NNF::@62::@63 b
For binary nodes (and, or, eqv)
void print(std::basic_ostream< Char, Traits > &s, bool assigned, IL &lb, IU &ub, unsigned int cardMin, unsigned int cardMax)
Print set view.
virtual size_t dispose(Space &home)
Delete actor and return its size.
Post propagator for SetVar x
Gecode toplevel namespace
int size(void) const
Return size of array (number of elements)
struct Gecode::@593::NNF::@62::@64 a
For atomic nodes.
bool me_failed(ModEvent me)
Check whether modification event me is failed.