this repo has no description
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
37#include <gecode/flatzinc/option.hh>
38#include <gecode/flatzinc/ast.hh>
39#include <vector>
40#include <iostream>
41
42namespace Gecode { namespace FlatZinc {
43
44 /// %Alias for a variable specification
45 class Alias {
46 public:
47 const int v;
48 Alias(int v0) : v(v0) {}
49 };
50
51 /// Base class for variable specifications
52 class VarSpec {
53 public:
54 /// Destructor
55 virtual ~VarSpec(void) {}
56 /// Variable index
57 int i;
58 /// Whether the variable aliases another variable
59 bool alias;
60 /// Whether the variable is assigned
61 bool assigned;
62 /// Whether the variable was introduced in the mzn2fzn translation
63 bool introduced;
64 /// Whether the variable functionally depends on another variable
65 bool funcDep;
66 /// Constructor
67 VarSpec(bool introduced0, bool funcDep0)
68 : introduced(introduced0), funcDep(funcDep0) {}
69 };
70
71 /// Specification for integer variables
72 class IntVarSpec : public VarSpec {
73 public:
74 Option<AST::SetLit* > domain;
75 IntVarSpec(const Option<AST::SetLit* >& d,
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
96 /// Specification for Boolean variables
97 class BoolVarSpec : public VarSpec {
98 public:
99 Option<AST::SetLit* > domain;
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
118 /// Specification for floating point variables
119 class FloatVarSpec : public VarSpec {
120 public:
121 Option<std::pair<double,double> > domain;
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
138 /// Specification for set variables
139 class SetVarSpec : public VarSpec {
140 public:
141 Option<AST::SetLit*> upperBound;
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