00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #ifndef __GECODE_FLATZINC_VARSPEC__HH__
00035 #define __GECODE_FLATZINC_VARSPEC__HH__
00036
00037 #include <gecode/flatzinc/option.hh>
00038 #include <gecode/flatzinc/ast.hh>
00039 #include <vector>
00040 #include <iostream>
00041
00042 namespace Gecode { namespace FlatZinc {
00043
00045 class Alias {
00046 public:
00047 const int v;
00048 Alias(int v0) : v(v0) {}
00049 };
00050
00052 class VarSpec {
00053 public:
00055 virtual ~VarSpec(void) {}
00057 int i;
00059 bool alias;
00061 bool assigned;
00063 bool introduced;
00065 bool funcDep;
00067 VarSpec(bool introduced0, bool funcDep0)
00068 : introduced(introduced0), funcDep(funcDep0) {}
00069 };
00070
00072 class IntVarSpec : public VarSpec {
00073 public:
00074 Option<AST::SetLit* > domain;
00075 IntVarSpec(const Option<AST::SetLit* >& d,
00076 bool introduced, bool funcDep)
00077 : VarSpec(introduced,funcDep) {
00078 alias = false;
00079 assigned = false;
00080 domain = d;
00081 }
00082 IntVarSpec(int i0, bool introduced, bool funcDep)
00083 : VarSpec(introduced,funcDep) {
00084 alias = false; assigned = true; i = i0; domain = Option<AST::SetLit* >::none();
00085 }
00086 IntVarSpec(const Alias& eq, bool introduced, bool funcDep)
00087 : VarSpec(introduced,funcDep) {
00088 alias = true; i = eq.v;
00089 }
00090 ~IntVarSpec(void) {
00091 if (!alias && !assigned && domain())
00092 delete domain.some();
00093 }
00094 };
00095
00097 class BoolVarSpec : public VarSpec {
00098 public:
00099 Option<AST::SetLit* > domain;
00100 BoolVarSpec(Option<AST::SetLit* >& d, bool introduced, bool funcDep)
00101 : VarSpec(introduced,funcDep) {
00102 alias = false; assigned = false; domain = d;
00103 }
00104 BoolVarSpec(bool b, bool introduced, bool funcDep)
00105 : VarSpec(introduced,funcDep) {
00106 alias = false; assigned = true; i = b; domain = Option<AST::SetLit* >::none();
00107 }
00108 BoolVarSpec(const Alias& eq, bool introduced, bool funcDep)
00109 : VarSpec(introduced,funcDep) {
00110 alias = true; i = eq.v;
00111 }
00112 ~BoolVarSpec(void) {
00113 if (!alias && !assigned && domain())
00114 delete domain.some();
00115 }
00116 };
00117
00119 class FloatVarSpec : public VarSpec {
00120 public:
00121 Option<std::pair<double,double> > domain;
00122 FloatVarSpec(Option<std::pair<double,double> >& d,
00123 bool introduced, bool funcDep)
00124 : VarSpec(introduced,funcDep), domain(d) {
00125 alias = false; assigned = false;
00126 }
00127 FloatVarSpec(double d, bool introduced, bool funcDep)
00128 : VarSpec(introduced,funcDep) {
00129 alias = false; assigned = true;
00130 domain = Option<std::pair<double,double> >::some(std::pair<double,double>(d,d));
00131 }
00132 FloatVarSpec(const Alias& eq, bool introduced, bool funcDep)
00133 : VarSpec(introduced,funcDep) {
00134 alias = true; i = eq.v;
00135 }
00136 };
00137
00139 class SetVarSpec : public VarSpec {
00140 public:
00141 Option<AST::SetLit*> upperBound;
00142 SetVarSpec(bool introduced, bool funcDep) : VarSpec(introduced,funcDep) {
00143 alias = false; assigned = false;
00144 upperBound = Option<AST::SetLit* >::none();
00145 }
00146 SetVarSpec(const Option<AST::SetLit* >& v, bool introduced, bool funcDep)
00147 : VarSpec(introduced,funcDep) {
00148 alias = false; assigned = false; upperBound = v;
00149 }
00150 SetVarSpec(AST::SetLit* v, bool introduced, bool funcDep)
00151 : VarSpec(introduced,funcDep) {
00152 alias = false; assigned = true;
00153 upperBound = Option<AST::SetLit*>::some(v);
00154 }
00155 SetVarSpec(const Alias& eq, bool introduced, bool funcDep)
00156 : VarSpec(introduced,funcDep) {
00157 alias = true; i = eq.v;
00158 }
00159 ~SetVarSpec(void) {
00160 if (!alias && upperBound())
00161 delete upperBound.some();
00162 }
00163 };
00164
00165 }}
00166
00167 #endif
00168
00169