Generated on Fri Oct 19 11:24:51 2018 for Gecode by doxygen 1.6.3

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  *  This file is part of Gecode, the generic constraint
00010  *  development environment:
00011  *     http://www.gecode.org
00012  *
00013  *  Permission is hereby granted, free of charge, to any person obtaining
00014  *  a copy of this software and associated documentation files (the
00015  *  "Software"), to deal in the Software without restriction, including
00016  *  without limitation the rights to use, copy, modify, merge, publish,
00017  *  distribute, sublicense, and/or sell copies of the Software, and to
00018  *  permit persons to whom the Software is furnished to do so, subject to
00019  *  the following conditions:
00020  *
00021  *  The above copyright notice and this permission notice shall be
00022  *  included in all copies or substantial portions of the Software.
00023  *
00024  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00025  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00026  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00027  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00028  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00029  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00030  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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 // STATISTICS: flatzinc-any