this repo has no description
1/*
2 * Main authors:
3 * Kevin Leo <kevin.leo@monash.edu>
4 * Andrea Rendl <andrea.rendl@nicta.com.au>
5 * Guido Tack <guido.tack@monash.edu>
6 */
7
8/* This Source Code Form is subject to the terms of the Mozilla Public
9 * License, v. 2.0. If a copy of the MPL was not distributed with this
10 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
11
12#include <minizinc/solvers/gecode/fzn_space.hh>
13#include <minizinc/solvers/gecode_solverinstance.hh>
14
15using namespace Gecode;
16
17namespace MiniZinc {
18
19FznSpace::FznSpace(FznSpace& f) : Space(f) {
20 // integer variables
21 iv.resize(f.iv.size());
22 for (unsigned int i = 0; i < iv.size(); i++) iv[i].update(*this, f.iv[i]);
23 for (unsigned int i = 0; i < f.iv_introduced.size(); i++)
24 iv_introduced.push_back(f.iv_introduced[i]);
25 for (unsigned int i = 0; i < f.iv_defined.size(); i++) iv_defined.push_back(f.iv_defined[i]);
26 if (f._copyAuxVars) {
27 IntVarArgs iva;
28 for (int i = 0; i < f.iv_aux.size(); i++) {
29 if (!f.iv_aux[i].assigned()) {
30 iva << IntVar();
31 iva[iva.size() - 1].update(*this, f.iv_aux[i]);
32 }
33 }
34 iv_aux = IntVarArray(*this, iva);
35 }
36
37 // boolean variables
38 bv.resize(f.bv.size());
39 for (unsigned int i = 0; i < bv.size(); i++) bv[i].update(*this, f.bv[i]);
40 if (f._copyAuxVars) {
41 BoolVarArgs bva;
42 for (int i = 0; i < f.bv_aux.size(); i++) {
43 if (!f.bv_aux[i].assigned()) {
44 bva << BoolVar();
45 bva[bva.size() - 1].update(*this, f.bv_aux[i]);
46 }
47 }
48 bv_aux = BoolVarArray(*this, bva);
49 }
50 for (unsigned int i = 0; i < f.bv_introduced.size(); i++)
51 bv_introduced.push_back(f.bv_introduced[i]);
52
53#ifdef GECODE_HAS_SET_VARS
54 sv.resize(f.sv.size());
55 for (unsigned int i = 0; i < sv.size(); i++) sv[i].update(*this, f.sv[i]);
56 if (f._copyAuxVars) {
57 SetVarArgs sva;
58 for (int i = 0; i < f.sv_aux.size(); i++) {
59 if (!f.sv_aux[i].assigned()) {
60 sva << SetVar();
61 sva[sva.size() - 1].update(*this, f.sv_aux[i]);
62 }
63 }
64 sv_aux = SetVarArray(*this, sva);
65 }
66 for (unsigned int i = 0; i < f.sv_introduced.size(); i++)
67 sv_introduced.push_back(f.sv_introduced[i]);
68#endif
69
70#ifdef GECODE_HAS_FLOAT_VARS
71 fv.resize(f.fv.size());
72 for (unsigned int i = 0; i < fv.size(); i++) fv[i].update(*this, f.fv[i]);
73 if (f._copyAuxVars) {
74 FloatVarArgs fva;
75 for (int i = 0; i < f.fv_aux.size(); i++) {
76 if (!f.fv_aux[i].assigned()) {
77 fva << FloatVar();
78 fva[fva.size() - 1].update(*this, f.fv_aux[i]);
79 }
80 }
81 fv_aux = FloatVarArray(*this, fva);
82 }
83#endif
84
85 _optVarIsInt = f._optVarIsInt;
86 _optVarIdx = f._optVarIdx;
87 _copyAuxVars = f._copyAuxVars;
88 _solveType = f._solveType;
89}
90
91Gecode::Space* FznSpace::copy(void) { return new FznSpace(*this); }
92
93void FznSpace::constrain(const Space& s) {
94 if (_optVarIsInt) {
95 if (_solveType == MiniZinc::SolveI::SolveType::ST_MIN)
96 rel(*this, iv[_optVarIdx], IRT_LE, static_cast<const FznSpace*>(&s)->iv[_optVarIdx].val());
97 else if (_solveType == MiniZinc::SolveI::SolveType::ST_MAX)
98 rel(*this, iv[_optVarIdx], IRT_GR, static_cast<const FznSpace*>(&s)->iv[_optVarIdx].val());
99 } else {
100#ifdef GECODE_HAS_FLOAT_VARS
101 if (_solveType == MiniZinc::SolveI::SolveType::ST_MIN)
102 rel(*this, fv[_optVarIdx], FRT_LE, static_cast<const FznSpace*>(&s)->fv[_optVarIdx].val());
103 else if (_solveType == MiniZinc::SolveI::SolveType::ST_MAX)
104 rel(*this, fv[_optVarIdx], FRT_GR, static_cast<const FznSpace*>(&s)->fv[_optVarIdx].val());
105#endif
106 }
107}
108
109} // namespace MiniZinc