Generated on Sat Feb 7 2015 02:01:14 for Gecode by doxygen 1.8.9.1
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: 2012-03-30 05:58:02 +0200 (Fri, 30 Mar 2012) $ by $Author: tack $
11  * $Revision: 12665 $
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  virtual ~VarSpec(void) {}
61  int i;
63  bool alias;
65  bool assigned;
67  bool introduced;
69  bool funcDep;
71  VarSpec(bool introduced0, bool funcDep0)
72  : introduced(introduced0), funcDep(funcDep0) {}
73  };
74 
76  class IntVarSpec : public VarSpec {
77  public:
80  bool introduced, bool funcDep)
81  : VarSpec(introduced,funcDep) {
82  alias = false;
83  assigned = false;
84  domain = d;
85  }
86  IntVarSpec(int i0, bool introduced, bool funcDep)
87  : VarSpec(introduced,funcDep) {
88  alias = false; assigned = true; i = i0;
89  }
90  IntVarSpec(const Alias& eq, bool introduced, bool funcDep)
91  : VarSpec(introduced,funcDep) {
92  alias = true; i = eq.v;
93  }
94  ~IntVarSpec(void) {
95  if (!alias && !assigned && domain())
96  delete domain.some();
97  }
98  };
99 
101  class BoolVarSpec : public VarSpec {
102  public:
105  : VarSpec(introduced,funcDep) {
106  alias = false; assigned = false; domain = d;
107  }
108  BoolVarSpec(bool b, bool introduced, bool funcDep)
109  : VarSpec(introduced,funcDep) {
110  alias = false; assigned = true; i = b;
111  }
112  BoolVarSpec(const Alias& eq, bool introduced, bool funcDep)
113  : VarSpec(introduced,funcDep) {
114  alias = true; i = eq.v;
115  }
116  ~BoolVarSpec(void) {
117  if (!alias && !assigned && domain())
118  delete domain.some();
119  }
120  };
121 
123  class FloatVarSpec : public VarSpec {
124  public:
126  FloatVarSpec(Option<std::pair<double,double> >& d,
127  bool introduced, bool funcDep)
128  : VarSpec(introduced,funcDep), domain(d) {
129  alias = false; assigned = false;
130  }
131  FloatVarSpec(double d, bool introduced, bool funcDep)
132  : VarSpec(introduced,funcDep) {
133  alias = false; assigned = true;
134  domain = Option<std::pair<double,double> >::some(std::pair<double,double>(d,d));
135  }
136  FloatVarSpec(const Alias& eq, bool introduced, bool funcDep)
137  : VarSpec(introduced,funcDep) {
138  alias = true; i = eq.v;
139  }
140  };
141 
143  class SetVarSpec : public VarSpec {
144  public:
146  SetVarSpec(bool introduced, bool funcDep) : VarSpec(introduced,funcDep) {
147  alias = false; assigned = false;
148  upperBound = Option<AST::SetLit* >::none();
149  }
151  : VarSpec(introduced,funcDep) {
152  alias = false; assigned = false; upperBound = v;
153  }
155  : VarSpec(introduced,funcDep) {
156  alias = false; assigned = true;
157  upperBound = Option<AST::SetLit*>::some(v);
158  }
159  SetVarSpec(const Alias& eq, bool introduced, bool funcDep)
160  : VarSpec(introduced,funcDep) {
161  alias = true; i = eq.v;
162  }
163  ~SetVarSpec(void) {
164  if (!alias && upperBound())
165  delete upperBound.some();
166  }
167  };
168 
169 }}
170 
171 #endif
172 
173 // STATISTICS: flatzinc-any
Option< AST::SetLit * > domain
Definition: varspec.hh:78
IntVarSpec(int i0, bool introduced, bool funcDep)
Definition: varspec.hh:86
Specification for set variables.
Definition: varspec.hh:143
FloatVarSpec(Option< std::pair< double, double > > &d, bool introduced, bool funcDep)
Definition: varspec.hh:126
const Val & some(void) const
Definition: option.hh:51
virtual ~VarSpec(void)
Destructor.
Definition: varspec.hh:59
Gecode::IntSet d(v, 7)
BoolVarSpec(const Alias &eq, bool introduced, bool funcDep)
Definition: varspec.hh:112
FloatVarSpec(double d, bool introduced, bool funcDep)
Definition: varspec.hh:131
bool alias
Whether the variable aliases another variable.
Definition: varspec.hh:63
SetVarSpec(const Option< AST::SetLit * > &v, bool introduced, bool funcDep)
Definition: varspec.hh:150
Option< std::pair< double, double > > domain
Definition: varspec.hh:125
SetVarSpec(AST::SetLit *v, bool introduced, bool funcDep)
Definition: varspec.hh:154
SetVarSpec(const Alias &eq, bool introduced, bool funcDep)
Definition: varspec.hh:159
Specification for Boolean variables.
Definition: varspec.hh:101
VarSpec(bool introduced0, bool funcDep0)
Constructor.
Definition: varspec.hh:71
SetVarSpec(bool introduced, bool funcDep)
Definition: varspec.hh:146
BoolVarSpec(Option< AST::SetLit * > &d, bool introduced, bool funcDep)
Definition: varspec.hh:104
bool funcDep
Whether the variable functionally depends on another variable.
Definition: varspec.hh:69
static Option< Val > none(void)
Definition: option.hh:53
Option< AST::SetLit * > domain
Definition: varspec.hh:103
const int v[7]
Definition: distinct.cpp:207
bool assigned
Whether the variable is assigned.
Definition: varspec.hh:65
int i
Variable index.
Definition: varspec.hh:61
Set literal node
Definition: ast.hh:175
IntVarSpec(const Option< AST::SetLit * > &d, bool introduced, bool funcDep)
Definition: varspec.hh:79
Specification for floating point variables.
Definition: varspec.hh:123
Base class for variable specifications.
Definition: varspec.hh:56
IntVarSpec(const Alias &eq, bool introduced, bool funcDep)
Definition: varspec.hh:90
Alias for a variable specification
Definition: varspec.hh:49
FloatVarSpec(const Alias &eq, bool introduced, bool funcDep)
Definition: varspec.hh:136
struct Gecode::@518::NNF::@57::@58 b
For binary nodes (and, or, eqv)
Gecode toplevel namespace
Specification for integer variables.
Definition: varspec.hh:76
bool introduced
Whether the variable was introduced in the mzn2fzn translation.
Definition: varspec.hh:67
BoolVarSpec(bool b, bool introduced, bool funcDep)
Definition: varspec.hh:108
Option< AST::SetLit * > upperBound
Definition: varspec.hh:145