Generated on Tue Feb 11 2025 17:33:26 for Gecode by doxygen 1.12.0
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
39#include <vector>
40#include <iostream>
41
42namespace 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;
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)
78 alias = false;
79 assigned = false;
80 domain = d;
81 }
82 IntVarSpec(int i0, bool introduced, bool funcDep)
84 alias = false; assigned = true; i = i0; domain = Option<AST::SetLit* >::none();
85 }
86 IntVarSpec(const Alias& eq, bool introduced, bool funcDep)
88 alias = true; i = eq.v;
89 }
91 if (!alias && !assigned && domain())
92 delete domain.some();
93 }
94 };
95
97 class BoolVarSpec : public VarSpec {
98 public:
102 alias = false; assigned = false; domain = d;
103 }
104 BoolVarSpec(bool b, bool introduced, bool funcDep)
106 alias = false; assigned = true; i = b; domain = Option<AST::SetLit* >::none();
107 }
108 BoolVarSpec(const Alias& eq, bool introduced, bool funcDep)
110 alias = true; i = eq.v;
111 }
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)
125 alias = false; assigned = false;
126 }
127 FloatVarSpec(double d, bool introduced, bool 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)
134 alias = true; i = eq.v;
135 }
136 };
137
139 class SetVarSpec : public VarSpec {
140 public:
148 alias = false; assigned = false; upperBound = v;
149 }
155 SetVarSpec(const Alias& eq, bool introduced, bool funcDep)
157 alias = true; i = eq.v;
158 }
160 if (!alias && upperBound())
161 delete upperBound.some();
162 }
163 };
164
165}}
166
167#endif
168
169// STATISTICS: flatzinc-any
struct Gecode::@603::NNF::@65::@66 b
For binary nodes (and, or, eqv)
Set literal node
Definition ast.hh:171
Alias for a variable specification
Definition varspec.hh:45
Specification for Boolean variables.
Definition varspec.hh:97
BoolVarSpec(const Alias &eq, bool introduced, bool funcDep)
Definition varspec.hh:108
Option< AST::SetLit * > domain
Definition varspec.hh:99
BoolVarSpec(Option< AST::SetLit * > &d, bool introduced, bool funcDep)
Definition varspec.hh:100
BoolVarSpec(bool b, bool introduced, bool funcDep)
Definition varspec.hh:104
Specification for floating point variables.
Definition varspec.hh:119
Option< std::pair< double, double > > domain
Definition varspec.hh:121
FloatVarSpec(const Alias &eq, bool introduced, bool funcDep)
Definition varspec.hh:132
FloatVarSpec(Option< std::pair< double, double > > &d, bool introduced, bool funcDep)
Definition varspec.hh:122
FloatVarSpec(double d, bool introduced, bool funcDep)
Definition varspec.hh:127
Specification for integer variables.
Definition varspec.hh:72
IntVarSpec(int i0, bool introduced, bool funcDep)
Definition varspec.hh:82
Option< AST::SetLit * > domain
Definition varspec.hh:74
IntVarSpec(const Option< AST::SetLit * > &d, bool introduced, bool funcDep)
Definition varspec.hh:75
IntVarSpec(const Alias &eq, bool introduced, bool funcDep)
Definition varspec.hh:86
Specification for set variables.
Definition varspec.hh:139
SetVarSpec(const Option< AST::SetLit * > &v, bool introduced, bool funcDep)
Definition varspec.hh:146
SetVarSpec(AST::SetLit *v, bool introduced, bool funcDep)
Definition varspec.hh:150
Option< AST::SetLit * > upperBound
Definition varspec.hh:141
SetVarSpec(const Alias &eq, bool introduced, bool funcDep)
Definition varspec.hh:155
SetVarSpec(bool introduced, bool funcDep)
Definition varspec.hh:142
Base class for variable specifications.
Definition varspec.hh:52
VarSpec(bool introduced0, bool funcDep0)
Constructor.
Definition varspec.hh:67
virtual ~VarSpec(void)
Destructor.
Definition varspec.hh:55
int i
Variable index.
Definition varspec.hh:57
bool introduced
Whether the variable was introduced in the mzn2fzn translation.
Definition varspec.hh:63
bool assigned
Whether the variable is assigned.
Definition varspec.hh:61
bool alias
Whether the variable aliases another variable.
Definition varspec.hh:59
bool funcDep
Whether the variable functionally depends on another variable.
Definition varspec.hh:65
Gecode toplevel namespace
Optional value.
Definition option.hh:41
const Val & some(void) const
Definition option.hh:47
static Option< Val > none(void)
Definition option.hh:49