38 #ifndef __GECODE_FLATZINC_AST_HH__ 39 #define __GECODE_FLATZINC_AST_HH__ 51 namespace Gecode {
namespace FlatZinc {
namespace AST {
65 std::string
what(
void)
const {
return _what; }
80 bool hasAtom(
const std::string&
id);
84 bool isFloat(
double&
i);
86 bool isCall(
const std::string&
id);
90 bool hasCall(
const std::string&
id);
92 Call* getCall(
const std::string&
id);
94 Array* getArray(
void);
98 std::string getVarName(
void);
102 int getBoolVar(
void);
104 int getFloatVar(
void);
113 double getFloat(
void);
118 std::string getString(
void);
123 bool isBoolVar(
void);
127 bool isFloatVar(
void);
144 virtual void print(std::ostream&) = 0;
152 virtual void print(std::ostream& os) {
153 os <<
"b(" << (
b ?
"true" :
"false") <<
")";
161 virtual void print(std::ostream& os) {
170 virtual void print(std::ostream& os) {
182 SetLit(
const std::vector<int>& s0) : interval(false), s(s0) {}
184 return ( (interval &&
min>
max) || (!interval && s.size() == 0));
186 virtual void print(std::ostream& os) {
197 Var(
int i0,
const std::string& n0) :
i(i0),
n(n0) {}
204 virtual void print(std::ostream& os) {
211 IntVar(
int i0,
const std::string& n0=
"") :
Var(i0,n0) {}
212 virtual void print(std::ostream& os) {
220 virtual void print(std::ostream& os) {
227 SetVar(
int i0,
const std::string& n0=
"") :
Var(i0,n0) {}
228 virtual void print(std::ostream& os) {
236 std::vector<Node*>
a;
242 virtual void print(std::ostream& os) {
244 for (
unsigned int i=0;
i<
a.size();
i++) {
252 for (
int i=
a.size();
i--;)
263 : id(id0), args(args0) {}
265 virtual void print(std::ostream& os) {
266 os <<
id <<
"("; args->
print(os); os <<
")";
270 if (
a->a.size() !=
n)
282 :
a(a0), idx(idx0) {}
284 virtual void print(std::ostream& os) {
296 Atom(
const std::string& id0) : id(id0) {}
297 virtual void print(std::ostream& os) {
307 virtual void print(std::ostream& os) {
308 os <<
"s(\"" << s <<
"\")";
317 Array*
a = dynamic_cast<Array*>(
this);
320 a->a.push_back(newNode);
325 if (
Array*
a = dynamic_cast<Array*>(
this)) {
326 for (
int i=
a->a.size();
i--;)
327 if (
Atom* at = dynamic_cast<Atom*>(
a->a[
i]))
330 }
else if (
Atom*
a = dynamic_cast<Atom*>(
this)) {
338 if (
Call*
a = dynamic_cast<Call*>(
this)) {
347 if (
Call*
a = dynamic_cast<Call*>(
this))
354 if (
Array*
a = dynamic_cast<Array*>(
this)) {
355 for (
int i=
a->a.size();
i--;)
356 if (
Call* at = dynamic_cast<Call*>(
a->a[
i]))
360 }
else if (
Call*
a = dynamic_cast<Call*>(
this)) {
368 if (
IntLit* il = dynamic_cast<IntLit*>(
this)) {
377 if (
FloatLit* fl = dynamic_cast<FloatLit*>(
this)) {
386 if (
Array*
a = dynamic_cast<Array*>(
this)) {
387 for (
int i=
a->a.size();
i--;)
388 if (
Call* at = dynamic_cast<Call*>(
a->a[
i]))
391 }
else if (
Call*
a = dynamic_cast<Call*>(
this)) {
400 if (
Array*
a = dynamic_cast<Array*>(
this))
407 if (
Atom*
a = dynamic_cast<Atom*>(
this))
414 if (
Var*
a = dynamic_cast<Var*>(
this))
420 if (
IntVar*
a = dynamic_cast<IntVar*>(
this))
422 throw TypeError(
"integer variable expected");
426 if (
BoolVar*
a = dynamic_cast<BoolVar*>(
this))
428 throw TypeError(
"bool variable expected");
432 if (
FloatVar*
a = dynamic_cast<FloatVar*>(
this))
434 throw TypeError(
"integer variable expected");
438 if (
SetVar*
a = dynamic_cast<SetVar*>(
this))
440 throw TypeError(
"set variable expected");
444 if (
IntLit*
a = dynamic_cast<IntLit*>(
this))
446 throw TypeError(
"integer literal expected");
450 if (
BoolLit*
a = dynamic_cast<BoolLit*>(
this))
452 throw TypeError(
"bool literal expected");
456 if (
FloatLit*
a = dynamic_cast<FloatLit*>(
this))
458 throw TypeError(
"float literal expected");
462 if (
SetLit*
a = dynamic_cast<SetLit*>(
this))
468 if (
String*
a = dynamic_cast<String*>(
this))
470 throw TypeError(
"string literal expected");
474 return (dynamic_cast<IntVar*>(
this) != NULL);
478 return (dynamic_cast<BoolVar*>(
this) != NULL);
482 return (dynamic_cast<SetVar*>(
this) != NULL);
486 return (dynamic_cast<FloatVar*>(
this) != NULL);
490 return (dynamic_cast<IntLit*>(
this) != NULL);
494 return (dynamic_cast<BoolLit*>(
this) != NULL);
498 return (dynamic_cast<FloatLit*>(
this) != NULL);
502 return (dynamic_cast<SetLit*>(
this) != NULL);
506 return (dynamic_cast<String*>(
this) != NULL);
510 return (dynamic_cast<Array*>(
this) != NULL);
514 return (dynamic_cast<Atom*>(
this) != NULL);
519 if (
Array*
a = dynamic_cast<Array*>(
n)) {
520 if (
a->a.size() == 1) {
SetVar(int i0, const std::string &n0="")
Var(int i0, const std::string &n0)
Constructor.
virtual void print(std::ostream &os)
Output string representation.
virtual void print(std::ostream &os)
Output string representation.
bool isBool(void)
Test if node is a Boolean node.
bool getBool(void)
Cast this node to a Boolean node.
Array(const std::vector< Node * > &a0)
SetLit(const std::vector< int > &s0)
virtual void print(std::ostream &os)
Output string representation.
SetLit * getSet(void)
Cast this node to a set literal node.
std::string getVarName(void)
Return name of variable represented by this node.
Call * getCall(void)
Return function call.
void max(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
int getFloatVar(void)
Cast this node to a Float variable node.
virtual void print(std::ostream &os)
Output string representation.
bool isAtom(void)
Test if node is an atom node.
struct Gecode::@511::NNF::@54::@55 b
For binary nodes (and, or, eqv)
bool isInt(void)
Test if node is an integer node.
Node * extractSingleton(Node *n)
SetLit(int min0, int max0)
Atom(const std::string &id0)
Variable node base class.
bool isSetVar(void)
Test if node is a set variable node.
bool isBoolVar(void)
Test if node is a Boolean variable node.
Node representing an array access
Atom * getAtom(void)
Cast this node to an Atom node.
virtual void print(std::ostream &os)
Output string representation.
Array * getArray(void)
Cast this node to an array node.
int getSetVar(void)
Cast this node to a set variable node.
double getFloat(void)
Cast this node to a Float node.
ArrayAccess(Node *a0, Node *idx0)
Gecode::IntArgs i(4, 1, 2, 3, 4)
int n
Number of negative literals for node type.
virtual ~Node(void)
Destructor.
String(const std::string &s0)
Node representing an atom
int getIntVar(void)
Cast this node to an integer variable node.
int getBoolVar(void)
Cast this node to a Boolean variable node.
virtual void print(std::ostream &os)
Output string representation.
bool isSet(void)
Test if node is a set literal node.
std::string what(void) const
virtual void print(std::ostream &os)
Output string representation.
virtual void print(std::ostream &os)
Output string representation.
Array * getArgs(unsigned int n)
virtual void print(std::ostream &os)
Output string representation.
bool isIntVar(void)
Test if node is an integer variable node.
struct Gecode::@511::NNF::@54::@56 a
For atomic nodes.
bool isString(void)
Test if node is a string node.
bool hasCall(const std::string &id)
Test if node is function call or array containing function call id.
void min(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
int getInt(void)
Cast this node to an integer node.
void print(std::basic_ostream< Char, Traits > &s, bool assigned, IL &lb, IU &ub, unsigned int cardMin, unsigned int cardMax)
Print set view.
virtual void print(std::ostream &)=0
Output string representation.
Exception signaling type error
bool hasAtom(const std::string &id)
Test if node has atom with id.
virtual void print(std::ostream &os)
Output string representation.
bool isFloatVar(void)
Test if node is a float variable node.
Call(const std::string &id0, Node *args0)
bool isArray(void)
Test if node is an array node.
IntVar(int i0, const std::string &n0="")
Gecode toplevel namespace
bool isFloat(void)
Test if node is a float node.
FloatVar(int i0, const std::string &n0="")
Node representing a function call
#define GECODE_VTABLE_EXPORT
A node in a FlatZinc abstract syntax tree.
TypeError(std::string what)
virtual void print(std::ostream &os)
Output string representation.
bool isCall(const std::string &id)
Test if node is function call with id.
void append(Node *n)
Append n to an array node.
BoolVar(int i0, const std::string &n0="")
Constructor.
std::string getString(void)
Cast this node to a string node.
virtual void print(std::ostream &os)
Output string representation.
virtual void print(std::ostream &os)
Output string representation.