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)) {
73 home.notice(*
this, AP_DISPOSE);
75 for (
int i=0;
i<
x.size();
i++)
76 varIdToPos.insert(x[i].
id(), i);
81 CBSBrancher<View>::post(Home home, ViewArray<View>& x) {
82 (void)
new (home) CBSBrancher(home,x);
86 Actor* CBSBrancher<View>::copy(Space& home) {
87 return new (home) CBSBrancher(home,*
this);
92 CBSBrancher<View>::dispose(Space& home) {
93 home.ignore(*
this, AP_DISPOSE);
94 varIdToPos.~VarIdToPos();
95 (void) Brancher::dispose(home);
100 CBSBrancher<View>::CBSBrancher(Space& home, CBSBrancher& b)
102 varIdToPos(
b.varIdToPos),
103 logProp(
b.logProp.begin(),
b.logProp.end(),
104 typename decltype(logProp)::size_type(),
105 typename decltype(logProp)::hasher(),
106 typename decltype(logProp)::key_equal(),
107 typename decltype(logProp)::allocator_type(home)) {
112 bool CBSBrancher<View>::status(
const Space& home)
const {
113 for (Propagators p(home, PropagatorGroup::all); p(); ++p) {
117 unsigned int domsum_b;
121 p.propagator().domainsizesum([
this](
unsigned int var_id)
122 {
return inbrancher(var_id); },
134 CBSBrancher<View>::inbrancher(
unsigned int varId)
const {
135 return varIdToPos.isIn(varId);
139 const Choice* CBSBrancher<View>::choice(Space& home) {
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;
157 for (
auto& kv : logProp)
158 kv.second.visited =
false;
160 for (Propagators p(home, PropagatorGroup::all); p(); ++p) {
161 unsigned int prop_id = p.propagator().id();
163 unsigned int domsum_b;
165 p.propagator().domainsizesum([
this](
unsigned int var_id)
166 {
return inbrancher(var_id); },
176 if (logProp.find(prop_id) == logProp.end())
177 logProp.insert(std::make_pair(prop_id, PropInfo{0, 0, 0, -1,
true}));
179 logProp[prop_id].visited =
true;
184 if (logProp[prop_id].domsum != domsum) {
185 logProp[prop_id].dens = -1;
187 p.propagator().solndistrib(home, SendMarginal);
188 logProp[prop_id].domsum = domsum;
194 for (
const auto& kv : logProp) {
195 unsigned int prop_id = kv.first;
196 const PropInfo& info = kv.second;
198 logProp.erase(prop_id);
199 else if (info.dens > maxSD.dens)
200 maxSD = {info.var_id, info.val, info.dens};
203 assert(maxSD.dens != -1);
204 assert(!x[varIdToPos[maxSD.var_id]].assigned());
205 return new PosValChoice<int>(*
this, 2, varIdToPos[maxSD.var_id], maxSD.val);
210 CBSBrancher<View>::choice(
const Space&, Archive& e) {
213 return new PosValChoice<int>(*
this, 2, pos, val);
218 CBSBrancher<View>::commit(Space& home,
const Choice& c,
unsigned int a) {
219 const auto& pvc =
static_cast<const PosValChoice<int>&
>(
c);
220 int pos = pvc.pos().pos;
230 CBSBrancher<View>::print(
const Space&,
const Choice& c,
unsigned int a,
231 std::ostream& o)
const {
232 const auto& pvc =
static_cast<const PosValChoice<int>&
>(
c);
233 int pos=pvc.pos().pos, val=pvc.val();
235 o <<
"x[" <<
pos <<
"] = " << val;
237 o <<
"x[" <<
pos <<
"] != " << val;
FloatValImpType x
Implementation of float value.
void update(Space &home, VarImpVar< VarImp > &y)
Update this variable to be a clone of variable y.
bool me_failed(ModEvent me)
Check whether modification event me is failed.
bool pos(const View &x)
Test whether x is postive.
Gecode toplevel namespace
@ ES_OK
Execution is okay.
@ ES_FAILED
Execution has resulted in failure.
Post propagator for SetVar x
Gecode::FloatVal c(-8, 8)
Gecode::FloatVal b(9, 12)
Gecode::IntArgs i({1, 2, 3, 4})