#include <gecode/int.hh>
#include <gecode/search.hh>
#include <iostream> // for std::cout
#include <utility> // for std::pair
#include <algorithm> // for std::for_each
using namespace std;
using namespace Gecode;
class Dom : public Propagator
{
protected:
ViewArray<Int::BoolView> G;
ViewArray<Int::BoolView> D;
int s;
public:
// posting
Dom(Space &home, ViewArray<Int::BoolView> &_G, ViewArray<Int::BoolView> &_D, int _s)
: Propagator(home), G(_G), D(_D), s(_s)
{
G.subscribe(home, *this, Int::PC_BOOL_VAL);
D.subscribe(home, *this, Int::PC_BOOL_VAL);
}
static ExecStatus post(Space &home,
ViewArray<Int::BoolView> G, ViewArray<Int::BoolView> D, int s)
{
(void)new (home) Dom(home, G, D, s);
return ES_OK;
}
// disposal
virtual size_t dispose(Space &home)
{
G.cancel(home, *this, Int::PC_BOOL_VAL);
D.cancel(home, *this, Int::PC_BOOL_VAL);
(void)Propagator::dispose(home);
return sizeof(*this);
}
// copying
Dom(Space &home, Dom &p)
: Propagator(home, p)
{
G.update(home, p.G);
D.update(home, p.D);
}
virtual Propagator *copy(Space &home)
{
return new (home) Dom(home, *this);
}
// cost computation
virtual PropCost cost(const Space &, const ModEventDelta &) const
{
return PropCost::binary(PropCost::HI);
}
// re-scheduling
virtual void reschedule(Space &home)
{
G.reschedule(home, *this, Int::PC_BOOL_VAL);
D.reschedule(home, *this, Int::PC_BOOL_VAL);
}
// propagation
virtual ExecStatus propagate(Space &home, const ModEventDelta &)
{
std::cout << "dom propagate\n";
return ES_NOFIX;
}
};
class testDom : public Space
{
protected:
BoolVarArray l;
public:
testDom(void) : l(*this, 100, 0, 1)
{
//rel(*this, BoolVar(l[0]), IRT_EQ, 0);
BoolVarArgs _foo(l);
dom(_foo, _foo, 1);
//branch(*this, l, BOOL_VAR_NONE(), BOOL_VAL_MIN());
}
// search support
testDom(testDom &s) : Space(s)
{
l.update(*this, s.l);
}
virtual Space *copy(void)
{
return new testDom(*this);
}
void dom(BoolVarArgs _G, BoolVarArgs _D, int s)
{
ViewArray<Int::BoolView> G(*this, _G);
ViewArray<Int::BoolView> D(*this, _D);
if (Dom::post(*this, G, D, s) != ES_OK)
this->fail();
}
// print solution
void print(void) const
{
std::cout << l << std::endl;
}
};
// main function
int main(int argc, char *argv[])
{
testDom *m = new testDom;
(void)m->status();
m->print();
return 0;
}