Permalink
Browse files

Update to match last gecode trunk version

  • Loading branch information...
Vincent Barichard
Vincent Barichard committed Oct 17, 2016
1 parent eda5af2 commit 5365557509afdf71a9eed1242bba408d31797bde
@@ -123,12 +123,7 @@ class ConnectFourOptions : public Options {
/// Succeed the space
static void gf_success(Space& home) {
Space::Branchers b(home);
while (b()) {
BrancherHandle bh(b.brancher());
++b;
bh.kill(home);
}
Home(home).branchergroup().kill(home);
}
/// Dummy function
View
@@ -100,12 +100,7 @@ class NimFiboOptions : public Options {
/// Succeed the space
static void gf_success(Space& home) {
Space::Branchers b(home);
while (b()) {
BrancherHandle bh(b.brancher());
++b;
bh.kill(home);
}
Home(home).branchergroup().kill(home);
}
/// Dummy function
@@ -156,14 +151,14 @@ class QCSPNimFibo : public Script, public QSpaceInfo {
// Adding Cut
if (opt.cut())
cut(*this, cutExpr1 && cutExpr2 && !(o1 && o2)); // Universal player can't play
cutExpr1 = cutExpr1 && o1;
branch(*this, X[i], INT_VAR_NONE(), INT_VAL_MIN());
} else {
// Existantial Player
rel(*this, o_im1 == (o1 && o2 && oi));
branch(*this, X[i], INT_VAR_NONE(), INT_VAL_MIN());
}
cutExpr1 = cutExpr1 && o1;
cutExpr2 = o2;
cutExpr2 = o1;
o_im1 = oi;
}
}
View
@@ -409,6 +409,8 @@ namespace Gecode { namespace Int { namespace Bool {
virtual Actor* copy(Space& home, bool share);
/// Give advice to propagator
virtual ExecStatus advise(Space& home, Advisor& a, const Delta& d);
/// Schedule function
virtual void reschedule(Space& home);
/// Cost function (defined as low unary)
virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
/// Perform propagation
@@ -414,6 +414,24 @@ namespace Gecode { namespace Int { namespace Bool {
return ES_NOFIX;
}
template<class VX, class VY>
void
QClause<VX,VY>::reschedule(Space& home) {
z.reschedule(home,*this,PC_BOOL_VAL);
if (n_zero == x.size() + y.size())
VX::schedule(home,*this,ME_BOOL_VAL);
for (int i=x.size(); i--; )
if (x[i].one()) {
VX::schedule(home,*this,ME_BOOL_VAL);
return;
}
for (int i=y.size(); i--; )
if (y[i].one()) {
VX::schedule(home,*this,ME_BOOL_VAL);
return;
}
}
template<class VX, class VY>
ExecStatus
QClause<VX,VY>::propagate(Space& home, const ModEventDelta&) {
View
@@ -40,8 +40,8 @@
using namespace std;
namespace Gecode {
BoolVarValPrint QSpaceInfo::customBoolVVP = NULL;
IntVarValPrint QSpaceInfo::customIntVVP = NULL;
BoolVarValPrint QSpaceInfo::customBoolVVP = NULL;
IntVarValPrint QSpaceInfo::customIntVVP = NULL;
bool Strategy::strategyInit() {
assert(bx == NULL);
@@ -214,14 +214,13 @@ namespace Gecode {
}
void
QSpaceInfo::QSpaceSharedInfoO::add(const QSpaceInfo& qsi, const BrancherHandle& bh,
QSpaceInfo::QSpaceSharedInfoO::add(const QSpaceInfo& qsi,
TQuantifier _q,
const BoolVarArgs& x) {
assert(bh.id() == (v.size() + 1));
unsigned int offset = 0;
if (v.size() > 0) offset = v[v.size()-1].offset + v[v.size()-1].size;
v.resize(bh.id());
v[bh.id()-1] = QBI(_q,offset,x.size());
v.resize(v.size() + 1);
v[v.size()-1] = QBI(_q,offset,x.size());
for (int i=0; i<x.size(); i++) {
if (qsi.curStrategyMethod & StrategyMethodValues::EXPAND)
_linkIdVars.push_back(LkBinderVarObj(qsi._boolVars.size()+i,LkBinderVarObj::BOOL));
@@ -230,14 +229,13 @@ namespace Gecode {
}
void
QSpaceInfo::QSpaceSharedInfoO::add(const QSpaceInfo& qsi, const BrancherHandle& bh,
QSpaceInfo::QSpaceSharedInfoO::add(const QSpaceInfo& qsi,
TQuantifier _q,
const IntVarArgs& x) {
assert(bh.id() == (v.size() + 1));
unsigned int offset = 0;
if (v.size() > 0) offset = v[v.size()-1].offset + v[v.size()-1].size;
v.resize(bh.id());
v[bh.id()-1] = QBI(_q,offset,x.size());
v.resize(v.size() + 1);
v[v.size()-1] = QBI(_q,offset,x.size());
for (int i=0; i<x.size() ; i++) {
if (qsi.curStrategyMethod & StrategyMethodValues::EXPAND)
_linkIdVars.push_back(LkBinderVarObj(qsi._intVars.size()+i,LkBinderVarObj::INT));
@@ -314,62 +312,59 @@ namespace Gecode {
}
void
QSpaceInfo::QSpaceSharedInfo::add(const QSpaceInfo& qsi, const BrancherHandle& bh,
QSpaceInfo::QSpaceSharedInfo::add(const QSpaceInfo& qsi,
TQuantifier _q,
const IntVarArgs& x) {
static_cast<QSpaceSharedInfoO*>(object())->add(qsi,bh,_q,x);
static_cast<QSpaceSharedInfoO*>(object())->add(qsi,_q,x);
}
void
QSpaceInfo::QSpaceSharedInfo::add(const QSpaceInfo& qsi, const BrancherHandle& bh,
QSpaceInfo::QSpaceSharedInfo::add(const QSpaceInfo& qsi,
TQuantifier _q,
const BoolVarArgs& x) {
static_cast<QSpaceSharedInfoO*>(object())->add(qsi,bh,_q,x);
static_cast<QSpaceSharedInfoO*>(object())->add(qsi,_q,x);
}
void
QSpaceInfo::updateQSpaceInfo(const BrancherHandle& bh,
TQuantifier _q,
QSpaceInfo::updateQSpaceInfo(TQuantifier _q,
const BoolVarArgs& x) {
sharedInfo.add(*this,bh,_q,x);
sharedInfo.add(*this,_q,x);
if (curStrategyMethod & StrategyMethodValues::EXPAND)
_boolVars = BoolVarArray(dynamic_cast<Space&>(*this),_boolVars+x);
}
void
QSpaceInfo::updateQSpaceInfo(const BrancherHandle& bh,
TQuantifier _q,
QSpaceInfo::updateQSpaceInfo(TQuantifier _q,
const IntVarArgs& x) {
sharedInfo.add(*this,bh,_q,x);
sharedInfo.add(*this,_q,x);
if (curStrategyMethod & StrategyMethodValues::EXPAND)
_intVars = IntVarArray(dynamic_cast<Space&>(*this),_intVars+x);
}
template<class BranchType> std::vector<BrancherHandle>
template<class BranchType> void
QSpaceInfo::branch(Home home, const BoolVar& x, BranchType vars, IntValBranch vals, BoolBranchFilter bf, BoolVarValPrint vvp) {
BoolVarArgs vaX;
vaX << x;
return this->branch<BranchType>(home,vaX,vars,vals,bf,vvp);
}
template QUACODE_EXPORT std::vector<BrancherHandle> QSpaceInfo::branch<>(Home home, const BoolVar& x, IntVarBranch vars, IntValBranch vals, BoolBranchFilter bf, BoolVarValPrint vvp);
template QUACODE_EXPORT std::vector<BrancherHandle> QSpaceInfo::branch<>(Home home, const BoolVar& x, TieBreak<IntVarBranch> vars, IntValBranch vals, BoolBranchFilter bf, BoolVarValPrint vvp);
template QUACODE_EXPORT void QSpaceInfo::branch<>(Home home, const BoolVar& x, IntVarBranch vars, IntValBranch vals, BoolBranchFilter bf, BoolVarValPrint vvp);
template QUACODE_EXPORT void QSpaceInfo::branch<>(Home home, const BoolVar& x, TieBreak<IntVarBranch> vars, IntValBranch vals, BoolBranchFilter bf, BoolVarValPrint vvp);
template<class BranchType> std::vector<BrancherHandle>
template<class BranchType> void
QSpaceInfo::branch(Home home, const IntVar& x, BranchType vars, IntValBranch vals, IntBranchFilter bf, IntVarValPrint vvp) {
IntVarArgs vaX;
vaX << x;
return this->branch<BranchType>(home,vaX,vars,vals,bf,vvp);
}
template QUACODE_EXPORT std::vector<BrancherHandle> QSpaceInfo::branch<>(Home home, const IntVar& x, IntVarBranch vars, IntValBranch vals, IntBranchFilter bf, IntVarValPrint vvp);
template QUACODE_EXPORT std::vector<BrancherHandle> QSpaceInfo::branch<>(Home home, const IntVar& x, TieBreak<IntVarBranch> vars, IntValBranch vals, IntBranchFilter bf, IntVarValPrint vvp);
template QUACODE_EXPORT void QSpaceInfo::branch<>(Home home, const BoolVarArgs& x, IntVarBranch vars, IntValBranch vals, BoolBranchFilter bf, BoolVarValPrint vvp);
template QUACODE_EXPORT void QSpaceInfo::branch<>(Home home, const BoolVarArgs& x, TieBreak<IntVarBranch> vars, IntValBranch vals, BoolBranchFilter bf, BoolVarValPrint vvp);
template<class BranchType> std::vector<BrancherHandle>
template<class BranchType> void
QSpaceInfo::branch(Home home, const BoolVarArgs& x, BranchType vars, IntValBranch vals, BoolBranchFilter bf, BoolVarValPrint vvp) {
std::vector<BrancherHandle> result;
assert(x.size() > 0);
if (home.failed()) return result;
if (home.failed()) return;
// Get the quantifier of the first variable of the quantifier
TQuantifier curQ = EXISTS;
@@ -396,32 +391,27 @@ namespace Gecode {
}
// Add brancher for unwatched variables
BrancherHandle bh;
if (vvp) {
customBoolVVP = vvp;
bh = Gecode::branch(home,UW_X,vars,vals,bf,&tripleChoice);
customBoolVVP = vvp;
Gecode::branch(home,UW_X,vars,vals,bf,&tripleChoice);
} else {
bh = Gecode::branch(home,UW_X,vars,vals,bf,&doubleChoice);
Gecode::branch(home,UW_X,vars,vals,bf,&doubleChoice);
}
// Update shared info
updateQSpaceInfo(bh,curQ,UW_X);
result.push_back(bh);
updateQSpaceInfo(curQ,UW_X);
// Update current quantifier
curQ = qi;
}
return result;
}
template QUACODE_EXPORT std::vector<BrancherHandle> QSpaceInfo::branch<>(Home home, const BoolVarArgs& x, IntVarBranch vars, IntValBranch vals, BoolBranchFilter bf, BoolVarValPrint vvp);
template QUACODE_EXPORT std::vector<BrancherHandle> QSpaceInfo::branch<>(Home home, const BoolVarArgs& x, TieBreak<IntVarBranch> vars, IntValBranch vals, BoolBranchFilter bf, BoolVarValPrint vvp);
template QUACODE_EXPORT void QSpaceInfo::branch<>(Home home, const IntVar& x, IntVarBranch vars, IntValBranch vals, IntBranchFilter bf, IntVarValPrint vvp);
template QUACODE_EXPORT void QSpaceInfo::branch<>(Home home, const IntVar& x, TieBreak<IntVarBranch> vars, IntValBranch vals, IntBranchFilter bf, IntVarValPrint vvp);
template<class BranchType> std::vector<BrancherHandle>
template<class BranchType> void
QSpaceInfo::branch(Home home, const IntVarArgs& x, BranchType vars, IntValBranch vals, IntBranchFilter bf, IntVarValPrint vvp) {
std::vector<BrancherHandle> result;
assert(x.size() > 0);
if (home.failed()) return result;
if (home.failed()) return;
// Get the quantifier of the first variable of the quantifier
TQuantifier curQ = EXISTS;
@@ -448,25 +438,21 @@ namespace Gecode {
}
// Add brancher for unwatched variables
BrancherHandle bh;
if (vvp) {
customIntVVP = vvp;
bh = Gecode::branch(home,UW_X,vars,vals,bf,&tripleChoice);
customIntVVP = vvp;
Gecode::branch(home,UW_X,vars,vals,bf,&tripleChoice);
} else {
bh = Gecode::branch(home,UW_X,vars,vals,bf,&doubleChoice);
Gecode::branch(home,UW_X,vars,vals,bf,&doubleChoice);
}
// Update shared info
updateQSpaceInfo(bh,curQ,UW_X);
result.push_back(bh);
updateQSpaceInfo(curQ,UW_X);
// Update current quantifier
curQ = qi;
}
return result;
}
template QUACODE_EXPORT std::vector<BrancherHandle> QSpaceInfo::branch<>(Home home, const IntVarArgs& x, IntVarBranch vars, IntValBranch vals, IntBranchFilter bf, IntVarValPrint vvp);
template QUACODE_EXPORT std::vector<BrancherHandle> QSpaceInfo::branch<>(Home home, const IntVarArgs& x, TieBreak<IntVarBranch> vars, IntValBranch vals, IntBranchFilter bf, IntVarValPrint vvp);
template QUACODE_EXPORT void QSpaceInfo::branch<>(Home home, const IntVarArgs& x, IntVarBranch vars, IntValBranch vals, IntBranchFilter bf, IntVarValPrint vvp);
template QUACODE_EXPORT void QSpaceInfo::branch<>(Home home, const IntVarArgs& x, TieBreak<IntVarBranch> vars, IntValBranch vals, IntBranchFilter bf, IntVarValPrint vvp);
}
View
@@ -409,9 +409,9 @@ namespace Gecode {
virtual SharedHandle::Object* copy(void) const { return new QSpaceSharedInfoO(*this); }
/// Add new quantified brancher information
void add(const QSpaceInfo& qsi, const BrancherHandle& bh, TQuantifier _q, const BoolVarArgs& x);
void add(const QSpaceInfo& qsi, TQuantifier _q, const BoolVarArgs& x);
/// Add new quantified brancher information
void add(const QSpaceInfo& qsi, const BrancherHandle& bh, TQuantifier _q, const IntVarArgs& x);
void add(const QSpaceInfo& qsi, TQuantifier _q, const IntVarArgs& x);
/// Return the quantifier used for the brancher \a bh
forceinline TQuantifier brancherQuantifier(unsigned int id) const { return v[id-1].quantifier; }
/// Return the offset computed when the brancher \a bh was added
@@ -448,8 +448,8 @@ namespace Gecode {
/// Initialise for use
void init(StrategyMethod sm);
/// Add new brancher information
void add(const QSpaceInfo& qsi, const BrancherHandle& bh, TQuantifier _q, const IntVarArgs& x);
void add(const QSpaceInfo& qsi, const BrancherHandle& bh, TQuantifier _q, const BoolVarArgs& x);
void add(const QSpaceInfo& qsi, TQuantifier _q, const IntVarArgs& x);
void add(const QSpaceInfo& qsi, TQuantifier _q, const BoolVarArgs& x);
/// SharedInfo access
/// Return the quantifier used for the brancher \a id
@@ -480,8 +480,8 @@ namespace Gecode {
};
/// Wrapper function to record choice in scenario
static void scenarioChoice(const Space &home, const BrancherHandle& bh, unsigned int a, BoolVar x, int i, const int& n, std::ostream& );
static void scenarioChoice(const Space &home, const BrancherHandle& bh, unsigned int a, IntVar x, int i, const int& n, std::ostream& );
static void scenarioChoice(const Space &home, unsigned int a, BoolVar x, int i, const int& n, std::ostream& );
static void scenarioChoice(const Space &home, unsigned int a, IntVar x, int i, const int& n, std::ostream& );
/// The following arrays are not maintained during cloning !!!
/// Only meaningful during modeling
@@ -516,10 +516,10 @@ namespace Gecode {
/// Array of all integer variables to branch with
IntVarArray _intVars;
/// Update QSpace with data from brancher handle \a bh which contains variables \a x quantified with
/// Update QSpace with variables \a x quantified with
/// quantifier \a _q. It will also update data shared by all clones.
QUACODE_EXPORT void updateQSpaceInfo(const BrancherHandle& bh, TQuantifier _q, const IntVarArgs& x);
QUACODE_EXPORT void updateQSpaceInfo(const BrancherHandle& bh, TQuantifier _q, const BoolVarArgs& x);
QUACODE_EXPORT void updateQSpaceInfo(TQuantifier _q, const IntVarArgs& x);
QUACODE_EXPORT void updateQSpaceInfo(TQuantifier _q, const BoolVarArgs& x);
private:
/// Copy Constructor (disabled)
QSpaceInfo(const QSpaceInfo& qs);
@@ -583,19 +583,18 @@ namespace Gecode {
/// Wrapper function to print data during branching
static BoolVarValPrint customBoolVVP;
static IntVarValPrint customIntVVP;
template <class VarType> static void runCustomChoice(const Space &home, const BrancherHandle& bh, unsigned int alt, VarType x, int pos, const int& val, std::ostream& os);
template <class VarType> static void doubleChoice(const Space &home, const BrancherHandle& bh, unsigned int alt, VarType x, int pos, const int& val, std::ostream& os);
template <class VarType> static void tripleChoice(const Space &home, const BrancherHandle& bh, unsigned int alt, VarType x, int pos, const int& val, std::ostream& os);
template <class VarType> static void runCustomChoice(const Space &home, const Brancher& bh, unsigned int alt, VarType x, int pos, const int& val, std::ostream& os);
template <class VarType> static void doubleChoice(const Space &home, const Brancher& bh, unsigned int alt, VarType x, int pos, const int& val, std::ostream& os);
template <class VarType> static void tripleChoice(const Space &home, const Brancher& bh, unsigned int alt, VarType x, int pos, const int& val, std::ostream& os);
/// Branch over boolean variable \a x, quantified variable selection \a vars and value selection \a vals
template <class BranchType> QUACODE_EXPORT std::vector<BrancherHandle> branch(Home home, const BoolVar& x, BranchType vars, IntValBranch vals, BoolBranchFilter bf=NULL, BoolVarValPrint vvp=NULL);
template <class BranchType> QUACODE_EXPORT void branch(Home home, const BoolVar& x, BranchType vars, IntValBranch vals, BoolBranchFilter bf=NULL, BoolVarValPrint vvp=NULL);
/// Branch over boolean variables \a x, quantified variable selection \a vars and value selection \a vals
template <class BranchType> QUACODE_EXPORT std::vector<BrancherHandle> branch(Home home, const BoolVarArgs& x, BranchType vars, IntValBranch vals, BoolBranchFilter bf=NULL, BoolVarValPrint vvp=NULL);
template <class BranchType> QUACODE_EXPORT void branch(Home home, const BoolVarArgs& x, BranchType vars, IntValBranch vals, BoolBranchFilter bf=NULL, BoolVarValPrint vvp=NULL);
/// Branch over integer variable \a x, quantified variable selection \a vars and value selection \a vals
template <class BranchType> QUACODE_EXPORT std::vector<BrancherHandle> branch(Home home, const IntVar& x, BranchType vars, IntValBranch vals, IntBranchFilter bf=NULL, IntVarValPrint vvp=NULL);
template <class BranchType> QUACODE_EXPORT void branch(Home home, const IntVar& x, BranchType vars, IntValBranch vals, IntBranchFilter bf=NULL, IntVarValPrint vvp=NULL);
/// Branch over integer variables \a x, quantified variable selection \a vars and value selection \a vals
template <class BranchType> QUACODE_EXPORT std::vector<BrancherHandle> branch(Home home, const IntVarArgs& x, BranchType vars, IntValBranch vals, IntBranchFilter bf=NULL, IntVarValPrint vvp=NULL);
template <class BranchType> QUACODE_EXPORT void branch(Home home, const IntVarArgs& x, BranchType vars, IntValBranch vals, IntBranchFilter bf=NULL, IntVarValPrint vvp=NULL);
};
}
View
@@ -662,25 +662,24 @@ namespace Gecode {
}
template<class VarType> forceinline
void QSpaceInfo::doubleChoice (const Space &home, const BrancherHandle& bh,
unsigned int,
void QSpaceInfo::doubleChoice (const Space &home, const Brancher& bh, unsigned int,
VarType x, int pos, const int&,
std::ostream& ) {
const QSpaceInfo& qsi = dynamic_cast<const QSpaceInfo&>(home);
if (qsi.bRecordStrategy) const_cast<QSpaceInfo&>(qsi).sharedInfo.scenarioChoice(bh.id(),pos,x.min(),x.max());
if (qsi.bRecordStrategy) const_cast<QSpaceInfo&>(qsi).sharedInfo.scenarioChoice(bh.id(),pos,x.min(),x.max());
}
template<> forceinline
void QSpaceInfo::runCustomChoice (const Space &home, const BrancherHandle& bh,
void QSpaceInfo::runCustomChoice (const Space &home, const Brancher& bh,
unsigned int alt,
BoolVar x, int pos, const int& val,
std::ostream& os) {
assert(QSpaceInfo::customBoolVVP);
(*QSpaceInfo::customBoolVVP)(home,bh,alt,x,pos,val,os);
}
template<> forceinline
void QSpaceInfo::runCustomChoice (const Space &home, const BrancherHandle& bh,
template<> forceinline
void QSpaceInfo::runCustomChoice (const Space &home, const Brancher& bh,
unsigned int alt,
IntVar x, int pos, const int& val,
std::ostream& os) {
@@ -689,7 +688,7 @@ namespace Gecode {
}
template<class VarType> forceinline
void QSpaceInfo::tripleChoice (const Space &home, const BrancherHandle& bh,
void QSpaceInfo::tripleChoice (const Space &home, const Brancher& bh,
unsigned int alt,
VarType x, int pos, const int& val,
std::ostream& os) {
Oops, something went wrong.

0 comments on commit 5365557

Please sign in to comment.