varspec.hh
Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ 00002 /* 00003 * Main authors: 00004 * Guido Tack <tack@gecode.org> 00005 * 00006 * Copyright: 00007 * Guido Tack, 2007 00008 * 00009 * Last modified: 00010 * $Date: 2010-04-08 11:25:15 +0200 (Thu, 08 Apr 2010) $ by $Author: tack $ 00011 * $Revision: 10682 $ 00012 * 00013 * This file is part of Gecode, the generic constraint 00014 * development environment: 00015 * http://www.gecode.org 00016 * 00017 * Permission is hereby granted, free of charge, to any person obtaining 00018 * a copy of this software and associated documentation files (the 00019 * "Software"), to deal in the Software without restriction, including 00020 * without limitation the rights to use, copy, modify, merge, publish, 00021 * distribute, sublicense, and/or sell copies of the Software, and to 00022 * permit persons to whom the Software is furnished to do so, subject to 00023 * the following conditions: 00024 * 00025 * The above copyright notice and this permission notice shall be 00026 * included in all copies or substantial portions of the Software. 00027 * 00028 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00029 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00030 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00031 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 00032 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 00033 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 00034 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00035 * 00036 */ 00037 00038 #ifndef __GECODE_FLATZINC_VARSPEC__HH__ 00039 #define __GECODE_FLATZINC_VARSPEC__HH__ 00040 00041 #include <gecode/flatzinc/option.hh> 00042 #include <gecode/flatzinc/ast.hh> 00043 #include <vector> 00044 #include <iostream> 00045 00046 namespace Gecode { namespace FlatZinc { 00047 00049 class Alias { 00050 public: 00051 const int v; 00052 Alias(int v0) : v(v0) {} 00053 }; 00054 00056 class VarSpec { 00057 public: 00059 bool introduced; 00061 virtual ~VarSpec(void) {} 00063 int i; 00065 bool alias; 00067 bool assigned; 00069 VarSpec(bool introduced0) : introduced(introduced0) {} 00070 }; 00071 00073 class IntVarSpec : public VarSpec { 00074 public: 00075 Option<AST::SetLit* > domain; 00076 IntVarSpec(const Option<AST::SetLit* >& d, bool introduced) 00077 : VarSpec(introduced) { 00078 alias = false; 00079 assigned = false; 00080 domain = d; 00081 } 00082 IntVarSpec(int i0, bool introduced) : VarSpec(introduced) { 00083 alias = false; assigned = true; i = i0; 00084 } 00085 IntVarSpec(const Alias& eq, bool introduced) : VarSpec(introduced) { 00086 alias = true; i = eq.v; 00087 } 00088 ~IntVarSpec(void) { 00089 if (!alias && !assigned && domain()) 00090 delete domain.some(); 00091 } 00092 }; 00093 00095 class BoolVarSpec : public VarSpec { 00096 public: 00097 Option<AST::SetLit* > domain; 00098 BoolVarSpec(Option<AST::SetLit* >& d, bool introduced) 00099 : VarSpec(introduced) { 00100 alias = false; assigned = false; domain = d; 00101 } 00102 BoolVarSpec(bool b, bool introduced) : VarSpec(introduced) { 00103 alias = false; assigned = true; i = b; 00104 } 00105 BoolVarSpec(const Alias& eq, bool introduced) : VarSpec(introduced) { 00106 alias = true; i = eq.v; 00107 } 00108 ~BoolVarSpec(void) { 00109 if (!alias && !assigned && domain()) 00110 delete domain.some(); 00111 } 00112 }; 00113 00115 class FloatVarSpec : public VarSpec { 00116 public: 00117 Option<std::vector<double>* > domain; 00118 FloatVarSpec(Option<std::vector<double>* >& d, bool introduced) 00119 : VarSpec(introduced) { 00120 alias = false; assigned = false; domain = d; 00121 } 00122 FloatVarSpec(bool b, bool introduced) : VarSpec(introduced) { 00123 alias = false; assigned = true; i = b; 00124 } 00125 FloatVarSpec(const Alias& eq, bool introduced) : VarSpec(introduced) { 00126 alias = true; i = eq.v; 00127 } 00128 ~FloatVarSpec(void) { 00129 if (!alias && !assigned && domain()) 00130 delete domain.some(); 00131 } 00132 }; 00133 00135 class SetVarSpec : public VarSpec { 00136 public: 00137 Option<AST::SetLit*> upperBound; 00138 SetVarSpec(bool introduced) : VarSpec(introduced) { 00139 alias = false; assigned = false; 00140 upperBound = Option<AST::SetLit* >::none(); 00141 } 00142 SetVarSpec(const Option<AST::SetLit* >& v, bool introduced) 00143 : VarSpec(introduced) { 00144 alias = false; assigned = false; upperBound = v; 00145 } 00146 SetVarSpec(AST::SetLit* v, bool introduced) : VarSpec(introduced) { 00147 alias = false; assigned = true; 00148 upperBound = Option<AST::SetLit*>::some(v); 00149 } 00150 SetVarSpec(const Alias& eq, bool introduced) : VarSpec(introduced) { 00151 alias = true; i = eq.v; 00152 } 00153 ~SetVarSpec(void) { 00154 if (!alias && upperBound()) 00155 delete upperBound.some(); 00156 } 00157 }; 00158 00159 }} 00160 00161 #endif 00162 00163 // STATISTICS: flatzinc-any