Generated on Mon Aug 27 2012 17:15:35 for Gecode by doxygen 1.8.1.2
varspec.hh
Go to the documentation of this file.
1 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2 /*
3  * Main authors:
4  * Guido Tack <tack@gecode.org>
5  *
6  * Copyright:
7  * Guido Tack, 2007
8  *
9  * Last modified:
10  * $Date: 2010-04-08 19:25:15 +1000 (Thu, 08 Apr 2010) $ by $Author: tack $
11  * $Revision: 10682 $
12  *
13  * This file is part of Gecode, the generic constraint
14  * development environment:
15  * http://www.gecode.org
16  *
17  * Permission is hereby granted, free of charge, to any person obtaining
18  * a copy of this software and associated documentation files (the
19  * "Software"), to deal in the Software without restriction, including
20  * without limitation the rights to use, copy, modify, merge, publish,
21  * distribute, sublicense, and/or sell copies of the Software, and to
22  * permit persons to whom the Software is furnished to do so, subject to
23  * the following conditions:
24  *
25  * The above copyright notice and this permission notice shall be
26  * included in all copies or substantial portions of the Software.
27  *
28  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35  *
36  */
37 
38 #ifndef __GECODE_FLATZINC_VARSPEC__HH__
39 #define __GECODE_FLATZINC_VARSPEC__HH__
40 
42 #include <gecode/flatzinc/ast.hh>
43 #include <vector>
44 #include <iostream>
45 
46 namespace Gecode { namespace FlatZinc {
47 
49  class Alias {
50  public:
51  const int v;
52  Alias(int v0) : v(v0) {}
53  };
54 
56  class VarSpec {
57  public:
59  bool introduced;
61  virtual ~VarSpec(void) {}
63  int i;
65  bool alias;
67  bool assigned;
69  VarSpec(bool introduced0) : introduced(introduced0) {}
70  };
71 
73  class IntVarSpec : public VarSpec {
74  public:
77  : VarSpec(introduced) {
78  alias = false;
79  assigned = false;
80  domain = d;
81  }
82  IntVarSpec(int i0, bool introduced) : VarSpec(introduced) {
83  alias = false; assigned = true; i = i0;
84  }
85  IntVarSpec(const Alias& eq, bool introduced) : VarSpec(introduced) {
86  alias = true; i = eq.v;
87  }
88  ~IntVarSpec(void) {
89  if (!alias && !assigned && domain())
90  delete domain.some();
91  }
92  };
93 
95  class BoolVarSpec : public VarSpec {
96  public:
99  : VarSpec(introduced) {
100  alias = false; assigned = false; domain = d;
101  }
102  BoolVarSpec(bool b, bool introduced) : VarSpec(introduced) {
103  alias = false; assigned = true; i = b;
104  }
105  BoolVarSpec(const Alias& eq, bool introduced) : VarSpec(introduced) {
106  alias = true; i = eq.v;
107  }
108  ~BoolVarSpec(void) {
109  if (!alias && !assigned && domain())
110  delete domain.some();
111  }
112  };
113 
115  class FloatVarSpec : public VarSpec {
116  public:
118  FloatVarSpec(Option<std::vector<double>* >& d, bool introduced)
119  : VarSpec(introduced) {
120  alias = false; assigned = false; domain = d;
121  }
122  FloatVarSpec(bool b, bool introduced) : VarSpec(introduced) {
123  alias = false; assigned = true; i = b;
124  }
125  FloatVarSpec(const Alias& eq, bool introduced) : VarSpec(introduced) {
126  alias = true; i = eq.v;
127  }
129  if (!alias && !assigned && domain())
130  delete domain.some();
131  }
132  };
133 
135  class SetVarSpec : public VarSpec {
136  public:
138  SetVarSpec(bool introduced) : VarSpec(introduced) {
139  alias = false; assigned = false;
141  }
143  : VarSpec(introduced) {
144  alias = false; assigned = false; upperBound = v;
145  }
146  SetVarSpec(AST::SetLit* v, bool introduced) : VarSpec(introduced) {
147  alias = false; assigned = true;
149  }
150  SetVarSpec(const Alias& eq, bool introduced) : VarSpec(introduced) {
151  alias = true; i = eq.v;
152  }
153  ~SetVarSpec(void) {
154  if (!alias && upperBound())
155  delete upperBound.some();
156  }
157  };
158 
159 }}
160 
161 #endif
162 
163 // STATISTICS: flatzinc-any