flatzinc.cpp
Go to the documentation of this file.
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
* Main authors:
* Guido Tack <tack@gecode.org>
*
* Contributing authors:
* Gabriel Hjort Blindell <gabriel.hjort.blindell@gmail.com>
*
* Copyright:
* Guido Tack, 2007-2012
* Gabriel Hjort Blindell, 2012
*
* This file is part of Gecode, the generic constraint
* development environment:
* http://www.gecode.org
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#include <gecode/flatzinc.hh>
#include <gecode/flatzinc/registry.hh>
#include <gecode/flatzinc/plugin.hh>
#include <gecode/flatzinc/branch.hh>
#include <gecode/search.hh>
#include <vector>
#include <string>
#include <sstream>
#include <limits>
#include <unordered_set>
namespace std {
template<> struct hash<Gecode::TupleSet> {
forceinline size_t
operator()(const Gecode::TupleSet& x) const {
return x.hash();
}
};
template<> struct hash<Gecode::SharedArray<int> > {
forceinline size_t
operator()(const Gecode::SharedArray<int>& x) const {
size_t seed = static_cast<size_t>(x.size());
for (int i=x.size(); i--; )
Gecode::cmb_hash(seed, x[i]);
return seed;
}
};
template<> struct hash<Gecode::DFA> {
forceinline size_t operator()(const Gecode::DFA& d) const {
return d.hash();
}
};
}
namespace Gecode { namespace FlatZinc {
// Default random number generator
Rnd defrnd(0);
class AuxVarBrancher : public Brancher {
protected:
bool done;
AuxVarBrancher(Home home, TieBreak<IntVarBranch> int_varsel0,
IntValBranch int_valsel0,
TieBreak<BoolVarBranch> bool_varsel0,
BoolValBranch bool_valsel0
#ifdef GECODE_HAS_SET_VARS
,
SetVarBranch set_varsel0,
SetValBranch set_valsel0
#endif
#ifdef GECODE_HAS_FLOAT_VARS
,
TieBreak<FloatVarBranch> float_varsel0,
FloatValBranch float_valsel0
#endif
)
: Brancher(home), done(false),
int_varsel(int_varsel0), int_valsel(int_valsel0),
bool_varsel(bool_varsel0), bool_valsel(bool_valsel0)
#ifdef GECODE_HAS_SET_VARS
, set_varsel(set_varsel0), set_valsel(set_valsel0)
#endif
#ifdef GECODE_HAS_FLOAT_VARS
, float_varsel(float_varsel0), float_valsel(float_valsel0)
#endif
{}
AuxVarBrancher(Space& home, AuxVarBrancher& b)
: Brancher(home, b), done(b.done) {}
class Choice : public Gecode::Choice {
public:
bool fail;
Choice(const Brancher& b, bool fail0)
: Gecode::Choice(b,1), fail(fail0) {}
virtual size_t size(void) const {
return sizeof(Choice);
}
virtual void archive(Archive& e) const {
Gecode::Choice::archive(e);
e.put(fail);
}
};
TieBreak<IntVarBranch> int_varsel;
IntValBranch int_valsel;
TieBreak<BoolVarBranch> bool_varsel;
BoolValBranch bool_valsel;
#ifdef GECODE_HAS_SET_VARS
SetVarBranch set_varsel;
SetValBranch set_valsel;
#endif
#ifdef GECODE_HAS_FLOAT_VARS
TieBreak<FloatVarBranch> float_varsel;
FloatValBranch float_valsel;
#endif
public:
virtual bool status(const Space& _home) const {
if (done) return false;
const FlatZincSpace& home = static_cast<const FlatZincSpace&>(_home);
for (int i=0; i<home.iv_aux.size(); i++)
if (!home.iv_aux[i].assigned()) return true;
for (int i=0; i<home.bv_aux.size(); i++)
if (!home.bv_aux[i].assigned()) return true;
#ifdef GECODE_HAS_SET_VARS
for (int i=0; i<home.sv_aux.size(); i++)
if (!home.sv_aux[i].assigned()) return true;
#endif
#ifdef GECODE_HAS_FLOAT_VARS
for (int i=0; i<home.fv_aux.size(); i++)
if (!home.fv_aux[i].assigned()) return true;
#endif
// No non-assigned variables left
return false;
}
virtual Choice* choice(Space& home) {
done = true;
FlatZincSpace& fzs = static_cast<FlatZincSpace&>(*home.clone());
fzs.needAuxVars = false;
branch(fzs,fzs.iv_aux,int_varsel,int_valsel);
branch(fzs,fzs.bv_aux,bool_varsel,bool_valsel);
#ifdef GECODE_HAS_SET_VARS
branch(fzs,fzs.sv_aux,set_varsel,set_valsel);
#endif
#ifdef GECODE_HAS_FLOAT_VARS
branch(fzs,fzs.fv_aux,float_varsel,float_valsel);
#endif
Search::Options opt; opt.clone = false;
FlatZincSpace* sol = dfs(&fzs, opt);
if (sol) {
delete sol;
return new Choice(*this,false);
} else {
return new Choice(*this,true);
}
}
virtual Choice* choice(const Space&, Archive& e) {
bool fail; e >> fail;
return new Choice(*this, fail);
}
virtual ExecStatus commit(Space&, const Gecode::Choice& c, unsigned int) {
return static_cast<const Choice&>(c).fail ? ES_FAILED : ES_OK;
}
virtual void print(const Space&, const Gecode::Choice& c,
unsigned int,
std::ostream& o) const {
o << "FlatZinc("
<< (static_cast<const Choice&>(c).fail ? "fail" : "ok")
<< ")";
}
virtual Actor* copy(Space& home) {
return new (home) AuxVarBrancher(home, *this);
}
static void post(Home home,
TieBreak<IntVarBranch> int_varsel,
IntValBranch int_valsel,
TieBreak<BoolVarBranch> bool_varsel,
BoolValBranch bool_valsel
#ifdef GECODE_HAS_SET_VARS
,
SetVarBranch set_varsel,
SetValBranch set_valsel
#endif
#ifdef GECODE_HAS_FLOAT_VARS
,
TieBreak<FloatVarBranch> float_varsel,
FloatValBranch float_valsel
#endif
) {
(void) new (home) AuxVarBrancher(home, int_varsel, int_valsel,
bool_varsel, bool_valsel
#ifdef GECODE_HAS_SET_VARS
, set_varsel, set_valsel
#endif
#ifdef GECODE_HAS_FLOAT_VARS
, float_varsel, float_valsel
#endif
);
}
virtual size_t dispose(Space&) {
return sizeof(*this);
}
};
class BranchInformationO : public SharedHandle::Object {
private:
struct BI {
std::string r0;
std::string r1;
std::vector<std::string> n;
BI(void) : r0(""), r1(""), n(0) {}
BI(const std::string& r00, const std::string& r10,
const std::vector<std::string>& n0)
: r0(r00), r1(r10), n(n0) {}
};
std::vector<BI> v;
BranchInformationO(std::vector<BI> v0) : v(v0) {}
public:
BranchInformationO(void) {}
virtual ~BranchInformationO(void) {}
virtual SharedHandle::Object* copy(void) const {
return new BranchInformationO(v);
}
void add(BrancherGroup bg,
const std::string& rel0,
const std::string& rel1,
const std::vector<std::string>& n) {
v.resize(std::max(static_cast<unsigned int>(v.size()),bg.id()+1));
v[bg.id()] = BI(rel0,rel1,n);
}
void print(const Brancher& b,
unsigned int a, int i, int n, std::ostream& o) const {
const BI& bi = v[b.group().id()];
o << bi.n[i] << " " << (a==0 ? bi.r0 : bi.r1) << " " << n;
}
#ifdef GECODE_HAS_FLOAT_VARS
void print(const Brancher& b,
unsigned int a, int i, const FloatNumBranch& nl,
std::ostream& o) const {
const BI& bi = v[b.group().id()];
o << bi.n[i] << " "
<< (((a == 0) == nl.l) ? "<=" : ">=") << nl.n;
}
#endif
};
BranchInformation::BranchInformation(void)
: SharedHandle(NULL) {}
BranchInformation::BranchInformation(const BranchInformation& bi)
: SharedHandle(bi) {}
void
BranchInformation::init(void) {
assert(object() == NULL);
object(new BranchInformationO());
}
void
BranchInformation::add(BrancherGroup bg,
const std::string& rel0,
const std::string& rel1,
const std::vector<std::string>& n) {
static_cast<BranchInformationO*>(object())->add(bg,rel0,rel1,n);
}
void
BranchInformation::print(const Brancher& b, unsigned int a, int i,
int n, std::ostream& o) const {
static_cast<const BranchInformationO*>(object())->print(b,a,i,n,o);
}
#ifdef GECODE_HAS_FLOAT_VARS
void
BranchInformation::print(const Brancher& b, unsigned int a, int i,
const FloatNumBranch& nl, std::ostream& o) const {
static_cast<const BranchInformationO*>(object())->print(b,a,i,nl,o);
}
#endif
template<class Var>
void varValPrint(const Space &home, const Brancher& b,
unsigned int a,
Var, int i, const int& n,
std::ostream& o) {
static_cast<const FlatZincSpace&>(home).branchInfo.print(b,a,i,n,o);
}
#ifdef GECODE_HAS_FLOAT_VARS
void varValPrintF(const Space &home, const Brancher& b,
unsigned int a,
FloatVar, int i, const FloatNumBranch& nl,
std::ostream& o) {
static_cast<const FlatZincSpace&>(home).branchInfo.print(b,a,i,nl,o);
}
#endif
IntSet vs2is(IntVarSpec* vs) {
if (vs->assigned) {
return IntSet(vs->i,vs->i);
}
if (vs->domain()) {
AST::SetLit* sl = vs->domain.some();
if (sl->interval) {
return IntSet(sl->min, sl->max);
} else {
int* newdom = heap.alloc<int>(static_cast<unsigned long int>(sl->s.size()));
for (int i=sl->s.size(); i--;)
newdom[i] = sl->s[i];
IntSet ret(newdom, sl->s.size());
heap.free(newdom, static_cast<unsigned long int>(sl->s.size()));
return ret;
}
}
return IntSet(Int::Limits::min, Int::Limits::max);
}
int vs2bsl(BoolVarSpec* bs) {
if (bs->assigned) {
return bs->i;
}
if (bs->domain()) {
AST::SetLit* sl = bs->domain.some();
assert(sl->interval);
return std::min(1, std::max(0, sl->min));
}
return 0;
}
int vs2bsh(BoolVarSpec* bs) {
if (bs->assigned) {
return bs->i;
}
if (bs->domain()) {
AST::SetLit* sl = bs->domain.some();
assert(sl->interval);
return std::max(0, std::min(1, sl->max));
}
return 1;
}
TieBreak<IntVarBranch> ann2ivarsel(AST::Node* ann, Rnd rnd, double decay) {
if (AST::Atom* s = dynamic_cast<AST::Atom*>(ann)) {
if (s->id == "input_order")
return TieBreak<IntVarBranch>(INT_VAR_NONE());
if (s->id == "first_fail")
return TieBreak<IntVarBranch>(INT_VAR_SIZE_MIN());
if (s->id == "anti_first_fail")
return TieBreak<IntVarBranch>(INT_VAR_SIZE_MAX());
if (s->id == "smallest")
return TieBreak<IntVarBranch>(INT_VAR_MIN_MIN());
if (s->id == "largest")
return TieBreak<IntVarBranch>(INT_VAR_MAX_MAX());
if (s->id == "occurrence")
return TieBreak<IntVarBranch>(INT_VAR_DEGREE_MAX());
if (s->id == "max_regret")
return TieBreak<IntVarBranch>(INT_VAR_REGRET_MIN_MAX());
if (s->id == "most_constrained")
return TieBreak<IntVarBranch>(INT_VAR_SIZE_MIN(),
INT_VAR_DEGREE_MAX());
if (s->id == "random") {
return TieBreak<IntVarBranch>(INT_VAR_RND(rnd));
}
if (s->id == "dom_w_deg") {
return TieBreak<IntVarBranch>(INT_VAR_AFC_SIZE_MAX(decay));
}
if (s->id == "afc_min")
return TieBreak<IntVarBranch>(INT_VAR_AFC_MIN(decay));
if (s->id == "afc_max")
return TieBreak<IntVarBranch>(INT_VAR_AFC_MAX(decay));
if (s->id == "afc_size_min")
return TieBreak<IntVarBranch>(INT_VAR_AFC_SIZE_MIN(decay));
if (s->id == "afc_size_max") {
return TieBreak<IntVarBranch>(INT_VAR_AFC_SIZE_MAX(decay));
}
if (s->id == "action_min")
return TieBreak<IntVarBranch>(INT_VAR_ACTION_MIN(decay));
if (s->id == "action_max")
return TieBreak<IntVarBranch>(INT_VAR_ACTION_MAX(decay));
if (s->id == "action_size_min")
return TieBreak<IntVarBranch>(INT_VAR_ACTION_SIZE_MIN(decay));
if (s->id == "action_size_max")
return TieBreak<IntVarBranch>(INT_VAR_ACTION_SIZE_MAX(decay));
}
std::cerr << "Warning, ignored search annotation: ";
ann->print(std::cerr);
std::cerr << std::endl;
return TieBreak<IntVarBranch>(INT_VAR_NONE());
}
IntValBranch ann2ivalsel(AST::Node* ann, std::string& r0, std::string& r1,
Rnd rnd) {
if (AST::Atom* s = dynamic_cast<AST::Atom*>(ann)) {
if (s->id == "indomain_min") {
r0 = "="; r1 = "!=";
return INT_VAL_MIN();
}
if (s->id == "indomain_max") {
r0 = "="; r1 = "!=";
return INT_VAL_MAX();
}
if (s->id == "indomain_median") {
r0 = "="; r1 = "!=";
return INT_VAL_MED();
}
if (s->id == "indomain_split") {
r0 = "<="; r1 = ">";
return INT_VAL_SPLIT_MIN();
}
if (s->id == "indomain_reverse_split") {
r0 = ">"; r1 = "<=";
return INT_VAL_SPLIT_MAX();
}
if (s->id == "indomain_random") {
r0 = "="; r1 = "!=";
return INT_VAL_RND(rnd);
}
if (s->id == "indomain") {
r0 = "="; r1 = "=";
return INT_VALUES_MIN();
}
if (s->id == "indomain_middle") {
std::cerr << "Warning, replacing unsupported annotation "
<< "indomain_middle with indomain_median" << std::endl;
r0 = "="; r1 = "!=";
return INT_VAL_MED();
}
if (s->id == "indomain_interval") {
std::cerr << "Warning, replacing unsupported annotation "
<< "indomain_interval with indomain_split" << std::endl;
r0 = "<="; r1 = ">";
return INT_VAL_SPLIT_MIN();
}
}
std::cerr << "Warning, ignored search annotation: ";
ann->print(std::cerr);
std::cerr << std::endl;
r0 = "="; r1 = "!=";
return INT_VAL_MIN();
}
IntAssign ann2asnivalsel(AST::Node* ann, Rnd rnd) {
if (AST::Atom* s = dynamic_cast<AST::Atom*>(ann)) {
if (s->id == "indomain_min")
return INT_ASSIGN_MIN();
if (s->id == "indomain_max")
return INT_ASSIGN_MAX();
if (s->id == "indomain_median")
return INT_ASSIGN_MED();
if (s->id == "indomain_random") {
return INT_ASSIGN_RND(rnd);
}
}
std::cerr << "Warning, ignored search annotation: ";
ann->print(std::cerr);
std::cerr << std::endl;
return INT_ASSIGN_MIN();
}
TieBreak<BoolVarBranch> ann2bvarsel(AST::Node* ann, Rnd rnd, double decay) {
if (AST::Atom* s = dynamic_cast<AST::Atom*>(ann)) {
if ((s->id == "input_order") ||
(s->id == "first_fail") ||
(s->id == "anti_first_fail") ||
(s->id == "smallest") ||
(s->id == "largest") ||
(s->id == "max_regret"))
return TieBreak<BoolVarBranch>(BOOL_VAR_NONE());
if ((s->id == "occurrence") ||
(s->id == "most_constrained"))
return TieBreak<BoolVarBranch>(BOOL_VAR_DEGREE_MAX());
if (s->id == "random")
return TieBreak<BoolVarBranch>(BOOL_VAR_RND(rnd));
if ((s->id == "afc_min") ||
(s->id == "afc_size_min"))
return TieBreak<BoolVarBranch>(BOOL_VAR_AFC_MIN(decay));
if ((s->id == "afc_max") ||
(s->id == "afc_size_max") ||
(s->id == "dom_w_deg"))
return TieBreak<BoolVarBranch>(BOOL_VAR_AFC_MAX(decay));
if ((s->id == "action_min") &&
(s->id == "action_size_min"))
return TieBreak<BoolVarBranch>(BOOL_VAR_ACTION_MIN(decay));
if ((s->id == "action_max") ||
(s->id == "action_size_max"))
return TieBreak<BoolVarBranch>(BOOL_VAR_ACTION_MAX(decay));
}
std::cerr << "Warning, ignored search annotation: ";
ann->print(std::cerr);
std::cerr << std::endl;
return TieBreak<BoolVarBranch>(BOOL_VAR_NONE());
}
BoolValBranch ann2bvalsel(AST::Node* ann, std::string& r0, std::string& r1,
Rnd rnd) {
if (AST::Atom* s = dynamic_cast<AST::Atom*>(ann)) {
if (s->id == "indomain_min") {
r0 = "="; r1 = "!=";
return BOOL_VAL_MIN();
}
if (s->id == "indomain_max") {
r0 = "="; r1 = "!=";
return BOOL_VAL_MAX();
}
if (s->id == "indomain_median") {
r0 = "="; r1 = "!=";
return BOOL_VAL_MIN();
}
if (s->id == "indomain_split") {
r0 = "<="; r1 = ">";
return BOOL_VAL_MIN();
}
if (s->id == "indomain_reverse_split") {
r0 = ">"; r1 = "<=";
return BOOL_VAL_MAX();
}
if (s->id == "indomain_random") {
r0 = "="; r1 = "!=";
return BOOL_VAL_RND(rnd);
}
if (s->id == "indomain") {
r0 = "="; r1 = "=";
return BOOL_VAL_MIN();
}
if (s->id == "indomain_middle") {
std::cerr << "Warning, replacing unsupported annotation "
<< "indomain_middle with indomain_median" << std::endl;
r0 = "="; r1 = "!=";
return BOOL_VAL_MIN();
}
if (s->id == "indomain_interval") {
std::cerr << "Warning, replacing unsupported annotation "
<< "indomain_interval with indomain_split" << std::endl;
r0 = "<="; r1 = ">";
return BOOL_VAL_MIN();
}
}
std::cerr << "Warning, ignored search annotation: ";
ann->print(std::cerr);
std::cerr << std::endl;
r0 = "="; r1 = "!=";
return BOOL_VAL_MIN();
}
BoolAssign ann2asnbvalsel(AST::Node* ann, Rnd rnd) {
if (AST::Atom* s = dynamic_cast<AST::Atom*>(ann)) {
if ((s->id == "indomain_min") ||
(s->id == "indomain_median"))
return BOOL_ASSIGN_MIN();
if (s->id == "indomain_max")
return BOOL_ASSIGN_MAX();
if (s->id == "indomain_random") {
return BOOL_ASSIGN_RND(rnd);
}
}
std::cerr << "Warning, ignored search annotation: ";
ann->print(std::cerr);
std::cerr << std::endl;
return BOOL_ASSIGN_MIN();
}
#ifdef GECODE_HAS_SET_VARS
SetVarBranch ann2svarsel(AST::Node* ann, Rnd rnd, double decay) {
if (AST::Atom* s = dynamic_cast<AST::Atom*>(ann)) {
if (s->id == "input_order")
return SET_VAR_NONE();
if (s->id == "first_fail")
return SET_VAR_SIZE_MIN();
if (s->id == "anti_first_fail")
return SET_VAR_SIZE_MAX();
if (s->id == "smallest")
return SET_VAR_MIN_MIN();
if (s->id == "largest")
return SET_VAR_MAX_MAX();
if (s->id == "afc_min")
return SET_VAR_AFC_MIN(decay);
if (s->id == "afc_max")
return SET_VAR_AFC_MAX(decay);
if (s->id == "afc_size_min")
return SET_VAR_AFC_SIZE_MIN(decay);
if (s->id == "afc_size_max")
return SET_VAR_AFC_SIZE_MAX(decay);
if (s->id == "action_min")
return SET_VAR_ACTION_MIN(decay);
if (s->id == "action_max")
return SET_VAR_ACTION_MAX(decay);
if (s->id == "action_size_min")
return SET_VAR_ACTION_SIZE_MIN(decay);
if (s->id == "action_size_max")
return SET_VAR_ACTION_SIZE_MAX(decay);
if (s->id == "random") {
return SET_VAR_RND(rnd);
}
}
std::cerr << "Warning, ignored search annotation: ";
ann->print(std::cerr);
std::cerr << std::endl;
return SET_VAR_NONE();
}
SetValBranch ann2svalsel(AST::Node* ann, std::string r0, std::string r1,
Rnd rnd) {
(void) rnd;
if (AST::Atom* s = dynamic_cast<AST::Atom*>(ann)) {
if (s->id == "indomain_min") {
r0 = "in"; r1 = "not in";
return SET_VAL_MIN_INC();
}
if (s->id == "indomain_max") {
r0 = "in"; r1 = "not in";
return SET_VAL_MAX_INC();
}
if (s->id == "outdomain_min") {
r1 = "in"; r0 = "not in";
return SET_VAL_MIN_EXC();
}
if (s->id == "outdomain_max") {
r1 = "in"; r0 = "not in";
return SET_VAL_MAX_EXC();
}
}
std::cerr << "Warning, ignored search annotation: ";
ann->print(std::cerr);
std::cerr << std::endl;
r0 = "in"; r1 = "not in";
return SET_VAL_MIN_INC();
}
#endif
#ifdef GECODE_HAS_FLOAT_VARS
TieBreak<FloatVarBranch> ann2fvarsel(AST::Node* ann, Rnd rnd,
double decay) {
if (AST::Atom* s = dynamic_cast<AST::Atom*>(ann)) {
if (s->id == "input_order")
return TieBreak<FloatVarBranch>(FLOAT_VAR_NONE());
if (s->id == "first_fail")
return TieBreak<FloatVarBranch>(FLOAT_VAR_SIZE_MIN());
if (s->id == "anti_first_fail")
return TieBreak<FloatVarBranch>(FLOAT_VAR_SIZE_MAX());
if (s->id == "smallest")
return TieBreak<FloatVarBranch>(FLOAT_VAR_MIN_MIN());
if (s->id == "largest")
return TieBreak<FloatVarBranch>(FLOAT_VAR_MAX_MAX());
if (s->id == "occurrence")
return TieBreak<FloatVarBranch>(FLOAT_VAR_DEGREE_MAX());
if (s->id == "most_constrained")
return TieBreak<FloatVarBranch>(FLOAT_VAR_SIZE_MIN(),
FLOAT_VAR_DEGREE_MAX());
if (s->id == "random") {
return TieBreak<FloatVarBranch>(FLOAT_VAR_RND(rnd));
}
if (s->id == "afc_min")
return TieBreak<FloatVarBranch>(FLOAT_VAR_AFC_MIN(decay));
if (s->id == "afc_max")
return TieBreak<FloatVarBranch>(FLOAT_VAR_AFC_MAX(decay));
if (s->id == "afc_size_min")
return TieBreak<FloatVarBranch>(FLOAT_VAR_AFC_SIZE_MIN(decay));
if (s->id == "afc_size_max")
return TieBreak<FloatVarBranch>(FLOAT_VAR_AFC_SIZE_MAX(decay));
if (s->id == "action_min")
return TieBreak<FloatVarBranch>(FLOAT_VAR_ACTION_MIN(decay));
if (s->id == "action_max")
return TieBreak<FloatVarBranch>(FLOAT_VAR_ACTION_MAX(decay));
if (s->id == "action_size_min")
return TieBreak<FloatVarBranch>(FLOAT_VAR_ACTION_SIZE_MIN(decay));
if (s->id == "action_size_max")
return TieBreak<FloatVarBranch>(FLOAT_VAR_ACTION_SIZE_MAX(decay));
}
std::cerr << "Warning, ignored search annotation: ";
ann->print(std::cerr);
std::cerr << std::endl;
return TieBreak<FloatVarBranch>(FLOAT_VAR_NONE());
}
FloatValBranch ann2fvalsel(AST::Node* ann, std::string r0, std::string r1) {
if (AST::Atom* s = dynamic_cast<AST::Atom*>(ann)) {
if (s->id == "indomain_split") {
r0 = "<="; r1 = ">";
return FLOAT_VAL_SPLIT_MIN();
}
if (s->id == "indomain_reverse_split") {
r1 = "<="; r0 = ">";
return FLOAT_VAL_SPLIT_MAX();
}
}
std::cerr << "Warning, ignored search annotation: ";
ann->print(std::cerr);
std::cerr << std::endl;
r0 = "<="; r1 = ">";
return FLOAT_VAL_SPLIT_MIN();
}
#endif
class FlatZincSpaceInitData {
public:
typedef std::unordered_set<TupleSet> TupleSetSet;
TupleSetSet tupleSetSet;
typedef std::unordered_set<SharedArray<int> > IntSharedArraySet;
IntSharedArraySet intSharedArraySet;
typedef std::unordered_set<DFA> DFASet;
DFASet dfaSet;
FlatZincSpaceInitData(void) {}
};
FlatZincSpace::FlatZincSpace(FlatZincSpace& f)
: Space(f),
_initData(NULL), _random(f._random),
_solveAnnotations(NULL), iv_boolalias(NULL),
#ifdef GECODE_HAS_FLOAT_VARS
step(f.step),
#endif
needAuxVars(f.needAuxVars) {
_optVar = f._optVar;
_optVarIsInt = f._optVarIsInt;
_method = f._method;
_lns = f._lns;
_lnsInitialSolution = f._lnsInitialSolution;
branchInfo = f.branchInfo;
iv.update(*this, f.iv);
iv_lns.update(*this, f.iv_lns);
intVarCount = f.intVarCount;
if (needAuxVars) {
IntVarArgs iva;
for (int i=0; i<f.iv_aux.size(); i++) {
if (!f.iv_aux[i].assigned()) {
iva << IntVar();
iva[iva.size()-1].update(*this, f.iv_aux[i]);
}
}
iv_aux = IntVarArray(*this, iva);
}
bv.update(*this, f.bv);
boolVarCount = f.boolVarCount;
if (needAuxVars) {
BoolVarArgs bva;
for (int i=0; i<f.bv_aux.size(); i++) {
if (!f.bv_aux[i].assigned()) {
bva << BoolVar();
bva[bva.size()-1].update(*this, f.bv_aux[i]);
}
}
bv_aux = BoolVarArray(*this, bva);
}
#ifdef GECODE_HAS_SET_VARS
sv.update(*this, f.sv);
setVarCount = f.setVarCount;
if (needAuxVars) {
SetVarArgs sva;
for (int i=0; i<f.sv_aux.size(); i++) {
if (!f.sv_aux[i].assigned()) {
sva << SetVar();
sva[sva.size()-1].update(*this, f.sv_aux[i]);
}
}
sv_aux = SetVarArray(*this, sva);
}
#endif
#ifdef GECODE_HAS_FLOAT_VARS
fv.update(*this, f.fv);
floatVarCount = f.floatVarCount;
if (needAuxVars) {
FloatVarArgs fva;
for (int i=0; i<f.fv_aux.size(); i++) {
if (!f.fv_aux[i].assigned()) {
fva << FloatVar();
fva[fva.size()-1].update(*this, f.fv_aux[i]);
}
}
fv_aux = FloatVarArray(*this, fva);
}
#endif
}
FlatZincSpace::FlatZincSpace(Rnd& random)
: _initData(new FlatZincSpaceInitData),
intVarCount(-1), boolVarCount(-1), floatVarCount(-1), setVarCount(-1),
_optVar(-1), _optVarIsInt(true), _lns(0), _lnsInitialSolution(0),
_random(random),
_solveAnnotations(NULL), needAuxVars(true) {
branchInfo.init();
}
void
FlatZincSpace::init(int intVars, int boolVars,
int setVars, int floatVars) {
(void) setVars;
(void) floatVars;
intVarCount = 0;
iv = IntVarArray(*this, intVars);
iv_introduced = std::vector<bool>(2*intVars);
iv_boolalias = alloc<int>(intVars+(intVars==0?1:0));
boolVarCount = 0;
bv = BoolVarArray(*this, boolVars);
bv_introduced = std::vector<bool>(2*boolVars);
#ifdef GECODE_HAS_SET_VARS
setVarCount = 0;
sv = SetVarArray(*this, setVars);
sv_introduced = std::vector<bool>(2*setVars);
#endif
#ifdef GECODE_HAS_FLOAT_VARS
floatVarCount = 0;
fv = FloatVarArray(*this, floatVars);
fv_introduced = std::vector<bool>(2*floatVars);
#endif
}
void
FlatZincSpace::newIntVar(IntVarSpec* vs) {
if (vs->alias) {
iv[intVarCount++] = iv[vs->i];
} else {
IntSet dom(vs2is(vs));
if (dom.size()==0) {
fail();
return;
} else {
iv[intVarCount++] = IntVar(*this, dom);
}
}
iv_introduced[2*(intVarCount-1)] = vs->introduced;
iv_introduced[2*(intVarCount-1)+1] = vs->funcDep;
iv_boolalias[intVarCount-1] = -1;
}
void
FlatZincSpace::aliasBool2Int(int iv, int bv) {
iv_boolalias[iv] = bv;
}
int
FlatZincSpace::aliasBool2Int(int iv) {
return iv_boolalias[iv];
}
void
FlatZincSpace::newBoolVar(BoolVarSpec* vs) {
if (vs->alias) {
bv[boolVarCount++] = bv[vs->i];
} else {
bv[boolVarCount++] = BoolVar(*this, vs2bsl(vs), vs2bsh(vs));
}
bv_introduced[2*(boolVarCount-1)] = vs->introduced;
bv_introduced[2*(boolVarCount-1)+1] = vs->funcDep;
}
#ifdef GECODE_HAS_SET_VARS
void
FlatZincSpace::newSetVar(SetVarSpec* vs) {
if (vs->alias) {
sv[setVarCount++] = sv[vs->i];
} else if (vs->assigned) {
assert(vs->upperBound());
AST::SetLit* vsv = vs->upperBound.some();
if (vsv->interval) {
IntSet d(vsv->min, vsv->max);
sv[setVarCount++] = SetVar(*this, d, d);
} else {
int* is = heap.alloc<int>(static_cast<unsigned long int>(vsv->s.size()));
for (int i=vsv->s.size(); i--; )
is[i] = vsv->s[i];
IntSet d(is, vsv->s.size());
heap.free(is,static_cast<unsigned long int>(vsv->s.size()));
sv[setVarCount++] = SetVar(*this, d, d);
}
} else if (vs->upperBound()) {
AST::SetLit* vsv = vs->upperBound.some();
if (vsv->interval) {
IntSet d(vsv->min, vsv->max);
sv[setVarCount++] = SetVar(*this, IntSet::empty, d);
} else {
int* is = heap.alloc<int>(static_cast<unsigned long int>(vsv->s.size()));
for (int i=vsv->s.size(); i--; )
is[i] = vsv->s[i];
IntSet d(is, vsv->s.size());
heap.free(is,static_cast<unsigned long int>(vsv->s.size()));
sv[setVarCount++] = SetVar(*this, IntSet::empty, d);
}
} else {
sv[setVarCount++] = SetVar(*this, IntSet::empty,
IntSet(Set::Limits::min,
Set::Limits::max));
}
sv_introduced[2*(setVarCount-1)] = vs->introduced;
sv_introduced[2*(setVarCount-1)+1] = vs->funcDep;
}
#else
void
FlatZincSpace::newSetVar(SetVarSpec*) {
throw FlatZinc::Error("Gecode", "set variables not supported");
}
#endif
#ifdef GECODE_HAS_FLOAT_VARS
void
FlatZincSpace::newFloatVar(FloatVarSpec* vs) {
if (vs->alias) {
fv[floatVarCount++] = fv[vs->i];
} else {
double dmin, dmax;
if (vs->domain()) {
dmin = vs->domain.some().first;
dmax = vs->domain.some().second;
if (dmin > dmax) {
fail();
return;
}
} else {
dmin = Float::Limits::min;
dmax = Float::Limits::max;
}
fv[floatVarCount++] = FloatVar(*this, dmin, dmax);
}
fv_introduced[2*(floatVarCount-1)] = vs->introduced;
fv_introduced[2*(floatVarCount-1)+1] = vs->funcDep;
}
#else
void
FlatZincSpace::newFloatVar(FloatVarSpec*) {
throw FlatZinc::Error("Gecode", "float variables not supported");
}
#endif
namespace {
struct ConExprOrder {
bool operator() (ConExpr* ce0, ConExpr* ce1) {
return ce0->args->a.size() < ce1->args->a.size();
}
};
}
void
FlatZincSpace::postConstraints(std::vector<ConExpr*>& ces) {
ConExprOrder ceo;
std::sort(ces.begin(), ces.end(), ceo);
for (unsigned int i=0; i<ces.size(); i++) {
const ConExpr& ce = *ces[i];
try {
registry().post(*this, ce);
} catch (Gecode::Exception& e) {
throw FlatZinc::Error("Gecode", e.what());
} catch (AST::TypeError& e) {
throw FlatZinc::Error("Type error", e.what());
}
delete ces[i];
ces[i] = NULL;
}
}
void flattenAnnotations(AST::Array* ann, std::vector<AST::Node*>& out) {
for (unsigned int i=0; i<ann->a.size(); i++) {
if (ann->a[i]->isCall("seq_search")) {
AST::Call* c = ann->a[i]->getCall();
if (c->args->isArray())
flattenAnnotations(c->args->getArray(), out);
else
out.push_back(c->args);
} else {
out.push_back(ann->a[i]);
}
}
}
void
FlatZincSpace::createBranchers(Printer&p, AST::Node* ann, FlatZincOptions& opt,
bool ignoreUnknown,
std::ostream& err) {
int seed = opt.seed();
double decay = opt.decay();
Rnd rnd(static_cast<unsigned int>(seed));
TieBreak<IntVarBranch> def_int_varsel = INT_VAR_AFC_SIZE_MAX(0.99);
IntBoolVarBranch def_intbool_varsel = INTBOOL_VAR_AFC_SIZE_MAX(0.99);
IntValBranch def_int_valsel = INT_VAL_MIN();
std::string def_int_rel_left = "=";
std::string def_int_rel_right = "!=";
TieBreak<BoolVarBranch> def_bool_varsel = BOOL_VAR_AFC_MAX(0.99);
BoolValBranch def_bool_valsel = BOOL_VAL_MIN();
std::string def_bool_rel_left = "=";
std::string def_bool_rel_right = "!=";
#ifdef GECODE_HAS_SET_VARS
SetVarBranch def_set_varsel = SET_VAR_AFC_SIZE_MAX(0.99);
SetValBranch def_set_valsel = SET_VAL_MIN_INC();
std::string def_set_rel_left = "in";
std::string def_set_rel_right = "not in";
#endif
#ifdef GECODE_HAS_FLOAT_VARS
TieBreak<FloatVarBranch> def_float_varsel = FLOAT_VAR_SIZE_MIN();
FloatValBranch def_float_valsel = FLOAT_VAL_SPLIT_MIN();
std::string def_float_rel_left = "<=";
std::string def_float_rel_right = ">";
#endif
std::vector<bool> iv_searched(iv.size());
for (unsigned int i=iv.size(); i--;)
iv_searched[i] = false;
std::vector<bool> bv_searched(bv.size());
for (unsigned int i=bv.size(); i--;)
bv_searched[i] = false;
#ifdef GECODE_HAS_SET_VARS
std::vector<bool> sv_searched(sv.size());
for (unsigned int i=sv.size(); i--;)
sv_searched[i] = false;
#endif
#ifdef GECODE_HAS_FLOAT_VARS
std::vector<bool> fv_searched(fv.size());
for (unsigned int i=fv.size(); i--;)
fv_searched[i] = false;
#endif
_lns = 0;
if (ann) {
std::vector<AST::Node*> flatAnn;
if (ann->isArray()) {
flattenAnnotations(ann->getArray() , flatAnn);
} else {
flatAnn.push_back(ann);
}
for (unsigned int i=0; i<flatAnn.size(); i++) {
if (flatAnn[i]->isCall("restart_geometric")) {
AST::Call* call = flatAnn[i]->getCall("restart_geometric");
opt.restart(RM_GEOMETRIC);
AST::Array* args = call->getArgs(2);
opt.restart_base(args->a[0]->getFloat());
opt.restart_scale(args->a[1]->getInt());
} else if (flatAnn[i]->isCall("restart_luby")) {
AST::Call* call = flatAnn[i]->getCall("restart_luby");
opt.restart(RM_LUBY);
opt.restart_scale(call->args->getInt());
} else if (flatAnn[i]->isCall("restart_linear")) {
AST::Call* call = flatAnn[i]->getCall("restart_linear");
opt.restart(RM_LINEAR);
opt.restart_scale(call->args->getInt());
} else if (flatAnn[i]->isCall("restart_constant")) {
AST::Call* call = flatAnn[i]->getCall("restart_constant");
opt.restart(RM_CONSTANT);
opt.restart_scale(call->args->getInt());
} else if (flatAnn[i]->isCall("restart_none")) {
opt.restart(RM_NONE);
} else if (flatAnn[i]->isCall("relax_and_reconstruct")) {
if (_lns != 0)
throw FlatZinc::Error("FlatZinc",
"Only one relax_and_reconstruct annotation allowed");
AST::Call *call = flatAnn[i]->getCall("relax_and_reconstruct");
AST::Array* args;
if (call->args->getArray()->a.size()==2) {
args = call->getArgs(2);
} else {
args = call->getArgs(3);
}
_lns = args->a[1]->getInt();
AST::Array *vars = args->a[0]->getArray();
int k=vars->a.size();
for (int i=vars->a.size(); i--;)
if (vars->a[i]->isInt())
k--;
iv_lns = IntVarArray(*this, k);
k = 0;
for (unsigned int i=0; i<vars->a.size(); i++) {
if (vars->a[i]->isInt())
continue;
iv_lns[k++] = iv[vars->a[i]->getIntVar()];
}
if (args->a.size()==3) {
AST::Array *initial = args->a[2]->getArray();
_lnsInitialSolution = IntSharedArray(initial->a.size());
for (unsigned int i=initial->a.size(); i--;)
_lnsInitialSolution[i] = initial->a[i]->getInt();
}
} else if (flatAnn[i]->isCall("gecode_search")) {
AST::Call* c = flatAnn[i]->getCall();
branchWithPlugin(c->args);
} else if (flatAnn[i]->isCall("int_search")) {
AST::Call *call = flatAnn[i]->getCall("int_search");
AST::Array *args = call->getArgs(4);
AST::Array *vars = args->a[0]->getArray();
int k=vars->a.size();
for (int i=vars->a.size(); i--;)
if (vars->a[i]->isInt())
k--;
IntVarArgs va(k);
std::vector<std::string> names;
k=0;
for (unsigned int i=0; i<vars->a.size(); i++) {
if (vars->a[i]->isInt())
continue;
va[k++] = iv[vars->a[i]->getIntVar()];
iv_searched[vars->a[i]->getIntVar()] = true;
names.push_back(vars->a[i]->getVarName());
}
std::string r0, r1;
{
BrancherGroup bg;
branch(bg(*this), va,
ann2ivarsel(args->a[1],rnd,decay),
ann2ivalsel(args->a[2],r0,r1,rnd),
nullptr,
&varValPrint<IntVar>);
branchInfo.add(bg,r0,r1,names);
}
} else if (flatAnn[i]->isCall("int_assign")) {
AST::Call *call = flatAnn[i]->getCall("int_assign");
AST::Array *args = call->getArgs(2);
AST::Array *vars = args->a[0]->getArray();
int k=vars->a.size();
for (int i=vars->a.size(); i--;)
if (vars->a[i]->isInt())
k--;
IntVarArgs va(k);
k=0;
for (unsigned int i=0; i<vars->a.size(); i++) {
if (vars->a[i]->isInt())
continue;
va[k++] = iv[vars->a[i]->getIntVar()];
iv_searched[vars->a[i]->getIntVar()] = true;
}
assign(*this, va, ann2asnivalsel(args->a[1],rnd), nullptr,
&varValPrint<IntVar>);
} else if (flatAnn[i]->isCall("bool_search")) {
AST::Call *call = flatAnn[i]->getCall("bool_search");
AST::Array *args = call->getArgs(4);
AST::Array *vars = args->a[0]->getArray();
int k=vars->a.size();
for (int i=vars->a.size(); i--;)
if (vars->a[i]->isBool())
k--;
BoolVarArgs va(k);
k=0;
std::vector<std::string> names;
for (unsigned int i=0; i<vars->a.size(); i++) {
if (vars->a[i]->isBool())
continue;
va[k++] = bv[vars->a[i]->getBoolVar()];
bv_searched[vars->a[i]->getBoolVar()] = true;
names.push_back(vars->a[i]->getVarName());
}
std::string r0, r1;
{
BrancherGroup bg;
branch(bg(*this), va,
ann2bvarsel(args->a[1],rnd,decay),
ann2bvalsel(args->a[2],r0,r1,rnd),
nullptr,
&varValPrint<BoolVar>);
branchInfo.add(bg,r0,r1,names);
}
} else if (flatAnn[i]->isCall("int_default_search")) {
AST::Call *call = flatAnn[i]->getCall("int_default_search");
AST::Array *args = call->getArgs(2);
def_int_varsel = ann2ivarsel(args->a[0],rnd,decay);
def_int_valsel = ann2ivalsel(args->a[1],
def_int_rel_left,def_int_rel_right,rnd);
} else if (flatAnn[i]->isCall("bool_default_search")) {
AST::Call *call = flatAnn[i]->getCall("bool_default_search");
AST::Array *args = call->getArgs(2);
def_bool_varsel = ann2bvarsel(args->a[0],rnd,decay);
def_bool_valsel = ann2bvalsel(args->a[1],
def_bool_rel_left,def_bool_rel_right,
rnd);
} else if (flatAnn[i]->isCall("set_search")) {
#ifdef GECODE_HAS_SET_VARS
AST::Call *call = flatAnn[i]->getCall("set_search");
AST::Array *args = call->getArgs(4);
AST::Array *vars = args->a[0]->getArray();
int k=vars->a.size();
for (int i=vars->a.size(); i--;)
if (vars->a[i]->isSet())
k--;
SetVarArgs va(k);
k=0;
std::vector<std::string> names;
for (unsigned int i=0; i<vars->a.size(); i++) {
if (vars->a[i]->isSet())
continue;
va[k++] = sv[vars->a[i]->getSetVar()];
sv_searched[vars->a[i]->getSetVar()] = true;
names.push_back(vars->a[i]->getVarName());
}
std::string r0, r1;
{
BrancherGroup bg;
branch(bg(*this), va,
ann2svarsel(args->a[1],rnd,decay),
ann2svalsel(args->a[2],r0,r1,rnd),
nullptr,
&varValPrint<SetVar>);
branchInfo.add(bg,r0,r1,names);
}
#else
if (!ignoreUnknown) {
err << "Warning, ignored search annotation: ";
flatAnn[i]->print(err);
err << std::endl;
}
#endif
} else if (flatAnn[i]->isCall("set_default_search")) {
#ifdef GECODE_HAS_SET_VARS
AST::Call *call = flatAnn[i]->getCall("set_default_search");
AST::Array *args = call->getArgs(2);
def_set_varsel = ann2svarsel(args->a[0],rnd,decay);
def_set_valsel = ann2svalsel(args->a[1],
def_set_rel_left,def_set_rel_right,rnd);
#else
if (!ignoreUnknown) {
err << "Warning, ignored search annotation: ";
flatAnn[i]->print(err);
err << std::endl;
}
#endif
} else if (flatAnn[i]->isCall("float_default_search")) {
#ifdef GECODE_HAS_FLOAT_VARS
AST::Call *call = flatAnn[i]->getCall("float_default_search");
AST::Array *args = call->getArgs(2);
def_float_varsel = ann2fvarsel(args->a[0],rnd,decay);
def_float_valsel = ann2fvalsel(args->a[1],
def_float_rel_left,def_float_rel_right);
#else
if (!ignoreUnknown) {
err << "Warning, ignored search annotation: ";
flatAnn[i]->print(err);
err << std::endl;
}
#endif
} else if (flatAnn[i]->isCall("float_search")) {
#ifdef GECODE_HAS_FLOAT_VARS
AST::Call *call = flatAnn[i]->getCall("float_search");
AST::Array *args = call->getArgs(5);
AST::Array *vars = args->a[0]->getArray();
int k=vars->a.size();
for (int i=vars->a.size(); i--;)
if (vars->a[i]->isFloat())
k--;
FloatVarArgs va(k);
k=0;
std::vector<std::string> names;
for (unsigned int i=0; i<vars->a.size(); i++) {
if (vars->a[i]->isFloat())
continue;
va[k++] = fv[vars->a[i]->getFloatVar()];
fv_searched[vars->a[i]->getFloatVar()] = true;
names.push_back(vars->a[i]->getVarName());
}
std::string r0, r1;
{
BrancherGroup bg;
branch(bg(*this), va,
ann2fvarsel(args->a[2],rnd,decay),
ann2fvalsel(args->a[3],r0,r1),
nullptr,
&varValPrintF);
branchInfo.add(bg,r0,r1,names);
}
#else
if (!ignoreUnknown) {
err << "Warning, ignored search annotation: ";
flatAnn[i]->print(err);
err << std::endl;
}
#endif
} else {
if (!ignoreUnknown) {
err << "Warning, ignored search annotation: ";
flatAnn[i]->print(err);
err << std::endl;
}
}
}
}
int introduced = 0;
int funcdep = 0;
int searched = 0;
for (int i=iv.size(); i--;) {
if (iv_searched[i] || (_method != SAT && _optVarIsInt && _optVar==i)) {
searched++;
} else if (iv_introduced[2*i]) {
if (iv_introduced[2*i+1]) {
funcdep++;
} else {
introduced++;
}
}
}
std::vector<std::string> iv_sol_names(iv.size()-(introduced+funcdep+searched));
IntVarArgs iv_sol(iv.size()-(introduced+funcdep+searched));
std::vector<std::string> iv_tmp_names(introduced);
IntVarArgs iv_tmp(introduced);
for (int i=iv.size(), j=0, k=0; i--;) {
if (iv_searched[i] || (_method != SAT && _optVarIsInt && _optVar==i))
continue;
if (iv_introduced[2*i]) {
if (!iv_introduced[2*i+1]) {
iv_tmp_names[j] = p.intVarName(i);
iv_tmp[j++] = iv[i];
}
} else {
iv_sol_names[k] = p.intVarName(i);
iv_sol[k++] = iv[i];
}
}
introduced = 0;
funcdep = 0;
searched = 0;
for (int i=bv.size(); i--;) {
if (bv_searched[i]) {
searched++;
} else if (bv_introduced[2*i]) {
if (bv_introduced[2*i+1]) {
funcdep++;
} else {
introduced++;
}
}
}
std::vector<std::string> bv_sol_names(bv.size()-(introduced+funcdep+searched));
BoolVarArgs bv_sol(bv.size()-(introduced+funcdep+searched));
BoolVarArgs bv_tmp(introduced);
std::vector<std::string> bv_tmp_names(introduced);
for (int i=bv.size(), j=0, k=0; i--;) {
if (bv_searched[i])
continue;
if (bv_introduced[2*i]) {
if (!bv_introduced[2*i+1]) {
bv_tmp_names[j] = p.boolVarName(i);
bv_tmp[j++] = bv[i];
}
} else {
bv_sol_names[k] = p.boolVarName(i);
bv_sol[k++] = bv[i];
}
}
if (iv_sol.size() > 0 && bv_sol.size() > 0) {
branch(*this, iv_sol, bv_sol, def_intbool_varsel, def_int_valsel);
} else if (iv_sol.size() > 0) {
BrancherGroup bg;
branch(bg(*this), iv_sol, def_int_varsel, def_int_valsel, nullptr,
&varValPrint<IntVar>);
branchInfo.add(bg,def_int_rel_left,def_int_rel_right,iv_sol_names);
} else if (bv_sol.size() > 0) {
BrancherGroup bg;
branch(bg(*this), bv_sol, def_bool_varsel, def_bool_valsel, nullptr,
&varValPrint<BoolVar>);
branchInfo.add(bg,def_bool_rel_left,def_bool_rel_right,bv_sol_names);
}
#ifdef GECODE_HAS_FLOAT_VARS
introduced = 0;
funcdep = 0;
searched = 0;
for (int i=fv.size(); i--;) {
if (fv_searched[i] || (_method != SAT && !_optVarIsInt && _optVar==i)) {
searched++;
} else if (fv_introduced[2*i]) {
if (fv_introduced[2*i+1]) {
funcdep++;
} else {
introduced++;
}
}
}
std::vector<std::string> fv_sol_names(fv.size()-(introduced+funcdep+searched));
FloatVarArgs fv_sol(fv.size()-(introduced+funcdep+searched));
FloatVarArgs fv_tmp(introduced);
std::vector<std::string> fv_tmp_names(introduced);
for (int i=fv.size(), j=0, k=0; i--;) {
if (fv_searched[i] || (_method != SAT && !_optVarIsInt && _optVar==i))
continue;
if (fv_introduced[2*i]) {
if (!fv_introduced[2*i+1]) {
fv_tmp_names[j] = p.floatVarName(i);
fv_tmp[j++] = fv[i];
}
} else {
fv_sol_names[k] = p.floatVarName(i);
fv_sol[k++] = fv[i];
}
}
if (fv_sol.size() > 0) {
BrancherGroup bg;
branch(bg(*this), fv_sol, def_float_varsel, def_float_valsel, nullptr,
&varValPrintF);
branchInfo.add(bg,def_float_rel_left,def_float_rel_right,fv_sol_names);
}
#endif
#ifdef GECODE_HAS_SET_VARS
introduced = 0;
funcdep = 0;
searched = 0;
for (int i=sv.size(); i--;) {
if (sv_searched[i]) {
searched++;
} else if (sv_introduced[2*i]) {
if (sv_introduced[2*i+1]) {
funcdep++;
} else {
introduced++;
}
}
}
std::vector<std::string> sv_sol_names(sv.size()-(introduced+funcdep+searched));
SetVarArgs sv_sol(sv.size()-(introduced+funcdep+searched));
SetVarArgs sv_tmp(introduced);
std::vector<std::string> sv_tmp_names(introduced);
for (int i=sv.size(), j=0, k=0; i--;) {
if (sv_searched[i])
continue;
if (sv_introduced[2*i]) {
if (!sv_introduced[2*i+1]) {
sv_tmp_names[j] = p.setVarName(i);
sv_tmp[j++] = sv[i];
}
} else {
sv_sol_names[k] = p.setVarName(i);
sv_sol[k++] = sv[i];
}
}
if (sv_sol.size() > 0) {
BrancherGroup bg;
branch(bg(*this), sv_sol, def_set_varsel, def_set_valsel, nullptr,
&varValPrint<SetVar>);
branchInfo.add(bg,def_set_rel_left,def_set_rel_right,sv_sol_names);
}
#endif
iv_aux = IntVarArray(*this, iv_tmp);
bv_aux = BoolVarArray(*this, bv_tmp);
int n_aux = iv_aux.size() + bv_aux.size();
#ifdef GECODE_HAS_SET_VARS
sv_aux = SetVarArray(*this, sv_tmp);
n_aux += sv_aux.size();
#endif
#ifdef GECODE_HAS_FLOAT_VARS
fv_aux = FloatVarArray(*this, fv_tmp);
n_aux += fv_aux.size();
#endif
if (n_aux > 0) {
if (_method == SAT) {
AuxVarBrancher::post(*this, def_int_varsel, def_int_valsel,
def_bool_varsel, def_bool_valsel
#ifdef GECODE_HAS_SET_VARS
, def_set_varsel, def_set_valsel
#endif
#ifdef GECODE_HAS_FLOAT_VARS
, def_float_varsel, def_float_valsel
#endif
);
} else {
{
BrancherGroup bg;
branch(bg(*this),iv_aux,def_int_varsel,def_int_valsel, nullptr,
&varValPrint<IntVar>);
branchInfo.add(bg,def_int_rel_left,def_int_rel_right,iv_tmp_names);
}
{
BrancherGroup bg;
branch(bg(*this),bv_aux,def_bool_varsel,def_bool_valsel, nullptr,
&varValPrint<BoolVar>);
branchInfo.add(bg,def_bool_rel_left,def_bool_rel_right,bv_tmp_names);
}
#ifdef GECODE_HAS_SET_VARS
{
BrancherGroup bg;
branch(bg(*this),sv_aux,def_set_varsel,def_set_valsel, nullptr,
&varValPrint<SetVar>);
branchInfo.add(bg,def_set_rel_left,def_set_rel_right,sv_tmp_names);
}
#endif
#ifdef GECODE_HAS_FLOAT_VARS
{
BrancherGroup bg;
branch(bg(*this),fv_aux,def_float_varsel,def_float_valsel, nullptr,
&varValPrintF);
branchInfo.add(bg,def_float_rel_left,def_float_rel_right,fv_tmp_names);
}
#endif
}
}
if (_method == MIN) {
if (_optVarIsInt) {
std::vector<std::string> names(1);
names[0] = p.intVarName(_optVar);
BrancherGroup bg;
branch(bg(*this), iv[_optVar], INT_VAL_MIN(),
&varValPrint<IntVar>);
branchInfo.add(bg,"=","!=",names);
} else {
#ifdef GECODE_HAS_FLOAT_VARS
std::vector<std::string> names(1);
names[0] = p.floatVarName(_optVar);
BrancherGroup bg;
branch(bg(*this), fv[_optVar], FLOAT_VAL_SPLIT_MIN(),
&varValPrintF);
branchInfo.add(bg,"<=",">",names);
#endif
}
} else if (_method == MAX) {
if (_optVarIsInt) {
std::vector<std::string> names(1);
names[0] = p.intVarName(_optVar);
BrancherGroup bg;
branch(bg(*this), iv[_optVar], INT_VAL_MAX(),
&varValPrint<IntVar>);
branchInfo.add(bg,"=","!=",names);
} else {
#ifdef GECODE_HAS_FLOAT_VARS
std::vector<std::string> names(1);
names[0] = p.floatVarName(_optVar);
BrancherGroup bg;
branch(bg(*this), fv[_optVar], FLOAT_VAL_SPLIT_MAX(),
&varValPrintF);
branchInfo.add(bg,"<=",">",names);
#endif
}
}
}
AST::Array*
FlatZincSpace::solveAnnotations(void) const {
return _solveAnnotations;
}
void
FlatZincSpace::solve(AST::Array* ann) {
_method = SAT;
_solveAnnotations = ann;
}
void
FlatZincSpace::minimize(int var, bool isInt, AST::Array* ann) {
_method = MIN;
_optVar = var;
_optVarIsInt = isInt;
_solveAnnotations = ann;
}
void
FlatZincSpace::maximize(int var, bool isInt, AST::Array* ann) {
_method = MAX;
_optVar = var;
_optVarIsInt = isInt;
_solveAnnotations = ann;
}
FlatZincSpace::~FlatZincSpace(void) {
delete _initData;
delete _solveAnnotations;
}
#ifdef GECODE_HAS_GIST
template<class Engine>
class GistEngine {
};
template<typename S>
class GistEngine<DFS<S> > {
public:
static void explore(S* root, const FlatZincOptions& opt,
Gist::Inspector* i, Gist::Comparator* c) {
Gecode::Gist::Options o;
o.c_d = opt.c_d(); o.a_d = opt.a_d();
o.inspect.click(i);
o.inspect.compare(c);
(void) Gecode::Gist::dfs(root, o);
}
};
template<typename S>
class GistEngine<BAB<S> > {
public:
static void explore(S* root, const FlatZincOptions& opt,
Gist::Inspector* i, Gist::Comparator* c) {
Gecode::Gist::Options o;
o.c_d = opt.c_d(); o.a_d = opt.a_d();
o.inspect.click(i);
o.inspect.compare(c);
(void) Gecode::Gist::bab(root, o);
}
};
template<class S>
class FZPrintingInspector
: public Gecode::Gist::TextOutput, public Gecode::Gist::Inspector {
private:
const Printer& p;
public:
FZPrintingInspector(const Printer& p0);
virtual void inspect(const Space& node);
virtual void finalize(void);
};
template<class S>
FZPrintingInspector<S>::FZPrintingInspector(const Printer& p0)
: TextOutput("Gecode/FlatZinc"), p(p0) {}
template<class S>
void
FZPrintingInspector<S>::inspect(const Space& node) {
init();
dynamic_cast<const S&>(node).print(getStream(), p);
getStream() << std::endl;
}
template<class S>
void
FZPrintingInspector<S>::finalize(void) {
Gecode::Gist::TextOutput::finalize();
}
template<class S>
class FZPrintingComparator
: public Gecode::Gist::VarComparator<S> {
private:
const Printer& p;
public:
FZPrintingComparator(const Printer& p0);
virtual void compare(const Space& s0, const Space& s1);
};
template<class S>
FZPrintingComparator<S>::FZPrintingComparator(const Printer& p0)
: Gecode::Gist::VarComparator<S>("Gecode/FlatZinc"), p(p0) {}
template<class S>
void
FZPrintingComparator<S>::compare(const Space& s0, const Space& s1) {
this->init();
try {
dynamic_cast<const S&>(s0).compare(dynamic_cast<const S&>(s1),
this->getStream(), p);
} catch (Exception& e) {
this->getStream() << "Exception: " << e.what();
}
this->getStream() << std::endl;
}
#endif
template<template<class> class Engine>
void
FlatZincSpace::runEngine(std::ostream& out, const Printer& p,
const FlatZincOptions& opt, Support::Timer& t_total) {
if (opt.restart()==RM_NONE) {
runMeta<Engine,Driver::EngineToMeta>(out,p,opt,t_total);
} else {
runMeta<Engine,RBS>(out,p,opt,t_total);
}
}
#ifdef GECODE_HAS_CPPROFILER
class FlatZincGetInfo : public CPProfilerSearchTracer::GetInfo {
public:
const Printer& p;
FlatZincGetInfo(const Printer& printer) : p(printer) {}
virtual std::string
getInfo(const Space& space) const {
std::stringstream ss;
if (const FlatZincSpace* fz_space = dynamic_cast<const FlatZincSpace*>(&space)) {
ss << "{\n\t\"domains\": \"";
ss << fz_space->getDomains(p);
ss << "\"\n}";
}
return ss.str();
}
~FlatZincGetInfo(void) {};
};
void printIntVar(std::ostream& os, const std::string name, const Int::IntView& x) {
os << "var ";
if (x.assigned()) {
os << "int: " << name << " = " << x.val() << ";";
} else if (x.range()) {
os << x.min() << ".." << x.max() << ": " << name << ";";
} else {
os << "array_union([";
Gecode::Int::ViewRanges<Int::IntView> r(x);
while (true) {
os << r.min() << ".." << r.max();
++r;
if (!r()) break;
os << ',';
}
os << "]): " << name << ";";
}
os << "\n";
}
void printBoolVar(std::ostream& os, const std::string name, const BoolVar& b) {
os << "var bool: " << name;
if(b.assigned())
os << " = " << (b.val() ? "true" : "false");
os << ";\n";
}
#ifdef GECODE_HAS_FLOAT_VARS
void printFloatVar(std::ostream& os, const std::string name, const Float::FloatView& f) {
os << "var ";
if(f.assigned())
os << "float: " << name << " = " << f.med() << ";";
else
os << f.min() << ".." << f.max() << ": " << name << ";";
os << "\n";
}
#endif
std::string FlatZincSpace::getDomains(const Printer& p) const {
std::ostringstream oss;
for (int i = 0; i < iv.size(); i++)
printIntVar(oss, p.intVarName(i), iv[i]);
for (int i = 0; i < bv.size(); i++)
printBoolVar(oss, p.boolVarName(i), bv[i]);
#ifdef GECODE_HAS_FLOAT_VARS
for (int i = 0; i < fv.size(); i++)
printFloatVar(oss, p.floatVarName(i), fv[i]);
#endif
#ifdef GECODE_HAS_SET_VARS
for (int i = 0; i < sv.size(); i++)
oss << "var " << sv[i] << ": " << p.setVarName(i) << ";" << std::endl;
#endif
return oss.str();
}
#endif
template<template<class> class Engine,
template<class,template<class> class> class Meta>
void
FlatZincSpace::runMeta(std::ostream& out, const Printer& p,
const FlatZincOptions& opt, Support::Timer& t_total) {
#ifdef GECODE_HAS_GIST
if (opt.mode() == SM_GIST) {
FZPrintingInspector<FlatZincSpace> pi(p);
FZPrintingComparator<FlatZincSpace> pc(p);
(void) GistEngine<Engine<FlatZincSpace> >::explore(this,opt,&pi,&pc);
return;
}
#endif
StatusStatistics sstat;
unsigned int n_p = 0;
Support::Timer t_solve;
t_solve.start();
if (status(sstat) != SS_FAILED) {
n_p = PropagatorGroup::all.size(*this);
}
Search::Options o;
o.stop = Driver::CombinedStop::create(opt.node(), opt.fail(), opt.time(),
true);
o.c_d = opt.c_d();
o.a_d = opt.a_d();
#ifdef GECODE_HAS_CPPROFILER
if (opt.mode() == SM_CPPROFILER) {
FlatZincGetInfo* getInfo = nullptr;
if (opt.profiler_info())
getInfo = new FlatZincGetInfo(p);
o.tracer = new CPProfilerSearchTracer(opt.profiler_id(),
opt.name(), opt.profiler_port(),
getInfo);
}
#endif
#ifdef GECODE_HAS_FLOAT_VARS
step = opt.step();
#endif
o.threads = opt.threads();
o.nogoods_limit = opt.nogoods() ? opt.nogoods_limit() : 0;
o.cutoff = new Search::CutoffAppend(new Search::CutoffConstant(0), 1, Driver::createCutoff(opt));
if (opt.interrupt())
Driver::CombinedStop::installCtrlHandler(true);
{
Meta<FlatZincSpace,Engine> se(this,o);
int noOfSolutions = opt.solutions();
if (noOfSolutions == -1) {
noOfSolutions = (_method == SAT) ? 1 : 0;
}
bool printAll = _method == SAT || opt.allSolutions() || noOfSolutions != 0;
int findSol = noOfSolutions;
FlatZincSpace* sol = NULL;
while (FlatZincSpace* next_sol = se.next()) {
delete sol;
sol = next_sol;
if (printAll) {
sol->print(out, p);
out << "----------" << std::endl;
}
if (--findSol==0)
goto stopped;
}
if (sol && !printAll) {
sol->print(out, p);
out << "----------" << std::endl;
}
if (!se.stopped()) {
if (sol) {
out << "==========" << std::endl;
} else {
out << "=====UNSATISFIABLE=====" << std::endl;
}
} else if (!sol) {
out << "=====UNKNOWN=====" << std::endl;
}
delete sol;
stopped:
if (opt.interrupt())
Driver::CombinedStop::installCtrlHandler(false);
if (opt.mode() == SM_STAT) {
Gecode::Search::Statistics stat = se.statistics();
double totalTime = (t_total.stop() / 1000.0);
double solveTime = (t_solve.stop() / 1000.0);
double initTime = totalTime - solveTime;
out << std::endl
<< "%%%mzn-stat: initTime=" << initTime
<< std::endl;
out << "%%%mzn-stat: solveTime=" << solveTime
<< std::endl;
out << "%%%mzn-stat: solutions="
<< std::abs(noOfSolutions - findSol) << std::endl
<< "%%%mzn-stat: variables="
<< (intVarCount + boolVarCount + setVarCount) << std::endl
<< "%%%mzn-stat: propagators=" << n_p << std::endl
<< "%%%mzn-stat: propagations=" << sstat.propagate+stat.propagate << std::endl
<< "%%%mzn-stat: nodes=" << stat.node << std::endl
<< "%%%mzn-stat: failures=" << stat.fail << std::endl
<< "%%%mzn-stat: restarts=" << stat.restart << std::endl
<< "%%%mzn-stat: peakDepth=" << stat.depth << std::endl
<< "%%%mzn-stat-end" << std::endl
<< std::endl;
}
}
delete o.stop;
delete o.tracer;
}
#ifdef GECODE_HAS_QT
void
FlatZincSpace::branchWithPlugin(AST::Node* ann) {
if (AST::Call* c = dynamic_cast<AST::Call*>(ann)) {
QString pluginName(c->id.c_str());
if (QLibrary::isLibrary(pluginName+".dll")) {
pluginName += ".dll";
} else if (QLibrary::isLibrary(pluginName+".dylib")) {
pluginName = "lib" + pluginName + ".dylib";
} else if (QLibrary::isLibrary(pluginName+".so")) {
// Must check .so after .dylib so that Mac OS uses .dylib
pluginName = "lib" + pluginName + ".so";
}
QPluginLoader pl(pluginName);
QObject* plugin_o = pl.instance();
if (!plugin_o) {
throw FlatZinc::Error("FlatZinc",
"Error loading plugin "+pluginName.toStdString()+
": "+pl.errorString().toStdString());
}
BranchPlugin* pb = qobject_cast<BranchPlugin*>(plugin_o);
if (!pb) {
throw FlatZinc::Error("FlatZinc",
"Error loading plugin "+pluginName.toStdString()+
": does not contain valid PluginBrancher");
}
pb->branch(*this, c);
}
}
#else
void
FlatZincSpace::branchWithPlugin(AST::Node*) {
throw FlatZinc::Error("FlatZinc",
"Branching with plugins not supported (requires Qt support)");
}
#endif
void
FlatZincSpace::run(std::ostream& out, const Printer& p,
const FlatZincOptions& opt, Support::Timer& t_total) {
switch (_method) {
case MIN:
case MAX:
runEngine<BAB>(out,p,opt,t_total);
break;
case SAT:
runEngine<DFS>(out,p,opt,t_total);
break;
}
}
void
FlatZincSpace::constrain(const Space& s) {
if (_optVarIsInt) {
if (_method == MIN)
rel(*this, iv[_optVar], IRT_LE,
static_cast<const FlatZincSpace*>(&s)->iv[_optVar].val());
else if (_method == MAX)
rel(*this, iv[_optVar], IRT_GR,
static_cast<const FlatZincSpace*>(&s)->iv[_optVar].val());
} else {
#ifdef GECODE_HAS_FLOAT_VARS
if (_method == MIN)
rel(*this, fv[_optVar], FRT_LE,
static_cast<const FlatZincSpace*>(&s)->fv[_optVar].val()-step);
else if (_method == MAX)
rel(*this, fv[_optVar], FRT_GR,
static_cast<const FlatZincSpace*>(&s)->fv[_optVar].val()+step);
#endif
}
}
bool
FlatZincSpace::slave(const MetaInfo& mi) {
if ((mi.type() == MetaInfo::RESTART) && (mi.restart() != 0) &&
(_lns > 0) && (mi.last()==NULL) && (_lnsInitialSolution.size()>0)) {
for (unsigned int i=iv_lns.size(); i--;) {
if (_random(99) <= _lns) {
rel(*this, iv_lns[i], IRT_EQ, _lnsInitialSolution[i]);
}
}
return false;
} else if ((mi.type() == MetaInfo::RESTART) && (mi.restart() != 0) &&
(_lns > 0) && mi.last()) {
const FlatZincSpace& last =
static_cast<const FlatZincSpace&>(*mi.last());
for (unsigned int i=iv_lns.size(); i--;) {
if (_random(99) <= _lns) {
rel(*this, iv_lns[i], IRT_EQ, last.iv_lns[i]);
}
}
return false;
}
return true;
}
Space*
FlatZincSpace::copy(void) {
return new FlatZincSpace(*this);
}
FlatZincSpace::Meth
FlatZincSpace::method(void) const {
return _method;
}
int
FlatZincSpace::optVar(void) const {
return _optVar;
}
bool
FlatZincSpace::optVarIsInt(void) const {
return _optVarIsInt;
}
void
FlatZincSpace::print(std::ostream& out, const Printer& p) const {
p.print(out, iv, bv
#ifdef GECODE_HAS_SET_VARS
, sv
#endif
#ifdef GECODE_HAS_FLOAT_VARS
, fv
#endif
);
}
void
FlatZincSpace::compare(const Space& s, std::ostream& out) const {
(void) s; (void) out;
#ifdef GECODE_HAS_GIST
const FlatZincSpace& fs = dynamic_cast<const FlatZincSpace&>(s);
for (int i = 0; i < iv.size(); ++i) {
std::stringstream ss;
ss << "iv[" << i << "]";
std::string result(Gecode::Gist::Comparator::compare(ss.str(), iv[i],
fs.iv[i]));
if (result.length() > 0) out << result << std::endl;
}
for (int i = 0; i < bv.size(); ++i) {
std::stringstream ss;
ss << "bv[" << i << "]";
std::string result(Gecode::Gist::Comparator::compare(ss.str(), bv[i],
fs.bv[i]));
if (result.length() > 0) out << result << std::endl;
}
#ifdef GECODE_HAS_SET_VARS
for (int i = 0; i < sv.size(); ++i) {
std::stringstream ss;
ss << "sv[" << i << "]";
std::string result(Gecode::Gist::Comparator::compare(ss.str(), sv[i],
fs.sv[i]));
if (result.length() > 0) out << result << std::endl;
}
#endif
#ifdef GECODE_HAS_FLOAT_VARS
for (int i = 0; i < fv.size(); ++i) {
std::stringstream ss;
ss << "fv[" << i << "]";
std::string result(Gecode::Gist::Comparator::compare(ss.str(), fv[i],
fs.fv[i]));
if (result.length() > 0) out << result << std::endl;
}
#endif
#endif
}
void
FlatZincSpace::compare(const FlatZincSpace& s, std::ostream& out,
const Printer& p) const {
p.printDiff(out, iv, s.iv, bv, s.bv
#ifdef GECODE_HAS_SET_VARS
, sv, s.sv
#endif
#ifdef GECODE_HAS_FLOAT_VARS
, fv, s.fv
#endif
);
}
void
FlatZincSpace::shrinkArrays(Printer& p) {
p.shrinkArrays(*this, _optVar, _optVarIsInt, iv, bv
#ifdef GECODE_HAS_SET_VARS
, sv
#endif
#ifdef GECODE_HAS_FLOAT_VARS
, fv
#endif
);
}
IntArgs
FlatZincSpace::arg2intargs(AST::Node* arg, int offset) {
AST::Array* a = arg->getArray();
IntArgs ia(a->a.size()+offset);
for (int i=offset; i--;)
ia[i] = 0;
for (int i=a->a.size(); i--;)
ia[i+offset] = a->a[i]->getInt();
return ia;
}
TupleSet
FlatZincSpace::arg2tupleset(const IntArgs& a, int noOfVars) {
int noOfTuples = a.size() == 0 ? 0 : (a.size()/noOfVars);
// Build TupleSet
TupleSet ts(noOfVars);
for (int i=0; i<noOfTuples; i++) {
IntArgs t(noOfVars);
for (int j=0; j<noOfVars; j++) {
t[j] = a[i*noOfVars+j];
}
ts.add(t);
}
ts.finalize();
if (_initData) {
FlatZincSpaceInitData::TupleSetSet::iterator it = _initData->tupleSetSet.find(ts);
if (it != _initData->tupleSetSet.end()) {
return *it;
}
_initData->tupleSetSet.insert(ts);
}
return ts;
}
IntSharedArray
FlatZincSpace::arg2intsharedarray(AST::Node* arg, int offset) {
IntArgs ia(arg2intargs(arg,offset));
SharedArray<int> sia(ia);
if (_initData) {
FlatZincSpaceInitData::IntSharedArraySet::iterator it = _initData->intSharedArraySet.find(sia);
if (it != _initData->intSharedArraySet.end()) {
return *it;
}
_initData->intSharedArraySet.insert(sia);
}
return sia;
}
IntArgs
FlatZincSpace::arg2boolargs(AST::Node* arg, int offset) {
AST::Array* a = arg->getArray();
IntArgs ia(a->a.size()+offset);
for (int i=offset; i--;)
ia[i] = 0;
for (int i=a->a.size(); i--;)
ia[i+offset] = a->a[i]->getBool();
return ia;
}
IntSharedArray
FlatZincSpace::arg2boolsharedarray(AST::Node* arg, int offset) {
IntArgs ia(arg2boolargs(arg,offset));
SharedArray<int> sia(ia);
if (_initData) {
FlatZincSpaceInitData::IntSharedArraySet::iterator it = _initData->intSharedArraySet.find(sia);
if (it != _initData->intSharedArraySet.end()) {
return *it;
}
_initData->intSharedArraySet.insert(sia);
}
return sia;
}
IntSet
FlatZincSpace::arg2intset(AST::Node* n) {
AST::SetLit* sl = n->getSet();
IntSet d;
if (sl->interval) {
d = IntSet(sl->min, sl->max);
} else {
Region re;
int* is = re.alloc<int>(static_cast<unsigned long int>(sl->s.size()));
for (int i=sl->s.size(); i--; )
is[i] = sl->s[i];
d = IntSet(is, sl->s.size());
}
return d;
}
IntSetArgs
FlatZincSpace::arg2intsetargs(AST::Node* arg, int offset) {
AST::Array* a = arg->getArray();
if (a->a.size() == 0) {
IntSetArgs emptyIa(0);
return emptyIa;
}
IntSetArgs ia(a->a.size()+offset);
for (int i=offset; i--;)
ia[i] = IntSet::empty;
for (int i=a->a.size(); i--;) {
ia[i+offset] = arg2intset(a->a[i]);
}
return ia;
}
IntVarArgs
FlatZincSpace::arg2intvarargs(AST::Node* arg, int offset) {
AST::Array* a = arg->getArray();
if (a->a.size() == 0) {
IntVarArgs emptyIa(0);
return emptyIa;
}
IntVarArgs ia(a->a.size()+offset);
for (int i=offset; i--;)
ia[i] = IntVar(*this, 0, 0);
for (int i=a->a.size(); i--;) {
if (a->a[i]->isIntVar()) {
ia[i+offset] = iv[a->a[i]->getIntVar()];
} else {
int value = a->a[i]->getInt();
IntVar iv(*this, value, value);
ia[i+offset] = iv;
}
}
return ia;
}
BoolVarArgs
FlatZincSpace::arg2boolvarargs(AST::Node* arg, int offset, int siv) {
AST::Array* a = arg->getArray();
if (a->a.size() == 0) {
BoolVarArgs emptyIa(0);
return emptyIa;
}
BoolVarArgs ia(a->a.size()+offset-(siv==-1?0:1));
for (int i=offset; i--;)
ia[i] = BoolVar(*this, 0, 0);
for (int i=0; i<static_cast<int>(a->a.size()); i++) {
if (i==siv)
continue;
if (a->a[i]->isBool()) {
bool value = a->a[i]->getBool();
BoolVar iv(*this, value, value);
ia[offset++] = iv;
} else if (a->a[i]->isIntVar() &&
aliasBool2Int(a->a[i]->getIntVar()) != -1) {
ia[offset++] = bv[aliasBool2Int(a->a[i]->getIntVar())];
} else {
ia[offset++] = bv[a->a[i]->getBoolVar()];
}
}
return ia;
}
BoolVar
FlatZincSpace::arg2BoolVar(AST::Node* n) {
BoolVar x0;
if (n->isBool()) {
x0 = BoolVar(*this, n->getBool(), n->getBool());
}
else {
x0 = bv[n->getBoolVar()];
}
return x0;
}
IntVar
FlatZincSpace::arg2IntVar(AST::Node* n) {
IntVar x0;
if (n->isIntVar()) {
x0 = iv[n->getIntVar()];
} else {
x0 = IntVar(*this, n->getInt(), n->getInt());
}
return x0;
}
bool
FlatZincSpace::isBoolArray(AST::Node* b, int& singleInt) {
AST::Array* a = b->getArray();
singleInt = -1;
if (a->a.size() == 0)
return true;
for (int i=a->a.size(); i--;) {
if (a->a[i]->isBoolVar() || a->a[i]->isBool()) {
} else if (a->a[i]->isIntVar()) {
if (aliasBool2Int(a->a[i]->getIntVar()) == -1) {
if (singleInt != -1) {
return false;
}
singleInt = i;
}
} else {
return false;
}
}
return singleInt==-1 || a->a.size() > 1;
}
#ifdef GECODE_HAS_SET_VARS
SetVar
FlatZincSpace::arg2SetVar(AST::Node* n) {
SetVar x0;
if (!n->isSetVar()) {
IntSet d = arg2intset(n);
x0 = SetVar(*this, d, d);
} else {
x0 = sv[n->getSetVar()];
}
return x0;
}
SetVarArgs
FlatZincSpace::arg2setvarargs(AST::Node* arg, int offset, int doffset,
const IntSet& od) {
AST::Array* a = arg->getArray();
SetVarArgs ia(a->a.size()+offset);
for (int i=offset; i--;) {
IntSet d = i<doffset ? od : IntSet::empty;
ia[i] = SetVar(*this, d, d);
}
for (int i=a->a.size(); i--;) {
ia[i+offset] = arg2SetVar(a->a[i]);
}
return ia;
}
#endif
#ifdef GECODE_HAS_FLOAT_VARS
FloatValArgs
FlatZincSpace::arg2floatargs(AST::Node* arg, int offset) {
AST::Array* a = arg->getArray();
FloatValArgs fa(a->a.size()+offset);
for (int i=offset; i--;)
fa[i] = 0.0;
for (int i=a->a.size(); i--;)
fa[i+offset] = a->a[i]->getFloat();
return fa;
}
FloatVarArgs
FlatZincSpace::arg2floatvarargs(AST::Node* arg, int offset) {
AST::Array* a = arg->getArray();
if (a->a.size() == 0) {
FloatVarArgs emptyFa(0);
return emptyFa;
}
FloatVarArgs fa(a->a.size()+offset);
for (int i=offset; i--;)
fa[i] = FloatVar(*this, 0.0, 0.0);
for (int i=a->a.size(); i--;) {
if (a->a[i]->isFloatVar()) {
fa[i+offset] = fv[a->a[i]->getFloatVar()];
} else {
double value = a->a[i]->getFloat();
FloatVar fv(*this, value, value);
fa[i+offset] = fv;
}
}
return fa;
}
FloatVar
FlatZincSpace::arg2FloatVar(AST::Node* n) {
FloatVar x0;
if (n->isFloatVar()) {
x0 = fv[n->getFloatVar()];
} else {
x0 = FloatVar(*this, n->getFloat(), n->getFloat());
}
return x0;
}
#endif
IntPropLevel
FlatZincSpace::ann2ipl(AST::Node* ann) {
if (ann) {
if (ann->hasAtom("val"))
return IPL_VAL;
if (ann->hasAtom("domain"))
return IPL_DOM;
if (ann->hasAtom("bounds") ||
ann->hasAtom("boundsR") ||
ann->hasAtom("boundsD") ||
ann->hasAtom("boundsZ"))
return IPL_BND;
}
return IPL_DEF;
}
DFA
FlatZincSpace::getSharedDFA(DFA& a) {
if (_initData) {
FlatZincSpaceInitData::DFASet::iterator it = _initData->dfaSet.find(a);
if (it != _initData->dfaSet.end()) {
return *it;
}
_initData->dfaSet.insert(a);
}
return a;
}
void
Printer::init(AST::Array* output) {
_output = output;
}
void
Printer::printElem(std::ostream& out,
AST::Node* ai,
const Gecode::IntVarArray& iv,
const Gecode::BoolVarArray& bv
#ifdef GECODE_HAS_SET_VARS
, const Gecode::SetVarArray& sv
#endif
#ifdef GECODE_HAS_FLOAT_VARS
,
const Gecode::FloatVarArray& fv
#endif
) const {
int k;
if (ai->isInt(k)) {
out << k;
} else if (ai->isIntVar()) {
out << iv[ai->getIntVar()];
} else if (ai->isBoolVar()) {
if (bv[ai->getBoolVar()].min() == 1) {
out << "true";
} else if (bv[ai->getBoolVar()].max() == 0) {
out << "false";
} else {
out << "false..true";
}
#ifdef GECODE_HAS_SET_VARS
} else if (ai->isSetVar()) {
if (!sv[ai->getSetVar()].assigned()) {
out << sv[ai->getSetVar()];
return;
}
SetVarGlbRanges svr(sv[ai->getSetVar()]);
if (!svr()) {
out << "{}";
return;
}
int min = svr.min();
int max = svr.max();
++svr;
if (svr()) {
SetVarGlbValues svv(sv[ai->getSetVar()]);
int i = svv.val();
out << "{" << i;
++svv;
for (; svv(); ++svv)
out << ", " << svv.val();
out << "}";
} else {
out << min << ".." << max;
}
#endif
#ifdef GECODE_HAS_FLOAT_VARS
} else if (ai->isFloatVar()) {
if (fv[ai->getFloatVar()].assigned()) {
FloatVal vv = fv[ai->getFloatVar()].val();
FloatNum v;
if (vv.singleton())
v = vv.min();
else if (vv < 0.0)
v = vv.max();
else
v = vv.min();
std::ostringstream oss;
// oss << std::scientific;
oss << std::setprecision(std::numeric_limits<double>::digits10);
oss << v;
if (oss.str().find(".") == std::string::npos)
oss << ".0";
out << oss.str();
} else {
out << fv[ai->getFloatVar()];
}
#endif
} else if (ai->isBool()) {
out << (ai->getBool() ? "true" : "false");
} else if (ai->isSet()) {
AST::SetLit* s = ai->getSet();
if (s->interval) {
out << s->min << ".." << s->max;
} else {
out << "{";
for (unsigned int i=0; i<s->s.size(); i++) {
out << s->s[i] << (i < s->s.size()-1 ? ", " : "}");
}
}
} else if (ai->isString()) {
std::string s = ai->getString();
for (unsigned int i=0; i<s.size(); i++) {
if (s[i] == '\\' && i<s.size()-1) {
switch (s[i+1]) {
case 'n': out << "\n"; break;
case '\\': out << "\\"; break;
case 't': out << "\t"; break;
default: out << "\\" << s[i+1];
}
i++;
} else {
out << s[i];
}
}
}
}
void
Printer::printElemDiff(std::ostream& out,
AST::Node* ai,
const Gecode::IntVarArray& iv1,
const Gecode::IntVarArray& iv2,
const Gecode::BoolVarArray& bv1,
const Gecode::BoolVarArray& bv2
#ifdef GECODE_HAS_SET_VARS
, const Gecode::SetVarArray& sv1,
const Gecode::SetVarArray& sv2
#endif
#ifdef GECODE_HAS_FLOAT_VARS
, const Gecode::FloatVarArray& fv1,
const Gecode::FloatVarArray& fv2
#endif
) const {
#ifdef GECODE_HAS_GIST
using namespace Gecode::Gist;
int k;
if (ai->isInt(k)) {
out << k;
} else if (ai->isIntVar()) {
std::string res(Comparator::compare("",iv1[ai->getIntVar()],
iv2[ai->getIntVar()]));
if (res.length() > 0) {
res.erase(0, 1); // Remove '='
out << res;
} else {
out << iv1[ai->getIntVar()];
}
} else if (ai->isBoolVar()) {
std::string res(Comparator::compare("",bv1[ai->getBoolVar()],
bv2[ai->getBoolVar()]));
if (res.length() > 0) {
res.erase(0, 1); // Remove '='
out << res;
} else {
out << bv1[ai->getBoolVar()];
}
#ifdef GECODE_HAS_SET_VARS
} else if (ai->isSetVar()) {
std::string res(Comparator::compare("",sv1[ai->getSetVar()],
sv2[ai->getSetVar()]));
if (res.length() > 0) {
res.erase(0, 1); // Remove '='
out << res;
} else {
out << sv1[ai->getSetVar()];
}
#endif
#ifdef GECODE_HAS_FLOAT_VARS
} else if (ai->isFloatVar()) {
std::string res(Comparator::compare("",fv1[ai->getFloatVar()],
fv2[ai->getFloatVar()]));
if (res.length() > 0) {
res.erase(0, 1); // Remove '='
out << res;
} else {
out << fv1[ai->getFloatVar()];
}
#endif
} else if (ai->isBool()) {
out << (ai->getBool() ? "true" : "false");
} else if (ai->isSet()) {
AST::SetLit* s = ai->getSet();
if (s->interval) {
out << s->min << ".." << s->max;
} else {
out << "{";
for (unsigned int i=0; i<s->s.size(); i++) {
out << s->s[i] << (i < s->s.size()-1 ? ", " : "}");
}
}
} else if (ai->isString()) {
std::string s = ai->getString();
for (unsigned int i=0; i<s.size(); i++) {
if (s[i] == '\\' && i<s.size()-1) {
switch (s[i+1]) {
case 'n': out << "\n"; break;
case '\\': out << "\\"; break;
case 't': out << "\t"; break;
default: out << "\\" << s[i+1];
}
i++;
} else {
out << s[i];
}
}
}
#else
(void) out;
(void) ai;
(void) iv1;
(void) iv2;
(void) bv1;
(void) bv2;
#ifdef GECODE_HAS_SET_VARS
(void) sv1;
(void) sv2;
#endif
#ifdef GECODE_HAS_FLOAT_VARS
(void) fv1;
(void) fv2;
#endif
#endif
}
void
Printer::print(std::ostream& out,
const Gecode::IntVarArray& iv,
const Gecode::BoolVarArray& bv
#ifdef GECODE_HAS_SET_VARS
,
const Gecode::SetVarArray& sv
#endif
#ifdef GECODE_HAS_FLOAT_VARS
,
const Gecode::FloatVarArray& fv
#endif
) const {
if (_output == NULL)
return;
for (unsigned int i=0; i< _output->a.size(); i++) {
AST::Node* ai = _output->a[i];
if (ai->isArray()) {
AST::Array* aia = ai->getArray();
int size = aia->a.size();
out << "[";
for (int j=0; j<size; j++) {
printElem(out,aia->a[j],iv,bv
#ifdef GECODE_HAS_SET_VARS
,sv
#endif
#ifdef GECODE_HAS_FLOAT_VARS
,fv
#endif
);
if (j<size-1)
out << ", ";
}
out << "]";
} else {
printElem(out,ai,iv,bv
#ifdef GECODE_HAS_SET_VARS
,sv
#endif
#ifdef GECODE_HAS_FLOAT_VARS
,fv
#endif
);
}
}
}
void
Printer::printDiff(std::ostream& out,
const Gecode::IntVarArray& iv1,
const Gecode::IntVarArray& iv2,
const Gecode::BoolVarArray& bv1,
const Gecode::BoolVarArray& bv2
#ifdef GECODE_HAS_SET_VARS
,
const Gecode::SetVarArray& sv1,
const Gecode::SetVarArray& sv2
#endif
#ifdef GECODE_HAS_FLOAT_VARS
,
const Gecode::FloatVarArray& fv1,
const Gecode::FloatVarArray& fv2
#endif
) const {
if (_output == NULL)
return;
for (unsigned int i=0; i< _output->a.size(); i++) {
AST::Node* ai = _output->a[i];
if (ai->isArray()) {
AST::Array* aia = ai->getArray();
int size = aia->a.size();
out << "[";
for (int j=0; j<size; j++) {
printElemDiff(out,aia->a[j],iv1,iv2,bv1,bv2
#ifdef GECODE_HAS_SET_VARS
,sv1,sv2
#endif
#ifdef GECODE_HAS_FLOAT_VARS
,fv1,fv2
#endif
);
if (j<size-1)
out << ", ";
}
out << "]";
} else {
printElemDiff(out,ai,iv1,iv2,bv1,bv2
#ifdef GECODE_HAS_SET_VARS
,sv1,sv2
#endif
#ifdef GECODE_HAS_FLOAT_VARS
,fv1,fv2
#endif
);
}
}
}
void
Printer::addIntVarName(const std::string& n) {
iv_names.push_back(n);
}
void
Printer::addBoolVarName(const std::string& n) {
bv_names.push_back(n);
}
#ifdef GECODE_HAS_FLOAT_VARS
void
Printer::addFloatVarName(const std::string& n) {
fv_names.push_back(n);
}
#endif
#ifdef GECODE_HAS_SET_VARS
void
Printer::addSetVarName(const std::string& n) {
sv_names.push_back(n);
}
#endif
void
Printer::shrinkElement(AST::Node* node,
std::map<int,int>& iv, std::map<int,int>& bv,
std::map<int,int>& sv, std::map<int,int>& fv) {
if (node->isIntVar()) {
AST::IntVar* x = static_cast<AST::IntVar*>(node);
if (iv.find(x->i) == iv.end()) {
int newi = iv.size();
iv[x->i] = newi;
}
x->i = iv[x->i];
} else if (node->isBoolVar()) {
AST::BoolVar* x = static_cast<AST::BoolVar*>(node);
if (bv.find(x->i) == bv.end()) {
int newi = bv.size();
bv[x->i] = newi;
}
x->i = bv[x->i];
} else if (node->isSetVar()) {
AST::SetVar* x = static_cast<AST::SetVar*>(node);
if (sv.find(x->i) == sv.end()) {
int newi = sv.size();
sv[x->i] = newi;
}
x->i = sv[x->i];
} else if (node->isFloatVar()) {
AST::FloatVar* x = static_cast<AST::FloatVar*>(node);
if (fv.find(x->i) == fv.end()) {
int newi = fv.size();
fv[x->i] = newi;
}
x->i = fv[x->i];
}
}
void
Printer::shrinkArrays(Space& home,
int& optVar, bool optVarIsInt,
Gecode::IntVarArray& iv,
Gecode::BoolVarArray& bv
#ifdef GECODE_HAS_SET_VARS
,
Gecode::SetVarArray& sv
#endif
#ifdef GECODE_HAS_FLOAT_VARS
,
Gecode::FloatVarArray& fv
#endif
) {
if (_output == NULL) {
if (optVarIsInt && optVar != -1) {
IntVar ov = iv[optVar];
iv = IntVarArray(home, 1);
iv[0] = ov;
optVar = 0;
} else {
iv = IntVarArray(home, 0);
}
bv = BoolVarArray(home, 0);
#ifdef GECODE_HAS_SET_VARS
sv = SetVarArray(home, 0);
#endif
#ifdef GECODE_HAS_FLOAT_VARS
if (!optVarIsInt && optVar != -1) {
FloatVar ov = fv[optVar];
fv = FloatVarArray(home, 1);
fv[0] = ov;
optVar = 0;
} else {
fv = FloatVarArray(home,0);
}
#endif
return;
}
std::map<int,int> iv_new;
std::map<int,int> bv_new;
std::map<int,int> sv_new;
std::map<int,int> fv_new;
if (optVar != -1) {
if (optVarIsInt)
iv_new[optVar] = 0;
else
fv_new[optVar] = 0;
optVar = 0;
}
for (unsigned int i=0; i< _output->a.size(); i++) {
AST::Node* ai = _output->a[i];
if (ai->isArray()) {
AST::Array* aia = ai->getArray();
for (unsigned int j=0; j<aia->a.size(); j++) {
shrinkElement(aia->a[j],iv_new,bv_new,sv_new,fv_new);
}
} else {
shrinkElement(ai,iv_new,bv_new,sv_new,fv_new);
}
}
IntVarArgs iva(iv_new.size());
for (std::map<int,int>::iterator i=iv_new.begin(); i != iv_new.end(); ++i) {
iva[(*i).second] = iv[(*i).first];
}
iv = IntVarArray(home, iva);
BoolVarArgs bva(bv_new.size());
for (std::map<int,int>::iterator i=bv_new.begin(); i != bv_new.end(); ++i) {
bva[(*i).second] = bv[(*i).first];
}
bv = BoolVarArray(home, bva);
#ifdef GECODE_HAS_SET_VARS
SetVarArgs sva(sv_new.size());
for (std::map<int,int>::iterator i=sv_new.begin(); i != sv_new.end(); ++i) {
sva[(*i).second] = sv[(*i).first];
}
sv = SetVarArray(home, sva);
#endif
#ifdef GECODE_HAS_FLOAT_VARS
FloatVarArgs fva(fv_new.size());
for (std::map<int,int>::iterator i=fv_new.begin(); i != fv_new.end(); ++i) {
fva[(*i).second] = fv[(*i).first];
}
fv = FloatVarArray(home, fva);
#endif
}
Printer::~Printer(void) {
delete _output;
}
}}
// STATISTICS: flatzinc-any
Gecode::ActorLink::Actor
friend class Actor
Definition core.hpp:590
Gecode::Archive
Archive representation
Definition archive.hpp:42
Gecode::Archive::put
void put(unsigned int i)
Add i to the contents.
Definition archive.hpp:174
Gecode::ArgArrayBase::a
T * a
Element array.
Definition array.hpp:544
Gecode::ArgArrayBase::size
int size(void) const
Return size of array (number of elements).
Definition array.hpp:1607
Gecode::BAB
Depth-first branch-and-bound search engine.
Definition search.hh:1070
Gecode::BoolAssign
Which values to select for assignment.
Definition int.hh:5000
Gecode::BoolValBranch
Which values to select for branching first.
Definition int.hh:4889
Gecode::BoolVarArgs
Passing Boolean variables.
Definition int.hh:712
Gecode::BoolVarArray
Boolean variable array.
Definition int.hh:808
Gecode::BoolVar
Boolean integer variables.
Definition int.hh:512
Gecode::BrancherGroup
Group of branchers.
Definition core.hpp:799
Gecode::Brancher
Base-class for branchers.
Definition core.hpp:1442
Gecode::Brancher::Space
friend class Space
Definition core.hpp:1444
Gecode::Brancher::Brancher
Brancher(Home home)
Constructor for creation.
Definition core.hpp:3605
Gecode::Brancher::Choice
friend class Choice
Definition core.hpp:1445
Gecode::CPProfilerSearchTracer::GetInfo
Class to send solution information to CPProfiler.
Definition search.hh:423
Gecode::Choice
Choice for performing commit
Definition core.hpp:1412
Gecode::Choice::archive
virtual void archive(Archive &e) const
Archive into e.
Definition core.cpp:891
Gecode::DFA
Deterministic finite automaton (DFA).
Definition int.hh:2049
Gecode::DFS
Depth-first search engine.
Definition search.hh:1036
Gecode::Exception
Exception: Base-class for exceptions
Definition exception.hpp:42
Gecode::Exception::what
virtual const char * what(void) const
Return information.
Definition exception.cpp:55
Gecode::FlatZinc::AST::Array
Array node
Definition ast.hh:231
Gecode::FlatZinc::AST::Array::a
std::vector< Node * > a
Definition ast.hh:233
Gecode::FlatZinc::AST::Atom
Node representing an atom
Definition ast.hh:290
Gecode::FlatZinc::AST::BoolVar
Boolean variable node.
Definition ast.hh:197
Gecode::FlatZinc::AST::Call
Node representing a function call
Definition ast.hh:255
Gecode::FlatZinc::AST::Call::args
Node * args
Definition ast.hh:258
Gecode::FlatZinc::AST::Call::getArgs
Array * getArgs(unsigned int n)
Definition ast.hh:265
Gecode::FlatZinc::AST::FloatVar
Float variable node.
Definition ast.hh:214
Gecode::FlatZinc::AST::IntVar
Integer variable node.
Definition ast.hh:206
Gecode::FlatZinc::AST::Node
A node in a FlatZinc abstract syntax tree.
Definition ast.hh:67
Gecode::FlatZinc::AST::Node::isSetVar
bool isSetVar(void)
Test if node is a set variable node.
Definition ast.hh:478
Gecode::FlatZinc::AST::Node::getArray
Array * getArray(void)
Cast this node to an array node.
Definition ast.hh:396
Gecode::FlatZinc::AST::Node::isBool
bool isBool(void)
Test if node is a Boolean node.
Definition ast.hh:490
Gecode::FlatZinc::AST::Node::isFloatVar
bool isFloatVar(void)
Test if node is a float variable node.
Definition ast.hh:482
Gecode::FlatZinc::AST::Node::isSet
bool isSet(void)
Test if node is a set literal node.
Definition ast.hh:498
Gecode::FlatZinc::AST::Node::getFloat
double getFloat(void)
Cast this node to a Float node.
Definition ast.hh:452
Gecode::FlatZinc::AST::Node::getFloatVar
int getFloatVar(void)
Cast this node to a Float variable node.
Definition ast.hh:428
Gecode::FlatZinc::AST::Node::isArray
bool isArray(void)
Test if node is an array node.
Definition ast.hh:506
Gecode::FlatZinc::AST::Node::getSet
SetLit * getSet(void)
Cast this node to a set literal node.
Definition ast.hh:458
Gecode::FlatZinc::AST::Node::isString
bool isString(void)
Test if node is a string node.
Definition ast.hh:502
Gecode::FlatZinc::AST::Node::hasAtom
bool hasAtom(const std::string &id)
Test if node has atom with id.
Definition ast.hh:321
Gecode::FlatZinc::AST::Node::isInt
bool isInt(int &i)
Test if node is int, if yes set i to the value.
Definition ast.hh:364
Gecode::FlatZinc::AST::Node::getInt
int getInt(void)
Cast this node to an integer node.
Definition ast.hh:440
Gecode::FlatZinc::AST::Node::isIntVar
bool isIntVar(void)
Test if node is an integer variable node.
Definition ast.hh:470
Gecode::FlatZinc::AST::Node::getIntVar
int getIntVar(void)
Cast this node to an integer variable node.
Definition ast.hh:416
Gecode::FlatZinc::AST::Node::isBoolVar
bool isBoolVar(void)
Test if node is a Boolean variable node.
Definition ast.hh:474
Gecode::FlatZinc::AST::Node::getCall
Call * getCall(void)
Return function call.
Definition ast.hh:343
Gecode::FlatZinc::AST::Node::getBoolVar
int getBoolVar(void)
Cast this node to a Boolean variable node.
Definition ast.hh:422
Gecode::FlatZinc::AST::Node::print
virtual void print(std::ostream &)=0
Output string representation.
Gecode::FlatZinc::AST::Node::getSetVar
int getSetVar(void)
Cast this node to a set variable node.
Definition ast.hh:434
Gecode::FlatZinc::AST::Node::getBool
bool getBool(void)
Cast this node to a Boolean node.
Definition ast.hh:446
Gecode::FlatZinc::AST::Node::getString
std::string getString(void)
Cast this node to a string node.
Definition ast.hh:464
Gecode::FlatZinc::AST::SetLit
Set literal node
Definition ast.hh:171
Gecode::FlatZinc::AST::SetLit::max
int max
Definition ast.hh:174
Gecode::FlatZinc::AST::SetLit::min
int min
Definition ast.hh:174
Gecode::FlatZinc::AST::SetLit::interval
bool interval
Definition ast.hh:173
Gecode::FlatZinc::AST::SetLit::s
std::vector< int > s
Definition ast.hh:175
Gecode::FlatZinc::AST::SetVar
Set variable node
Definition ast.hh:222
Gecode::FlatZinc::AST::TypeError
Exception signaling type error
Definition ast.hh:55
Gecode::FlatZinc::AST::Var::i
int i
Definition ast.hh:191
Gecode::FlatZinc::AuxVarBrancher::Choice
Choice that only signals failure or success
Definition flatzinc.cpp:137
Gecode::FlatZinc::AuxVarBrancher::Choice::fail
bool fail
Whether brancher should fail.
Definition flatzinc.cpp:140
Gecode::FlatZinc::AuxVarBrancher::Choice::size
virtual size_t size(void) const
Report size occupied.
Definition flatzinc.cpp:145
Gecode::FlatZinc::AuxVarBrancher::Choice::Choice
Choice(const Brancher &b, bool fail0)
Initialize choice for brancher b.
Definition flatzinc.cpp:142
Gecode::FlatZinc::AuxVarBrancher::Choice::archive
virtual void archive(Archive &e) const
Archive into e.
Definition flatzinc.cpp:149
Gecode::FlatZinc::AuxVarBrancher::choice
virtual Choice * choice(const Space &, Archive &e)
Return choice.
Definition flatzinc.cpp:211
Gecode::FlatZinc::AuxVarBrancher::float_valsel
FloatValBranch float_valsel
Definition flatzinc.cpp:165
Gecode::FlatZinc::AuxVarBrancher::set_varsel
SetVarBranch set_varsel
Definition flatzinc.cpp:160
Gecode::FlatZinc::AuxVarBrancher::bool_varsel
TieBreak< BoolVarBranch > bool_varsel
Definition flatzinc.cpp:157
Gecode::FlatZinc::AuxVarBrancher::print
virtual void print(const Space &, const Gecode::Choice &c, unsigned int, std::ostream &o) const
Print explanation.
Definition flatzinc.cpp:220
Gecode::FlatZinc::AuxVarBrancher::int_valsel
IntValBranch int_valsel
Definition flatzinc.cpp:156
Gecode::FlatZinc::AuxVarBrancher::int_varsel
TieBreak< IntVarBranch > int_varsel
Definition flatzinc.cpp:155
Gecode::FlatZinc::AuxVarBrancher::set_valsel
SetValBranch set_valsel
Definition flatzinc.cpp:161
Gecode::FlatZinc::AuxVarBrancher::status
virtual bool status(const Space &_home) const
Check status of brancher, return true if alternatives left.
Definition flatzinc.cpp:170
Gecode::FlatZinc::AuxVarBrancher::done
bool done
Flag whether brancher is done.
Definition flatzinc.cpp:105
Gecode::FlatZinc::AuxVarBrancher::copy
virtual Actor * copy(Space &home)
Copy brancher.
Definition flatzinc.cpp:228
Gecode::FlatZinc::AuxVarBrancher::post
static void post(Home home, TieBreak< IntVarBranch > int_varsel, IntValBranch int_valsel, TieBreak< BoolVarBranch > bool_varsel, BoolValBranch bool_valsel, SetVarBranch set_varsel, SetValBranch set_valsel, TieBreak< FloatVarBranch > float_varsel, FloatValBranch float_valsel)
Post brancher.
Definition flatzinc.cpp:232
Gecode::FlatZinc::AuxVarBrancher::float_varsel
TieBreak< FloatVarBranch > float_varsel
Definition flatzinc.cpp:164
Gecode::FlatZinc::AuxVarBrancher::choice
virtual Choice * choice(Space &home)
Return choice.
Definition flatzinc.cpp:189
Gecode::FlatZinc::AuxVarBrancher::commit
virtual ExecStatus commit(Space &, const Gecode::Choice &c, unsigned int)
Perform commit for choice c.
Definition flatzinc.cpp:216
Gecode::FlatZinc::AuxVarBrancher::dispose
virtual size_t dispose(Space &)
Delete brancher and return its size.
Definition flatzinc.cpp:259
Gecode::FlatZinc::AuxVarBrancher::bool_valsel
BoolValBranch bool_valsel
Definition flatzinc.cpp:158
Gecode::FlatZinc::AuxVarBrancher::AuxVarBrancher
AuxVarBrancher(Home home, TieBreak< IntVarBranch > int_varsel0, IntValBranch int_valsel0, TieBreak< BoolVarBranch > bool_varsel0, BoolValBranch bool_valsel0, SetVarBranch set_varsel0, SetValBranch set_valsel0, TieBreak< FloatVarBranch > float_varsel0, FloatValBranch float_valsel0)
Construct brancher.
Definition flatzinc.cpp:107
Gecode::FlatZinc::AuxVarBrancher::AuxVarBrancher
AuxVarBrancher(Space &home, AuxVarBrancher &b)
Copy constructor.
Definition flatzinc.cpp:133
Gecode::FlatZinc::BoolVarSpec
Specification for Boolean variables.
Definition varspec.hh:97
Gecode::FlatZinc::BoolVarSpec::domain
Option< AST::SetLit * > domain
Definition varspec.hh:99
Gecode::FlatZinc::BranchInformationO
Definition flatzinc.cpp:264
Gecode::FlatZinc::BranchInformationO::print
void print(const Brancher &b, unsigned int a, int i, int n, std::ostream &o) const
Output branch information.
Definition flatzinc.cpp:292
Gecode::FlatZinc::BranchInformationO::~BranchInformationO
virtual ~BranchInformationO(void)
Definition flatzinc.cpp:279
Gecode::FlatZinc::BranchInformationO::add
void add(BrancherGroup bg, const std::string &rel0, const std::string &rel1, const std::vector< std::string > &n)
Add new brancher information.
Definition flatzinc.cpp:284
Gecode::FlatZinc::BranchInformationO::print
void print(const Brancher &b, unsigned int a, int i, const FloatNumBranch &nl, std::ostream &o) const
Definition flatzinc.cpp:298
Gecode::FlatZinc::BranchInformationO::copy
virtual SharedHandle::Object * copy(void) const
Definition flatzinc.cpp:280
Gecode::FlatZinc::BranchInformationO::BranchInformationO
BranchInformationO(void)
Definition flatzinc.cpp:278
Gecode::FlatZinc::BranchInformation::init
void init(void)
Initialise for use.
Definition flatzinc.cpp:315
Gecode::FlatZinc::BranchInformation::print
void print(const Brancher &b, unsigned int a, int i, int n, std::ostream &o) const
Output branch information.
Definition flatzinc.cpp:328
Gecode::FlatZinc::BranchInformation::BranchInformation
BranchInformation(void)
Constructor.
Definition flatzinc.cpp:308
Gecode::FlatZinc::BranchInformation::add
void add(BrancherGroup bg, const std::string &rel0, const std::string &rel1, const std::vector< std::string > &n)
Add new brancher information.
Definition flatzinc.cpp:321
Gecode::FlatZinc::ConExpr
Abstract representation of a constraint.
Definition conexpr.hh:43
Gecode::FlatZinc::Error
Exception class for FlatZinc errors
Definition flatzinc.hh:665
Gecode::FlatZinc::FZPrintingComparator
Definition flatzinc.cpp:1700
Gecode::FlatZinc::FZPrintingComparator::compare
virtual void compare(const Space &s0, const Space &s1)
Use the compare method of the template class S to compare two spaces.
Definition flatzinc.cpp:1717
Gecode::FlatZinc::FZPrintingComparator::FZPrintingComparator
FZPrintingComparator(const Printer &p0)
Constructor.
Definition flatzinc.cpp:1712
Gecode::FlatZinc::FZPrintingInspector
An inspector for printing simple text output.
Definition flatzinc.cpp:1668
Gecode::FlatZinc::FZPrintingInspector::finalize
virtual void finalize(void)
Finalize when Gist exits.
Definition flatzinc.cpp:1694
Gecode::FlatZinc::FZPrintingInspector::FZPrintingInspector
FZPrintingInspector(const Printer &p0)
Constructor.
Definition flatzinc.cpp:1681
Gecode::FlatZinc::FZPrintingInspector::inspect
virtual void inspect(const Space &node)
Use the print method of the template class S to print a space.
Definition flatzinc.cpp:1686
Gecode::FlatZinc::FlatZincGetInfo::FlatZincGetInfo
FlatZincGetInfo(const Printer &printer)
Definition flatzinc.cpp:1746
Gecode::FlatZinc::FlatZincGetInfo::p
const Printer & p
Definition flatzinc.cpp:1745
Gecode::FlatZinc::FlatZincGetInfo::~FlatZincGetInfo
~FlatZincGetInfo(void)
Definition flatzinc.cpp:1757
Gecode::FlatZinc::FlatZincGetInfo::getInfo
virtual std::string getInfo(const Space &space) const
Return info for a space.
Definition flatzinc.cpp:1748
Gecode::FlatZinc::FlatZincOptions
Options for running FlatZinc models
Definition flatzinc.hh:226
Gecode::FlatZinc::FlatZincSpaceInitData
Definition flatzinc.cpp:753
Gecode::FlatZinc::FlatZincSpaceInitData::TupleSetSet
std::unordered_set< TupleSet > TupleSetSet
Hash table of tuple sets.
Definition flatzinc.cpp:756
Gecode::FlatZinc::FlatZincSpaceInitData::dfaSet
DFASet dfaSet
Hash table of DFAs.
Definition flatzinc.cpp:768
Gecode::FlatZinc::FlatZincSpaceInitData::DFASet
std::unordered_set< DFA > DFASet
Hash table of DFAs.
Definition flatzinc.cpp:766
Gecode::FlatZinc::FlatZincSpaceInitData::FlatZincSpaceInitData
FlatZincSpaceInitData(void)
Initialize.
Definition flatzinc.cpp:771
Gecode::FlatZinc::FlatZincSpaceInitData::intSharedArraySet
IntSharedArraySet intSharedArraySet
Hash table of shared integer arrays.
Definition flatzinc.cpp:763
Gecode::FlatZinc::FlatZincSpaceInitData::tupleSetSet
TupleSetSet tupleSetSet
Hash table of tuple sets.
Definition flatzinc.cpp:758
Gecode::FlatZinc::FlatZincSpaceInitData::IntSharedArraySet
std::unordered_set< SharedArray< int > > IntSharedArraySet
Hash table of shared integer arrays.
Definition flatzinc.cpp:761
Gecode::FlatZinc::FlatZincSpace
A space that can be initialized with a FlatZinc model.
Definition flatzinc.hh:428
Gecode::FlatZinc::FlatZincSpace::createBranchers
void createBranchers(Printer &p, AST::Node *ann, FlatZincOptions &opt, bool ignoreUnknown, std::ostream &err=std::cerr)
Create branchers corresponding to the solve item annotations.
Definition flatzinc.cpp:1037
Gecode::FlatZinc::FlatZincSpace::iv_lns
Gecode::IntVarArray iv_lns
The integer variables used in LNS.
Definition flatzinc.hh:490
Gecode::FlatZinc::FlatZincSpace::shrinkArrays
void shrinkArrays(Printer &p)
Remove all variables not needed for output.
Definition flatzinc.cpp:2111
Gecode::FlatZinc::FlatZincSpace::_lns
unsigned int _lns
Percentage of variables to keep in LNS (or 0 for no LNS).
Definition flatzinc.hh:456
Gecode::FlatZinc::FlatZincSpace::maximize
void maximize(int var, bool isInt, AST::Array *annotation)
Post that integer variable var should be maximized.
Definition flatzinc.cpp:1616
Gecode::FlatZinc::FlatZincSpace::arg2intvarargs
IntVarArgs arg2intvarargs(AST::Node *arg, int offset=0)
Convert arg to IntVarArgs.
Definition flatzinc.cpp:2227
Gecode::FlatZinc::FlatZincSpace::fv
Gecode::FloatVarArray fv
The float variables.
Definition flatzinc.hh:512
Gecode::FlatZinc::FlatZincSpace::_random
Rnd _random
Random number generator.
Definition flatzinc.hh:462
Gecode::FlatZinc::FlatZincSpace::newBoolVar
void newBoolVar(BoolVarSpec *vs)
Create new Boolean variable from specification.
Definition flatzinc.cpp:908
Gecode::FlatZinc::FlatZincSpace::arg2FloatVar
FloatVar arg2FloatVar(AST::Node *n)
Convert n to FloatVar.
Definition flatzinc.cpp:2375
Gecode::FlatZinc::FlatZincSpace::print
void print(std::ostream &out, const Printer &p) const
Produce output on out using p.
Definition flatzinc.cpp:2046
Gecode::FlatZinc::FlatZincSpace::fv_introduced
std::vector< bool > fv_introduced
Indicates whether a float variable is introduced by mzn2fzn.
Definition flatzinc.hh:516
Gecode::FlatZinc::FlatZincSpace::_solveAnnotations
AST::Array * _solveAnnotations
Annotations on the solve item.
Definition flatzinc.hh:465
Gecode::FlatZinc::FlatZincSpace::_optVar
int _optVar
Index of the variable to optimize.
Definition flatzinc.hh:448
Gecode::FlatZinc::FlatZincSpace::branchInfo
BranchInformation branchInfo
Information for printing branches.
Definition flatzinc.hh:607
Gecode::FlatZinc::FlatZincSpace::run
void run(std::ostream &out, const Printer &p, const FlatZincOptions &opt, Gecode::Support::Timer &t_total)
Run the search.
Definition flatzinc.cpp:1967
Gecode::FlatZinc::FlatZincSpace::getSharedDFA
DFA getSharedDFA(DFA &a)
Share DFA a if possible.
Definition flatzinc.cpp:2402
Gecode::FlatZinc::FlatZincSpace::newFloatVar
void newFloatVar(FloatVarSpec *vs)
Create new float variable from specification.
Definition flatzinc.cpp:967
Gecode::FlatZinc::FlatZincSpace::arg2SetVar
SetVar arg2SetVar(AST::Node *n)
Convert n to SetVar.
Definition flatzinc.cpp:2317
Gecode::FlatZinc::FlatZincSpace::iv_boolalias
int * iv_boolalias
Indicates whether an integer variable aliases a Boolean variable.
Definition flatzinc.hh:495
Gecode::FlatZinc::FlatZincSpace::slave
virtual bool slave(const MetaInfo &mi)
Slave function for restarts.
Definition flatzinc.cpp:2002
Gecode::FlatZinc::FlatZincSpace::postConstraints
void postConstraints(std::vector< ConExpr * > &ces)
Post a constraint specified by ce.
Definition flatzinc.cpp:1004
Gecode::FlatZinc::FlatZincSpace::arg2setvarargs
SetVarArgs arg2setvarargs(AST::Node *arg, int offset=0, int doffset=0, const IntSet &od=IntSet::empty)
Convert n to SetVarArgs.
Definition flatzinc.cpp:2328
Gecode::FlatZinc::FlatZincSpace::_optVarIsInt
bool _optVarIsInt
Whether variable to optimize is integer (or float).
Definition flatzinc.hh:450
Gecode::FlatZinc::FlatZincSpace::FlatZincSpace
FlatZincSpace(FlatZincSpace &)
Copy constructor.
Definition flatzinc.cpp:774
Gecode::FlatZinc::FlatZincSpace::bv
Gecode::BoolVarArray bv
The Boolean variables.
Definition flatzinc.hh:497
Gecode::FlatZinc::FlatZincSpace::newSetVar
void newSetVar(SetVarSpec *vs)
Create new set variable from specification.
Definition flatzinc.cpp:920
Gecode::FlatZinc::FlatZincSpace::optVarIsInt
bool optVarIsInt(void) const
Return whether variable used for optimization is integer (or float).
Definition flatzinc.cpp:2041
Gecode::FlatZinc::FlatZincSpace::iv_introduced
std::vector< bool > iv_introduced
Indicates whether an integer variable is introduced by mzn2fzn.
Definition flatzinc.hh:493
Gecode::FlatZinc::FlatZincSpace::arg2IntVar
IntVar arg2IntVar(AST::Node *n)
Convert n to IntVar.
Definition flatzinc.cpp:2285
Gecode::FlatZinc::FlatZincSpace::getDomains
std::string getDomains(const Printer &p) const
Get string representing the domains of variables (for cpprofiler).
Definition flatzinc.cpp:1795
Gecode::FlatZinc::FlatZincSpace::_initData
FlatZincSpaceInitData * _initData
Initialisation data (only used for posting constraints).
Definition flatzinc.hh:437
Gecode::FlatZinc::FlatZincSpace::method
Meth method(void) const
Return whether to solve a satisfaction or optimization problem.
Definition flatzinc.cpp:2031
Gecode::FlatZinc::FlatZincSpace::sv_introduced
std::vector< bool > sv_introduced
Indicates whether a set variable is introduced by mzn2fzn.
Definition flatzinc.hh:508
Gecode::FlatZinc::FlatZincSpace::arg2intset
IntSet arg2intset(AST::Node *n)
Convert n to IntSet.
Definition flatzinc.cpp:2197
Gecode::FlatZinc::FlatZincSpace::bv_introduced
std::vector< bool > bv_introduced
Indicates whether a Boolean variable is introduced by mzn2fzn.
Definition flatzinc.hh:501
Gecode::FlatZinc::FlatZincSpace::fv_aux
Gecode::FloatVarArray fv_aux
The introduced float variables.
Definition flatzinc.hh:514
Gecode::FlatZinc::FlatZincSpace::minimize
void minimize(int var, bool isInt, AST::Array *annotation)
Post that integer variable var should be minimized.
Definition flatzinc.cpp:1608
Gecode::FlatZinc::FlatZincSpace::constrain
virtual void constrain(const Space &s)
Implement optimization.
Definition flatzinc.cpp:1981
Gecode::FlatZinc::FlatZincSpace::arg2boolargs
IntArgs arg2boolargs(AST::Node *arg, int offset=0)
Convert arg (array of Booleans) to IntArgs.
Definition flatzinc.cpp:2173
Gecode::FlatZinc::FlatZincSpace::sv_aux
Gecode::SetVarArray sv_aux
The introduced set variables.
Definition flatzinc.hh:506
Gecode::FlatZinc::FlatZincSpace::floatVarCount
int floatVarCount
Number of float variables.
Definition flatzinc.hh:443
Gecode::FlatZinc::FlatZincSpace::boolVarCount
int boolVarCount
Number of Boolean variables.
Definition flatzinc.hh:441
Gecode::FlatZinc::FlatZincSpace::sv
Gecode::SetVarArray sv
The set variables.
Definition flatzinc.hh:504
Gecode::FlatZinc::FlatZincSpace::setVarCount
int setVarCount
Number of set variables.
Definition flatzinc.hh:445
Gecode::FlatZinc::FlatZincSpace::~FlatZincSpace
~FlatZincSpace(void)
Destructor.
Definition flatzinc.cpp:1623
Gecode::FlatZinc::FlatZincSpace::optVar
int optVar(void) const
Return index of variable used for optimization.
Definition flatzinc.cpp:2036
Gecode::FlatZinc::FlatZincSpace::arg2floatvarargs
FloatVarArgs arg2floatvarargs(AST::Node *arg, int offset=0)
Convert n to FloatVarArgs.
Definition flatzinc.cpp:2354
Gecode::FlatZinc::FlatZincSpace::arg2boolsharedarray
IntSharedArray arg2boolsharedarray(AST::Node *arg, int offset=0)
Convert arg (array of integers) to IntSharedArray.
Definition flatzinc.cpp:2183
Gecode::FlatZinc::FlatZincSpace::solve
void solve(AST::Array *annotation)
Post the solve item.
Definition flatzinc.cpp:1602
Gecode::FlatZinc::FlatZincSpace::step
Gecode::FloatNum step
Step by which a next solution has to have lower cost.
Definition flatzinc.hh:518
Gecode::FlatZinc::FlatZincSpace::_lnsInitialSolution
IntSharedArray _lnsInitialSolution
Initial solution to start the LNS (or NULL for no LNS).
Definition flatzinc.hh:459
Gecode::FlatZinc::FlatZincSpace::bv_aux
Gecode::BoolVarArray bv_aux
The introduced Boolean variables.
Definition flatzinc.hh:499
Gecode::FlatZinc::FlatZincSpace::arg2intsharedarray
IntSharedArray arg2intsharedarray(AST::Node *arg, int offset=0)
Convert arg (array of integers) to IntSharedArray.
Definition flatzinc.cpp:2159
Gecode::FlatZinc::FlatZincSpace::arg2boolvarargs
BoolVarArgs arg2boolvarargs(AST::Node *arg, int offset=0, int siv=-1)
Convert arg to BoolVarArgs.
Definition flatzinc.cpp:2248
Gecode::FlatZinc::FlatZincSpace::aliasBool2Int
void aliasBool2Int(int iv, int bv)
Link integer variable iv to Boolean variable bv.
Definition flatzinc.cpp:899
Gecode::FlatZinc::FlatZincSpace::solveAnnotations
AST::Array * solveAnnotations(void) const
Return the solve item annotations.
Definition flatzinc.cpp:1597
Gecode::FlatZinc::FlatZincSpace::iv_aux
Gecode::IntVarArray iv_aux
The introduced integer variables.
Definition flatzinc.hh:487
Gecode::FlatZinc::FlatZincSpace::iv
Gecode::IntVarArray iv
The integer variables.
Definition flatzinc.hh:485
Gecode::FlatZinc::FlatZincSpace::copy
virtual Gecode::Space * copy(void)
Copy function.
Definition flatzinc.cpp:2026
Gecode::FlatZinc::FlatZincSpace::init
void init(int intVars, int boolVars, int setVars, int floatVars)
Initialize space with given number of variables.
Definition flatzinc.cpp:856
Gecode::FlatZinc::FlatZincSpace::isBoolArray
bool isBoolArray(AST::Node *b, int &singleInt)
Check if b is array of Booleans (or has a single integer).
Definition flatzinc.cpp:2295
Gecode::FlatZinc::FlatZincSpace::ann2ipl
IntPropLevel ann2ipl(AST::Node *ann)
Convert ann to integer propagation level.
Definition flatzinc.cpp:2386
Gecode::FlatZinc::FlatZincSpace::newIntVar
void newIntVar(IntVarSpec *vs)
Create new integer variable from specification.
Definition flatzinc.cpp:881
Gecode::FlatZinc::FlatZincSpace::_method
Meth _method
Whether to solve as satisfaction or optimization problem.
Definition flatzinc.hh:453
Gecode::FlatZinc::FlatZincSpace::compare
void compare(const Space &s, std::ostream &out) const
Compare this space with space s and print the differences on out.
Definition flatzinc.cpp:2058
Gecode::FlatZinc::FlatZincSpace::Meth
Meth
Definition flatzinc.hh:430
Gecode::FlatZinc::FlatZincSpace::MIN
@ MIN
Definition flatzinc.hh:432
Gecode::FlatZinc::FlatZincSpace::SAT
@ SAT
Definition flatzinc.hh:431
Gecode::FlatZinc::FlatZincSpace::MAX
@ MAX
Definition flatzinc.hh:433
Gecode::FlatZinc::FlatZincSpace::intVarCount
int intVarCount
Number of integer variables.
Definition flatzinc.hh:439
Gecode::FlatZinc::FlatZincSpace::arg2BoolVar
BoolVar arg2BoolVar(AST::Node *n)
Convert n to BoolVar.
Definition flatzinc.cpp:2274
Gecode::FlatZinc::FlatZincSpace::arg2tupleset
TupleSet arg2tupleset(const IntArgs &a, int noOfVars)
Convert a to TupleSet.
Definition flatzinc.cpp:2133
Gecode::FlatZinc::FlatZincSpace::arg2intsetargs
IntSetArgs arg2intsetargs(AST::Node *arg, int offset=0)
Convert arg to IntSetArgs.
Definition flatzinc.cpp:2212
Gecode::FlatZinc::FlatZincSpace::arg2floatargs
FloatValArgs arg2floatargs(AST::Node *arg, int offset=0)
Convert n to FloatValArgs.
Definition flatzinc.cpp:2344
Gecode::FlatZinc::FlatZincSpace::needAuxVars
bool needAuxVars
Whether the introduced variables still need to be copied.
Definition flatzinc.hh:521
Gecode::FlatZinc::FlatZincSpace::arg2intargs
IntArgs arg2intargs(AST::Node *arg, int offset=0)
Convert arg (array of integers) to IntArgs.
Definition flatzinc.cpp:2123
Gecode::FlatZinc::FloatVarSpec
Specification for floating point variables.
Definition varspec.hh:119
Gecode::FlatZinc::FloatVarSpec::domain
Option< std::pair< double, double > > domain
Definition varspec.hh:121
Gecode::FlatZinc::GistEngine< BAB< S > >::explore
static void explore(S *root, const FlatZincOptions &opt, Gist::Inspector *i, Gist::Comparator *c)
Definition flatzinc.cpp:1655
Gecode::FlatZinc::GistEngine< DFS< S > >::explore
static void explore(S *root, const FlatZincOptions &opt, Gist::Inspector *i, Gist::Comparator *c)
Definition flatzinc.cpp:1641
Gecode::FlatZinc::GistEngine
Traits class for search engines.
Definition flatzinc.cpp:1634
Gecode::FlatZinc::IntBoolVarBranch
Which integer or Boolean variable to select for branching.
Definition branch.hh:44
Gecode::FlatZinc::IntVarSpec
Specification for integer variables.
Definition varspec.hh:72
Gecode::FlatZinc::IntVarSpec::domain
Option< AST::SetLit * > domain
Definition varspec.hh:74
Gecode::FlatZinc::Printer
Output support class for FlatZinc interpreter.
Definition flatzinc.hh:107
Gecode::FlatZinc::Printer::addFloatVarName
void addFloatVarName(const std::string &n)
Definition flatzinc.cpp:2738
Gecode::FlatZinc::Printer::printDiff
void printDiff(std::ostream &out, const Gecode::IntVarArray &iv1, const Gecode::IntVarArray &iv2, const Gecode::BoolVarArray &bv1, const Gecode::BoolVarArray &bv2, const Gecode::SetVarArray &sv1, const Gecode::SetVarArray &sv2, const Gecode::FloatVarArray &fv1, const Gecode::FloatVarArray &fv2) const
Definition flatzinc.cpp:2678
Gecode::FlatZinc::Printer::addSetVarName
void addSetVarName(const std::string &n)
Definition flatzinc.cpp:2744
Gecode::FlatZinc::Printer::init
void init(AST::Array *output)
Definition flatzinc.cpp:2414
Gecode::FlatZinc::Printer::~Printer
~Printer(void)
Definition flatzinc.cpp:2877
Gecode::FlatZinc::Printer::print
void print(std::ostream &out, const Gecode::IntVarArray &iv, const Gecode::BoolVarArray &bv, const Gecode::SetVarArray &sv, const Gecode::FloatVarArray &fv) const
Definition flatzinc.cpp:2631
Gecode::FlatZinc::Printer::shrinkArrays
void shrinkArrays(Space &home, int &optVar, bool optVarIsInt, Gecode::IntVarArray &iv, Gecode::BoolVarArray &bv, Gecode::SetVarArray &sv, Gecode::FloatVarArray &fv)
Definition flatzinc.cpp:2785
Gecode::FlatZinc::Printer::addIntVarName
void addIntVarName(const std::string &n)
Definition flatzinc.cpp:2729
Gecode::FlatZinc::Printer::addBoolVarName
void addBoolVarName(const std::string &n)
Definition flatzinc.cpp:2733
Gecode::FlatZinc::Printer::shrinkElement
void shrinkElement(AST::Node *node, std::map< int, int > &iv, std::map< int, int > &bv, std::map< int, int > &sv, std::map< int, int > &fv)
Definition flatzinc.cpp:2750
Gecode::FlatZinc::Registry::post
void post(FlatZincSpace &s, const ConExpr &ce)
Post constraint specified by ce.
Definition registry.cpp:59
Gecode::FlatZinc::SetVarSpec
Specification for set variables.
Definition varspec.hh:139
Gecode::FlatZinc::SetVarSpec::upperBound
Option< AST::SetLit * > upperBound
Definition varspec.hh:141
Gecode::FlatZinc::VarSpec::i
int i
Variable index.
Definition varspec.hh:57
Gecode::FlatZinc::VarSpec::introduced
bool introduced
Whether the variable was introduced in the mzn2fzn translation.
Definition varspec.hh:63
Gecode::FlatZinc::VarSpec::assigned
bool assigned
Whether the variable is assigned.
Definition varspec.hh:61
Gecode::FlatZinc::VarSpec::alias
bool alias
Whether the variable aliases another variable.
Definition varspec.hh:59
Gecode::FlatZinc::VarSpec::funcDep
bool funcDep
Whether the variable functionally depends on another variable.
Definition varspec.hh:65
Gecode::FloatNumBranch
Value description class for branching.
Definition float.hh:1462
Gecode::FloatNumBranch::l
bool l
Whether to try the lower or upper half first.
Definition float.hh:1467
Gecode::FloatNumBranch::n
FloatNum n
The middle value for branching.
Definition float.hh:1465
Gecode::FloatValArgs
Passing float arguments.
Definition float.hh:950
Gecode::FloatValBranch
Which values to select for branching first.
Definition float.hh:1820
Gecode::FloatVal::size
FloatNum size(void) const
Return size of float value (distance between maximum and minimum).
Definition val.hpp:78
Gecode::FloatVarArgs
Passing float variables.
Definition float.hh:979
Gecode::FloatVarArray
Float variable array.
Definition float.hh:1030
Gecode::FloatVar
Float variables.
Definition float.hh:870
Gecode::Float::FloatView
Float view for float variables.
Definition view.hpp:52
Gecode::Gist::Comparator
Abstract base class for comparators.
Definition gist.hh:119
Gecode::Gist::Comparator::compare
virtual void compare(const Space &s0, const Space &s1)=0
Call-back function.
Gecode::Gist::Inspector
Abstract base class for inspectors.
Definition gist.hh:99
Gecode::Gist::Options::_I::click
void click(Inspector *i)
Add inspector that reacts on node double clicks.
Definition gist.hpp:170
Gecode::Gist::Options::_I::compare
void compare(Comparator *c)
Add comparator.
Definition gist.hpp:182
Gecode::Gist::Options
Options for Gist
Definition gist.hh:234
Gecode::Gist::Options::inspect
class Gecode::Gist::Options::_I inspect
Gecode::Gist::TextOutput
An window for simple text output.
Definition gist.hh:160
Gecode::Gist::TextOutput::finalize
void finalize(void)
Clean up when Gist exits.
Definition gist.cpp:64
Gecode::Gist::TextOutput::TextOutput
TextOutput(const std::string &name)
Constructor.
Definition gist.cpp:60
Gecode::Gist::TextOutput::getStream
std::ostream & getStream(void)
Get the stream that is used to output text.
Definition gist.cpp:85
Gecode::Gist::TextOutput::init
void init(void)
Initialize the implementation object.
Definition gist.cpp:77
Gecode::Gist::VarComparator
A simple comparator.
Definition gist.hh:211
Gecode::Gist::VarComparator::VarComparator
VarComparator(std::string name)
Constructor.
Definition gist.hpp:37
Gecode::Group::id
unsigned int id(void) const
Return a unique id for the group.
Definition core.hpp:4974
Gecode::Home
Home class for posting propagators
Definition core.hpp:856
Gecode::IntArgs
Passing integer arguments.
Definition int.hh:628
Gecode::IntAssign
Which values to select for assignment.
Definition int.hh:4971
Gecode::IntSet
Integer sets.
Definition int.hh:174
Gecode::IntSet::empty
static const IntSet empty
Empty set.
Definition int.hh:283
Gecode::IntValBranch
Which values to select for branching first.
Definition int.hh:4854
Gecode::IntVarArgs
Passing integer variables.
Definition int.hh:656
Gecode::IntVarArray
Integer variable array.
Definition int.hh:763
Gecode::IntVar
Integer variables.
Definition int.hh:371
Gecode::Int::IntView
Integer view for integer variables.
Definition view.hpp:129
Gecode::Int::IntView::min
int min(void) const
Return minimum of domain.
Definition int.hpp:58
Gecode::Int::IntView::range
bool range(void) const
Test whether domain is a range.
Definition int.hpp:103
Gecode::Int::IntView::val
int val(void) const
Return assigned value (only if assigned).
Definition int.hpp:70
Gecode::Int::IntView::max
int max(void) const
Return maximum of domain.
Definition int.hpp:62
Gecode::Int::ViewRanges
Range iterator for integer views.
Definition view.hpp:54
Gecode::MetaInfo
Information passed by meta search engines.
Definition core.hpp:1613
Gecode::MetaInfo::RESTART
@ RESTART
Information is provided by a restart-based engine.
Definition core.hpp:1618
Gecode::MetaInfo::restart
unsigned long int restart(void) const
Return number of restarts.
Definition core.hpp:3086
Gecode::MetaInfo::last
const Space * last(void) const
Return last solution found (possibly NULL).
Definition core.hpp:3101
Gecode::MetaInfo::type
Type type(void) const
Return type of information.
Definition core.hpp:3082
Gecode::PropagatorGroup::all
static PropagatorGroup all
Group of all propagators.
Definition core.hpp:789
Gecode::Region::alloc
T * alloc(long unsigned int n)
Allocate block of n objects of type T from region.
Definition region.hpp:386
Gecode::Rnd
Random number generator.
Definition rnd.hpp:42
Gecode::Search::Options
Search engine options
Definition search.hh:746
Gecode::Search::Options::c_d
unsigned int c_d
Create a clone after every c_d commits (commit distance).
Definition search.hh:753
Gecode::Search::Options::a_d
unsigned int a_d
Create a clone during recomputation if distance is greater than a_d (adaptive distance).
Definition search.hh:755
Gecode::Search::Statistics::restart
unsigned long int restart
Number of restarts.
Definition search.hh:156
Gecode::Search::Statistics::depth
unsigned long int depth
Maximum depth of search stack.
Definition search.hh:154
Gecode::Search::Statistics::fail
unsigned long int fail
Number of failed nodes in search tree.
Definition search.hh:150
Gecode::Search::Statistics::node
unsigned long int node
Number of nodes expanded.
Definition search.hh:152
Gecode::SetValBranch
Which values to select for branching first.
Definition set.hh:1447
Gecode::SetVarArgs
Passing set variables.
Definition set.hh:488
Gecode::SetVarArray
Set variable array
Definition set.hh:570
Gecode::SetVarBranch
Which variable to select for branching.
Definition set.hh:1296
Gecode::SetVar
Set variables
Definition set.hh:127
Gecode::SharedArray
Shared array with arbitrary number of elements.
Definition shared-array.hpp:53
Gecode::SharedArray::size
int size(void) const
Return number of elements.
Definition shared-array.hpp:299
Gecode::SharedHandle::Object
The shared object.
Definition shared-object.hpp:53
Gecode::SharedHandle::SharedHandle
SharedHandle(void)
Create shared handle with no object pointing to.
Definition shared-object.hpp:122
Gecode::SharedHandle::object
SharedHandle::Object * object(void) const
Access to the shared object.
Definition shared-object.hpp:102
Gecode::Space
Computation spaces.
Definition core.hpp:1742
Gecode::Space::p
struct Gecode::Space::@055132133326276162005044145100211202071356247106::@275070317317120154232063063134255170030071110047 p
Data only available during propagation or branching.
Gecode::Space::c
struct Gecode::Space::@055132133326276162005044145100211202071356247106::@155123175027073262103111264343315000271204104107 c
Data available only during copying.
Gecode::Space::Region
friend class Region
Definition core.hpp:1755
Gecode::Space::alloc
T * alloc(long unsigned int n)
Allocate block of n objects of type T from space heap.
Definition core.hpp:2837
Gecode::Space::BrancherGroup
friend class BrancherGroup
Definition core.hpp:1748
Gecode::StatusStatistics
Statistics for execution of status
Definition core.hpp:1691
Gecode::StatusStatistics::propagate
unsigned long int propagate
Number of propagator executions.
Definition core.hpp:1694
Gecode::Support::Timer
Timer
Definition timer.hpp:51
Gecode::Support::Timer::stop
double stop(void)
Get time since start of timer.
Definition timer.hpp:76
Gecode::Support::Timer::start
void start(void)
Start timer.
Definition timer.hpp:66
Gecode::TieBreak
Combine variable selection criteria for tie-breaking.
Definition tiebreak.hpp:38
Gecode::TupleSet
Class represeting a set of tuples.
Definition int.hh:2191
Gecode::TupleSet::add
TupleSet & add(const IntArgs &t)
Add tuple t to tuple set.
Definition tuple-set.hpp:142
Gecode::TupleSet::hash
std::size_t hash(void) const
Return hash key.
Definition tuple-set.hpp:227
Gecode::TupleSet::finalize
void finalize(void)
Finalize tuple set.
Definition tuple-set.hpp:155
Gecode::VarArray::assigned
bool assigned(void) const
Test if all variables are assigned.
Definition array.hpp:1026
Gecode::VarArray::size
int size(void) const
Return size of array (number of elements).
Definition array.hpp:926
Gecode::VarImpView::assigned
bool assigned(void) const
Test whether view is assigned.
Definition view.hpp:516
Gecode::Var
Base class for variables.
Definition var.hpp:40
Test::Options::seed
unsigned int seed
The random seed to be used.
Definition test.hh:79
pi
const int * pi[]
Definition photo.cpp:14262
branch.hh
flatzinc.hh
Gecode::heap
Heap heap
The single global heap.
Definition heap.cpp:44
Gecode::Int::OffsetView::offset
int offset(void) const
Integer-precision integer scale view.
Definition view.hpp:642
Gecode::Int::OffsetView::operator()
View & operator()(View &x)
Integer-precision integer scale view.
Definition view.hpp:632
Gecode::Space::fail
void fail(void)
Fail space.
Definition core.hpp:4030
Gecode::SM_GIST
@ SM_GIST
Run script in Gist.
Definition driver.hh:98
Gecode::RM_CONSTANT
@ RM_CONSTANT
Restart with constant sequence.
Definition driver.hh:108
Gecode::RM_LINEAR
@ RM_LINEAR
Restart with linear sequence.
Definition driver.hh:109
Gecode::RM_LUBY
@ RM_LUBY
Restart with Luby sequence.
Definition driver.hh:110
Gecode::RM_NONE
@ RM_NONE
No restarts.
Definition driver.hh:107
Gecode::RM_GEOMETRIC
@ RM_GEOMETRIC
Restart with geometric sequence.
Definition driver.hh:111
Gecode::Gist::bab
int bab(Space *root, const Gist::Options &opt=Gist::Options::def)
Create a new stand-alone Gist for branch-and-bound search of root.
Definition gist.hpp:208
Gecode::Gist::dfs
int dfs(Space *root, const Gist::Options &opt=Gist::Options::def)
Create a new stand-alone Gist for root.
Definition gist.hpp:203
Gecode::assign
void assign(Home home, const FloatVarArgs &x, FloatVarBranch vars, FloatAssign vals, FloatBranchFilter bf=nullptr, FloatVarValPrint vvp=nullptr)
Assign all x with variable selection vars and value selection vals.
Definition branch.cpp:111
Gecode::rel
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVar x1)
Post propagator for .
Definition rel.cpp:68
Gecode::FloatNum
double FloatNum
Floating point number base type.
Definition float.hh:106
Gecode::FRT_GR
@ FRT_GR
Greater ( ).
Definition float.hh:1074
Gecode::FRT_LE
@ FRT_LE
Less ( ).
Definition float.hh:1072
Gecode::IntPropLevel
IntPropLevel
Propagation levels for integer propagators.
Definition int.hh:974
Gecode::IRT_EQ
@ IRT_EQ
Equality ( ).
Definition int.hh:926
Gecode::IRT_LE
@ IRT_LE
Less ( ).
Definition int.hh:929
Gecode::IRT_GR
@ IRT_GR
Greater ( ).
Definition int.hh:931
Gecode::IPL_DOM
@ IPL_DOM
Domain propagation Options: basic versus advanced propagation.
Definition int.hh:979
Gecode::IPL_VAL
@ IPL_VAL
Value propagation.
Definition int.hh:977
Gecode::IPL_DEF
@ IPL_DEF
Simple propagation levels.
Definition int.hh:976
Gecode::IPL_BND
@ IPL_BND
Bounds propagation.
Definition int.hh:978
Gecode::Space::Space
Space(void)
Default constructor.
Definition core.cpp:115
Gecode::Space::clone
Space * clone(CloneStatistics &stat=unused_clone) const
Clone space.
Definition core.hpp:3224
Gecode::SS_FAILED
@ SS_FAILED
Space is failed
Definition core.hpp:1682
Gecode::FlatZinc
Interpreter for the FlatZinc language.
Gecode::FlatZinc::printIntVar
void printIntVar(std::ostream &os, const std::string name, const Int::IntView &x)
Definition flatzinc.cpp:1760
Gecode::FlatZinc::registry
Registry & registry(void)
Return global registry object.
Definition registry.cpp:53
Gecode::FlatZinc::varValPrintF
void varValPrintF(const Space &home, const Brancher &b, unsigned int a, FloatVar, int i, const FloatNumBranch &nl, std::ostream &o)
Definition flatzinc.cpp:348
Gecode::FlatZinc::ann2ivarsel
TieBreak< IntVarBranch > ann2ivarsel(AST::Node *ann, Rnd rnd, double decay)
Definition flatzinc.cpp:400
Gecode::FlatZinc::varValPrint
void varValPrint(const Space &home, const Brancher &b, unsigned int a, Var, int i, const int &n, std::ostream &o)
Definition flatzinc.cpp:340
Gecode::FlatZinc::ann2asnbvalsel
BoolAssign ann2asnbvalsel(AST::Node *ann, Rnd rnd)
Definition flatzinc.cpp:603
Gecode::FlatZinc::ann2bvarsel
TieBreak< BoolVarBranch > ann2bvarsel(AST::Node *ann, Rnd rnd, double decay)
Definition flatzinc.cpp:518
Gecode::FlatZinc::printFloatVar
void printFloatVar(std::ostream &os, const std::string name, const Float::FloatView &f)
Definition flatzinc.cpp:1786
Gecode::FlatZinc::printBoolVar
void printBoolVar(std::ostream &os, const std::string name, const BoolVar &b)
Definition flatzinc.cpp:1779
Gecode::FlatZinc::ann2fvarsel
TieBreak< FloatVarBranch > ann2fvarsel(AST::Node *ann, Rnd rnd, double decay)
Definition flatzinc.cpp:689
Gecode::FlatZinc::ann2bvalsel
BoolValBranch ann2bvalsel(AST::Node *ann, std::string &r0, std::string &r1, Rnd rnd)
Definition flatzinc.cpp:552
Gecode::FlatZinc::vs2is
IntSet vs2is(IntVarSpec *vs)
Definition flatzinc.cpp:356
Gecode::FlatZinc::ann2fvalsel
FloatValBranch ann2fvalsel(AST::Node *ann, std::string r0, std::string r1)
Definition flatzinc.cpp:733
Gecode::FlatZinc::vs2bsl
int vs2bsl(BoolVarSpec *bs)
Definition flatzinc.cpp:376
Gecode::FlatZinc::ann2ivalsel
IntValBranch ann2ivalsel(AST::Node *ann, std::string &r0, std::string &r1, Rnd rnd)
Definition flatzinc.cpp:449
Gecode::FlatZinc::INTBOOL_VAR_AFC_SIZE_MAX
IntBoolVarBranch INTBOOL_VAR_AFC_SIZE_MAX(double d=1.0)
Select variable with largest accumulated failure count divided by domain size.
Definition branch.hpp:138
Gecode::FlatZinc::defrnd
GECODE_FLATZINC_EXPORT Rnd defrnd
Uninitialized default random number generator.
Gecode::FlatZinc::branch
void branch(Home home, const IntVarArgs &x, const BoolVarArgs &y, IntBoolVarBranch vars, IntValBranch vals)
Branch function for integer and Boolean variables.
Definition branch.cpp:120
Gecode::FlatZinc::ann2svarsel
SetVarBranch ann2svarsel(AST::Node *ann, Rnd rnd, double decay)
Definition flatzinc.cpp:621
Gecode::FlatZinc::ann2svalsel
SetValBranch ann2svalsel(AST::Node *ann, std::string r0, std::string r1, Rnd rnd)
Definition flatzinc.cpp:659
Gecode::FlatZinc::vs2bsh
int vs2bsh(BoolVarSpec *bs)
Definition flatzinc.cpp:388
Gecode::FlatZinc::ann2asnivalsel
IntAssign ann2asnivalsel(AST::Node *ann, Rnd rnd)
Definition flatzinc.cpp:500
Gecode::FlatZinc::flattenAnnotations
void flattenAnnotations(AST::Array *ann, std::vector< AST::Node * > &out)
Definition flatzinc.cpp:1022
Gecode::Float::Limits::max
const FloatNum max
Largest allowed float value.
Definition float.hh:844
Gecode::Float::Limits::min
const FloatNum min
Smallest allowed float value.
Definition float.hh:846
Gecode::Gist
The Gecode Interactive Search Tool.
Gecode::Int::Limits::min
const int min
Smallest allowed integer value.
Definition int.hh:118
Gecode::Int::Limits::max
const int max
Largest allowed integer value.
Definition int.hh:116
Gecode::Set::Limits::min
const int min
Smallest allowed integer in integer set.
Definition set.hh:99
Gecode::Set::Limits::max
const int max
Largest allowed integer in integer set.
Definition set.hh:97
Gecode::Set::print
void print(std::basic_ostream< Char, Traits > &s, bool assigned, IL &lb, IU &ub, unsigned int cardMin, unsigned int cardMax)
Print set view.
Definition print.hpp:63
Gecode
Gecode toplevel namespace
Gecode::FLOAT_VAR_RND
FloatVarBranch FLOAT_VAR_RND(Rnd r)
Select random variable (uniform distribution, for tie breaking).
Definition var.hpp:112
Gecode::FLOAT_VAL_SPLIT_MAX
FloatValBranch FLOAT_VAL_SPLIT_MAX(void)
Select values greater than mean of smallest and largest value.
Definition val.hpp:60
Gecode::IntSetArgs
ArgArray< IntSet > IntSetArgs
Passing set arguments.
Definition int.hh:619
Gecode::SET_VAR_ACTION_SIZE_MIN
SetVarBranch SET_VAR_ACTION_SIZE_MIN(double d=1.0, BranchTbl tbl=nullptr)
Select variable with smallest action divided by domain size with decay factor d.
Definition var.hpp:246
Gecode::INT_ASSIGN_RND
IntAssign INT_ASSIGN_RND(Rnd r)
Select random value.
Definition assign.hpp:70
Gecode::SET_VAR_ACTION_SIZE_MAX
SetVarBranch SET_VAR_ACTION_SIZE_MAX(double d=1.0, BranchTbl tbl=nullptr)
Select variable with largest action divided by domain size with decay factor d.
Definition var.hpp:256
Gecode::INT_VAL_SPLIT_MIN
IntValBranch INT_VAL_SPLIT_MIN(void)
Select values not greater than mean of smallest and largest value.
Definition val.hpp:75
Gecode::FLOAT_VAR_AFC_MIN
FloatVarBranch FLOAT_VAR_AFC_MIN(double d=1.0, BranchTbl tbl=nullptr)
Select variable with smallest accumulated failure count with decay factor d.
Definition var.hpp:127
Gecode::BOOL_ASSIGN_MAX
BoolAssign BOOL_ASSIGN_MAX(void)
Select largest value.
Definition assign.hpp:105
Gecode::FLOAT_VAR_SIZE_MAX
FloatVarBranch FLOAT_VAR_SIZE_MAX(BranchTbl tbl=nullptr)
Select variable with largest domain size.
Definition var.hpp:212
Gecode::INT_VAR_AFC_SIZE_MAX
IntVarBranch INT_VAR_AFC_SIZE_MAX(double d=1.0, BranchTbl tbl=nullptr)
Select variable with largest accumulated failure count divided by domain size with decay factor d.
Definition var.hpp:236
Gecode::FLOAT_VAR_MAX_MAX
FloatVarBranch FLOAT_VAR_MAX_MAX(BranchTbl tbl=nullptr)
Select variable with largest max.
Definition var.hpp:202
Gecode::SET_VAR_NONE
SetVarBranch SET_VAR_NONE(void)
Select first unassigned variable.
Definition var.hpp:96
Gecode::INT_VAR_DEGREE_MAX
IntVarBranch INT_VAR_DEGREE_MAX(BranchTbl tbl=nullptr)
Select variable with largest degree.
Definition var.hpp:121
Gecode::INT_VAR_ACTION_MAX
IntVarBranch INT_VAR_ACTION_MAX(double d=1.0, BranchTbl tbl=nullptr)
Select variable with highest action with decay factor d.
Definition var.hpp:156
Gecode::FLOAT_VAR_AFC_SIZE_MIN
FloatVarBranch FLOAT_VAR_AFC_SIZE_MIN(double d=1.0, BranchTbl tbl=nullptr)
Select variable with smalllest accumulated failure count divided by domain size with decay factor d.
Definition var.hpp:227
Gecode::IntSharedArray
SharedArray< int > IntSharedArray
Arrays of integers that can be shared among several element constraints.
Definition int.hh:1477
Gecode::INT_VAL_MED
IntValBranch INT_VAL_MED(void)
Select greatest value not greater than the median.
Definition val.hpp:60
Gecode::INT_VAR_REGRET_MIN_MAX
IntVarBranch INT_VAR_REGRET_MIN_MAX(BranchTbl tbl=nullptr)
Select variable with largest min-regret.
Definition var.hpp:291
Gecode::INT_VAR_ACTION_SIZE_MAX
IntVarBranch INT_VAR_ACTION_SIZE_MAX(double d=1.0, BranchTbl tbl=nullptr)
Select variable with largest action divided by domain size with decay factor d.
Definition var.hpp:256
Gecode::min
void min(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition arithmetic.cpp:67
Gecode::BOOL_VAL_MIN
BoolValBranch BOOL_VAL_MIN(void)
Select smallest value.
Definition val.hpp:130
Gecode::INT_VAR_NONE
IntVarBranch INT_VAR_NONE(void)
Select first unassigned variable.
Definition var.hpp:96
Gecode::dom
void dom(Home home, FloatVar x, FloatVal n)
Propagates .
Definition dom.cpp:40
Gecode::BOOL_VAR_NONE
BoolVarBranch BOOL_VAR_NONE(void)
Select first unassigned variable.
Definition var.hpp:364
Gecode::INT_VAR_AFC_MAX
IntVarBranch INT_VAR_AFC_MAX(double d=1.0, BranchTbl tbl=nullptr)
Select variable with largest accumulated failure count with decay factor d.
Definition var.hpp:136
Gecode::INT_VAR_AFC_MIN
IntVarBranch INT_VAR_AFC_MIN(double d=1.0, BranchTbl tbl=nullptr)
Select variable with smallest accumulated failure count with decay factor d.
Definition var.hpp:126
Gecode::INT_VALUES_MIN
IntValBranch INT_VALUES_MIN(void)
Try all values starting from smallest.
Definition val.hpp:100
Gecode::SET_VAR_SIZE_MIN
SetVarBranch SET_VAR_SIZE_MIN(BranchTbl tbl=nullptr)
Select variable with smallest unknown set.
Definition var.hpp:206
Gecode::SET_VAR_RND
SetVarBranch SET_VAR_RND(Rnd r)
Select random variable (uniform distribution, for tie breaking).
Definition var.hpp:101
Gecode::cmb_hash
void cmb_hash(std::size_t &seed, const T h)
Combine hash value h into seed.
Definition hash.hpp:44
Gecode::SET_VAR_MAX_MAX
SetVarBranch SET_VAR_MAX_MAX(BranchTbl tbl=nullptr)
Select variable with largest maximum unknown element.
Definition var.hpp:201
Gecode::INT_VAL_MAX
IntValBranch INT_VAL_MAX(void)
Select largest value.
Definition val.hpp:65
Gecode::FLOAT_VAR_ACTION_MAX
FloatVarBranch FLOAT_VAR_ACTION_MAX(double d=1.0, BranchTbl tbl=nullptr)
Select variable with highest action with decay factor d.
Definition var.hpp:157
Gecode::BOOL_VAL_MAX
BoolValBranch BOOL_VAL_MAX(void)
Select largest value.
Definition val.hpp:135
Gecode::BOOL_VAR_RND
BoolVarBranch BOOL_VAR_RND(Rnd r)
Select random variable (uniform distribution, for tie breaking).
Definition var.hpp:369
Gecode::BOOL_VAR_ACTION_MIN
BoolVarBranch BOOL_VAR_ACTION_MIN(double d=1.0, BranchTbl tbl=nullptr)
Select variable with lowest action with decay factor d.
Definition var.hpp:414
Gecode::SET_VAR_AFC_MAX
SetVarBranch SET_VAR_AFC_MAX(double d=1.0, BranchTbl tbl=nullptr)
Select variable with largest accumulated failure count with decay factor d.
Definition var.hpp:136
Gecode::FLOAT_VAR_MIN_MIN
FloatVarBranch FLOAT_VAR_MIN_MIN(BranchTbl tbl=nullptr)
Select variable with smallest min.
Definition var.hpp:187
Gecode::SET_VAR_MIN_MIN
SetVarBranch SET_VAR_MIN_MIN(BranchTbl tbl=nullptr)
Select variable with smallest minimum unknown element.
Definition var.hpp:186
Gecode::FLOAT_VAR_ACTION_MIN
FloatVarBranch FLOAT_VAR_ACTION_MIN(double d=1.0, BranchTbl tbl=nullptr)
Select variable with lowest action with decay factor d.
Definition var.hpp:147
Gecode::SET_VAL_MAX_INC
SetValBranch SET_VAL_MAX_INC(void)
Include largest element.
Definition val.hpp:75
Gecode::BOOL_ASSIGN_RND
BoolAssign BOOL_ASSIGN_RND(Rnd r)
Select random value.
Definition assign.hpp:110
Gecode::INT_VAL_SPLIT_MAX
IntValBranch INT_VAL_SPLIT_MAX(void)
Select values greater than mean of smallest and largest value.
Definition val.hpp:80
Gecode::INT_VAL_MIN
IntValBranch INT_VAL_MIN(void)
Select smallest value.
Definition val.hpp:55
Gecode::INT_ASSIGN_MED
IntAssign INT_ASSIGN_MED(void)
Select greatest value not greater than the median.
Definition assign.hpp:60
Gecode::SET_VAR_AFC_MIN
SetVarBranch SET_VAR_AFC_MIN(double d=1.0, BranchTbl tbl=nullptr)
Select variable with smallest accumulated failure count with decay factor d.
Definition var.hpp:126
Gecode::BOOL_VAR_AFC_MIN
BoolVarBranch BOOL_VAR_AFC_MIN(double d=1.0, BranchTbl tbl=nullptr)
Select variable with smallest accumulated failure count with decay factor d.
Definition var.hpp:394
Gecode::dfs
T * dfs(T *s, const Search::Options &o=Search::Options::def)
Invoke depth-first search engine for subclass T of space s with options o.
Definition dfs.hpp:73
Gecode::BOOL_VAR_AFC_MAX
BoolVarBranch BOOL_VAR_AFC_MAX(double d=1.0, BranchTbl tbl=nullptr)
Select variable with largest accumulated failure count with decay factor d.
Definition var.hpp:404
Gecode::FLOAT_VAR_NONE
FloatVarBranch FLOAT_VAR_NONE(void)
Select first unassigned variable.
Definition var.hpp:97
Gecode::INT_VAR_MAX_MAX
IntVarBranch INT_VAR_MAX_MAX(BranchTbl tbl=nullptr)
Select variable with largest max.
Definition var.hpp:201
Gecode::INT_ASSIGN_MIN
IntAssign INT_ASSIGN_MIN(void)
Select smallest value.
Definition assign.hpp:55
Gecode::INT_VAR_ACTION_MIN
IntVarBranch INT_VAR_ACTION_MIN(double d=1.0, BranchTbl tbl=nullptr)
Select variable with lowest action with decay factor d.
Definition var.hpp:146
Gecode::INT_VAR_RND
IntVarBranch INT_VAR_RND(Rnd r)
Select random variable (uniform distribution, for tie breaking).
Definition var.hpp:101
Gecode::INT_VAR_AFC_SIZE_MIN
IntVarBranch INT_VAR_AFC_SIZE_MIN(double d=1.0, BranchTbl tbl=nullptr)
Select variable with smallest accumulated failure count divided by domain size with decay factor d.
Definition var.hpp:226
Gecode::SET_VAL_MIN_INC
SetValBranch SET_VAL_MIN_INC(void)
Include smallest element.
Definition val.hpp:55
Gecode::ExecStatus
ExecStatus
Definition core.hpp:472
Gecode::ES_OK
@ ES_OK
Execution is okay.
Definition core.hpp:476
Gecode::ES_FAILED
@ ES_FAILED
Execution has resulted in failure.
Definition core.hpp:474
Gecode::max
void max(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition arithmetic.cpp:49
Gecode::FLOAT_VAR_DEGREE_MAX
FloatVarBranch FLOAT_VAR_DEGREE_MAX(BranchTbl tbl=nullptr)
Select variable with largest degree.
Definition var.hpp:122
Gecode::SET_VAR_AFC_SIZE_MIN
SetVarBranch SET_VAR_AFC_SIZE_MIN(double d=1.0, BranchTbl tbl=nullptr)
Select variable with smallest accumulated failure count divided by domain size with decay factor d.
Definition var.hpp:226
Gecode::SET_VAL_MAX_EXC
SetValBranch SET_VAL_MAX_EXC(void)
Exclude largest element.
Definition val.hpp:80
Gecode::FLOAT_VAR_ACTION_SIZE_MAX
FloatVarBranch FLOAT_VAR_ACTION_SIZE_MAX(double d=1.0, BranchTbl tbl=nullptr)
Select variable with largest action divided by domain size with decay factor d.
Definition var.hpp:257
Gecode::BOOL_VAL_RND
BoolValBranch BOOL_VAL_RND(Rnd r)
Select random value.
Definition val.hpp:140
Gecode::SET_VAR_AFC_SIZE_MAX
SetVarBranch SET_VAR_AFC_SIZE_MAX(double d=1.0, BranchTbl tbl=nullptr)
Select variable with largest accumulated failure count divided by domain size with decay factor d.
Definition var.hpp:236
Gecode::SET_VAR_ACTION_MIN
SetVarBranch SET_VAR_ACTION_MIN(double d=1.0, BranchTbl tbl=nullptr)
Select variable with lowest action with decay factor d.
Definition var.hpp:146
Gecode::INT_VAR_SIZE_MIN
IntVarBranch INT_VAR_SIZE_MIN(BranchTbl tbl=nullptr)
Select variable with smallest domain size.
Definition var.hpp:206
Gecode::BOOL_VAR_DEGREE_MAX
BoolVarBranch BOOL_VAR_DEGREE_MAX(BranchTbl tbl=nullptr)
Select variable with largest degree.
Definition var.hpp:389
Gecode::FLOAT_VAR_AFC_SIZE_MAX
FloatVarBranch FLOAT_VAR_AFC_SIZE_MAX(double d=1.0, BranchTbl tbl=nullptr)
Select variable with largest accumulated failure count divided by domain size with decay factor d.
Definition var.hpp:237
Gecode::INT_VAR_ACTION_SIZE_MIN
IntVarBranch INT_VAR_ACTION_SIZE_MIN(double d=1.0, BranchTbl tbl=nullptr)
Select variable with smallest action divided by domain size with decay factor d.
Definition var.hpp:246
Gecode::BOOL_VAR_ACTION_MAX
BoolVarBranch BOOL_VAR_ACTION_MAX(double d=1.0, BranchTbl tbl=nullptr)
Select variable with highest action with decay factor d.
Definition var.hpp:424
Gecode::BOOL_ASSIGN_MIN
BoolAssign BOOL_ASSIGN_MIN(void)
Select smallest value.
Definition assign.hpp:100
Gecode::FLOAT_VAL_SPLIT_MIN
FloatValBranch FLOAT_VAL_SPLIT_MIN(void)
Select values not greater than mean of smallest and largest value.
Definition val.hpp:55
Gecode::INT_ASSIGN_MAX
IntAssign INT_ASSIGN_MAX(void)
Select largest value.
Definition assign.hpp:65
Gecode::FLOAT_VAR_SIZE_MIN
FloatVarBranch FLOAT_VAR_SIZE_MIN(BranchTbl tbl=nullptr)
Select variable with smallest domain size.
Definition var.hpp:207
Gecode::INT_VAR_MIN_MIN
IntVarBranch INT_VAR_MIN_MIN(BranchTbl tbl=nullptr)
Select variable with smallest min.
Definition var.hpp:186
Gecode::FLOAT_VAR_AFC_MAX
FloatVarBranch FLOAT_VAR_AFC_MAX(double d=1.0, BranchTbl tbl=nullptr)
Select variable with largest accumulated failure count with decay factor d.
Definition var.hpp:137
Gecode::SET_VAL_MIN_EXC
SetValBranch SET_VAL_MIN_EXC(void)
Exclude smallest element.
Definition val.hpp:60
Gecode::INT_VAR_SIZE_MAX
IntVarBranch INT_VAR_SIZE_MAX(BranchTbl tbl=nullptr)
Select variable with largest domain size.
Definition var.hpp:211
Gecode::SET_VAR_SIZE_MAX
SetVarBranch SET_VAR_SIZE_MAX(BranchTbl tbl=nullptr)
Select variable with largest unknown set.
Definition var.hpp:211
Gecode::INT_VAL_RND
IntValBranch INT_VAL_RND(Rnd r)
Select random value.
Definition val.hpp:70
Gecode::SET_VAR_ACTION_MAX
SetVarBranch SET_VAR_ACTION_MAX(double d=1.0, BranchTbl tbl=nullptr)
Select variable with highest action with decay factor d.
Definition var.hpp:156
Gecode::FLOAT_VAR_ACTION_SIZE_MIN
FloatVarBranch FLOAT_VAR_ACTION_SIZE_MIN(double d=1.0, BranchTbl tbl=nullptr)
Select variable with smallest action divided by domain size with decay factor d.
Definition var.hpp:247
Test::Float::Arithmetic::step
const Gecode::FloatNum step
Definition arithmetic.cpp:785
Test::Int::Basic::i
Gecode::IntArgs i({1, 2, 3, 4})
Test::Int::Distinct::v
const int v[7]
Definition distinct.cpp:259
Test::opt
Options opt
The options.
Definition test.cpp:97
std
Definition flatzinc.cpp:52
plugin.hh
registry.hh
search.hh
Gecode::FlatZinc::Option::some
const Val & some(void) const
Definition option.hh:47
std::hash< Gecode::DFA >::operator()
size_t operator()(const Gecode::DFA &d) const
Return hash key for d.
Definition flatzinc.cpp:78
std::hash< Gecode::SharedArray< int > >::operator()
size_t operator()(const Gecode::SharedArray< int > &x) const
Return hash key for x.
Definition flatzinc.cpp:67
std::hash< Gecode::TupleSet >::operator()
size_t operator()(const Gecode::TupleSet &x) const
Return hash key for x.
Definition flatzinc.cpp:58
GECODE_HAS_FLOAT_VARS
#define GECODE_HAS_FLOAT_VARS
Definition config.hpp:35
GECODE_HAS_SET_VARS
#define GECODE_HAS_SET_VARS
Definition config.hpp:56
forceinline
#define forceinline
Definition config.hpp:187