Generated on Tue Jan 19 2021 06:15:49 for Gecode by doxygen 1.8.13
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  * This file is part of Gecode, the generic constraint
10  * development environment:
11  * http://www.gecode.org
12  *
13  * Permission is hereby granted, free of charge, to any person obtaining
14  * a copy of this software and associated documentation files (the
15  * "Software"), to deal in the Software without restriction, including
16  * without limitation the rights to use, copy, modify, merge, publish,
17  * distribute, sublicense, and/or sell copies of the Software, and to
18  * permit persons to whom the Software is furnished to do so, subject to
19  * the following conditions:
20  *
21  * The above copyright notice and this permission notice shall be
22  * included in all copies or substantial portions of the Software.
23  *
24  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31  *
32  */
33 
34 #ifndef __GECODE_FLATZINC_VARSPEC__HH__
35 #define __GECODE_FLATZINC_VARSPEC__HH__
36 
38 #include <gecode/flatzinc/ast.hh>
39 #include <vector>
40 #include <iostream>
41 
42 namespace Gecode { namespace FlatZinc {
43 
45  class Alias {
46  public:
47  const int v;
48  Alias(int v0) : v(v0) {}
49  };
50 
52  class VarSpec {
53  public:
55  virtual ~VarSpec(void) {}
57  int i;
59  bool alias;
61  bool assigned;
63  bool introduced;
65  bool funcDep;
67  VarSpec(bool introduced0, bool funcDep0)
68  : introduced(introduced0), funcDep(funcDep0) {}
69  };
70 
72  class IntVarSpec : public VarSpec {
73  public:
76  bool introduced, bool funcDep)
77  : VarSpec(introduced,funcDep) {
78  alias = false;
79  assigned = false;
80  domain = d;
81  }
82  IntVarSpec(int i0, bool introduced, bool funcDep)
83  : VarSpec(introduced,funcDep) {
84  alias = false; assigned = true; i = i0; domain = Option<AST::SetLit* >::none();
85  }
86  IntVarSpec(const Alias& eq, bool introduced, bool funcDep)
87  : VarSpec(introduced,funcDep) {
88  alias = true; i = eq.v;
89  }
90  ~IntVarSpec(void) {
91  if (!alias && !assigned && domain())
92  delete domain.some();
93  }
94  };
95 
97  class BoolVarSpec : public VarSpec {
98  public:
100  BoolVarSpec(Option<AST::SetLit* >& d, bool introduced, bool funcDep)
101  : VarSpec(introduced,funcDep) {
102  alias = false; assigned = false; domain = d;
103  }
104  BoolVarSpec(bool b, bool introduced, bool funcDep)
105  : VarSpec(introduced,funcDep) {
106  alias = false; assigned = true; i = b; domain = Option<AST::SetLit* >::none();
107  }
108  BoolVarSpec(const Alias& eq, bool introduced, bool funcDep)
109  : VarSpec(introduced,funcDep) {
110  alias = true; i = eq.v;
111  }
112  ~BoolVarSpec(void) {
113  if (!alias && !assigned && domain())
114  delete domain.some();
115  }
116  };
117 
119  class FloatVarSpec : public VarSpec {
120  public:
122  FloatVarSpec(Option<std::pair<double,double> >& d,
123  bool introduced, bool funcDep)
124  : VarSpec(introduced,funcDep), domain(d) {
125  alias = false; assigned = false;
126  }
127  FloatVarSpec(double d, bool introduced, bool funcDep)
128  : VarSpec(introduced,funcDep) {
129  alias = false; assigned = true;
130  domain = Option<std::pair<double,double> >::some(std::pair<double,double>(d,d));
131  }
132  FloatVarSpec(const Alias& eq, bool introduced, bool funcDep)
133  : VarSpec(introduced,funcDep) {
134  alias = true; i = eq.v;
135  }
136  };
137 
139  class SetVarSpec : public VarSpec {
140  public:
142  SetVarSpec(bool introduced, bool funcDep) : VarSpec(introduced,funcDep) {
143  alias = false; assigned = false;
144  upperBound = Option<AST::SetLit* >::none();
145  }
146  SetVarSpec(const Option<AST::SetLit* >& v, bool introduced, bool funcDep)
147  : VarSpec(introduced,funcDep) {
148  alias = false; assigned = false; upperBound = v;
149  }
150  SetVarSpec(AST::SetLit* v, bool introduced, bool funcDep)
151  : VarSpec(introduced,funcDep) {
152  alias = false; assigned = true;
153  upperBound = Option<AST::SetLit*>::some(v);
154  }
155  SetVarSpec(const Alias& eq, bool introduced, bool funcDep)
156  : VarSpec(introduced,funcDep) {
157  alias = true; i = eq.v;
158  }
159  ~SetVarSpec(void) {
160  if (!alias && upperBound())
161  delete upperBound.some();
162  }
163  };
164 
165 }}
166 
167 #endif
168 
169 // STATISTICS: flatzinc-any
Option< AST::SetLit *> domain
Definition: varspec.hh:74
Optional value.
Definition: option.hh:41
IntVarSpec(int i0, bool introduced, bool funcDep)
Definition: varspec.hh:82
Specification for set variables.
Definition: varspec.hh:139
FloatVarSpec(Option< std::pair< double, double > > &d, bool introduced, bool funcDep)
Definition: varspec.hh:122
virtual ~VarSpec(void)
Destructor.
Definition: varspec.hh:55
Gecode::IntSet d(v, 7)
BoolVarSpec(const Alias &eq, bool introduced, bool funcDep)
Definition: varspec.hh:108
FloatVarSpec(double d, bool introduced, bool funcDep)
Definition: varspec.hh:127
bool alias
Whether the variable aliases another variable.
Definition: varspec.hh:59
SetVarSpec(const Option< AST::SetLit * > &v, bool introduced, bool funcDep)
Definition: varspec.hh:146
Option< std::pair< double, double > > domain
Definition: varspec.hh:121
SetVarSpec(AST::SetLit *v, bool introduced, bool funcDep)
Definition: varspec.hh:150
Gecode::IntArgs i({1, 2, 3, 4})
SetVarSpec(const Alias &eq, bool introduced, bool funcDep)
Definition: varspec.hh:155
Specification for Boolean variables.
Definition: varspec.hh:97
struct Gecode::@593::NNF::@62::@63 b
For binary nodes (and, or, eqv)
VarSpec(bool introduced0, bool funcDep0)
Constructor.
Definition: varspec.hh:67
SetVarSpec(bool introduced, bool funcDep)
Definition: varspec.hh:142
BoolVarSpec(Option< AST::SetLit * > &d, bool introduced, bool funcDep)
Definition: varspec.hh:100
bool funcDep
Whether the variable functionally depends on another variable.
Definition: varspec.hh:65
static Option< Val > none(void)
Definition: option.hh:49
Option< AST::SetLit *> domain
Definition: varspec.hh:99
bool assigned
Whether the variable is assigned.
Definition: varspec.hh:61
int i
Variable index.
Definition: varspec.hh:57
Set literal node
Definition: ast.hh:171
bool assigned(View x, int v)
Whether x is assigned to value v.
Definition: single.hpp:43
IntVarSpec(const Option< AST::SetLit * > &d, bool introduced, bool funcDep)
Definition: varspec.hh:75
Specification for floating point variables.
Definition: varspec.hh:119
Base class for variable specifications.
Definition: varspec.hh:52
IntVarSpec(const Alias &eq, bool introduced, bool funcDep)
Definition: varspec.hh:86
Alias for a variable specification
Definition: varspec.hh:45
FloatVarSpec(const Alias &eq, bool introduced, bool funcDep)
Definition: varspec.hh:132
Gecode toplevel namespace
Specification for integer variables.
Definition: varspec.hh:72
bool introduced
Whether the variable was introduced in the mzn2fzn translation.
Definition: varspec.hh:63
const Val & some(void) const
Definition: option.hh:47
BoolVarSpec(bool b, bool introduced, bool funcDep)
Definition: varspec.hh:104
Option< AST::SetLit * > upperBound
Definition: varspec.hh:141