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++) { 23 iv[i].update(*this, f.iv[i]); 24 } 25 for (auto&& i : f.ivIntroduced) { 26 ivIntroduced.push_back(i); 27 } 28 for (auto&& i : f.ivDefined) { 29 ivDefined.push_back(i); 30 } 31 if (f.copyAuxVars) { 32 IntVarArgs iva; 33 for (int i = 0; i < f.ivAux.size(); i++) { 34 if (!f.ivAux[i].assigned()) { 35 iva << IntVar(); 36 iva[iva.size() - 1].update(*this, f.ivAux[i]); 37 } 38 } 39 ivAux = IntVarArray(*this, iva); 40 } 41 42 // boolean variables 43 bv.resize(f.bv.size()); 44 for (unsigned int i = 0; i < bv.size(); i++) { 45 bv[i].update(*this, f.bv[i]); 46 } 47 if (f.copyAuxVars) { 48 BoolVarArgs bva; 49 for (int i = 0; i < f.bvAux.size(); i++) { 50 if (!f.bvAux[i].assigned()) { 51 bva << BoolVar(); 52 bva[bva.size() - 1].update(*this, f.bvAux[i]); 53 } 54 } 55 bvAux = BoolVarArray(*this, bva); 56 } 57 for (auto&& i : f.bvIntroduced) { 58 bvIntroduced.push_back(i); 59 } 60 61#ifdef GECODE_HAS_SET_VARS 62 sv.resize(f.sv.size()); 63 for (unsigned int i = 0; i < sv.size(); i++) { 64 sv[i].update(*this, f.sv[i]); 65 } 66 if (f.copyAuxVars) { 67 SetVarArgs sva; 68 for (int i = 0; i < f.svAux.size(); i++) { 69 if (!f.svAux[i].assigned()) { 70 sva << SetVar(); 71 sva[sva.size() - 1].update(*this, f.svAux[i]); 72 } 73 } 74 svAux = SetVarArray(*this, sva); 75 } 76 for (auto&& i : f.svIntroduced) { 77 svIntroduced.push_back(i); 78 } 79#endif 80 81#ifdef GECODE_HAS_FLOAT_VARS 82 fv.resize(f.fv.size()); 83 for (unsigned int i = 0; i < fv.size(); i++) { 84 fv[i].update(*this, f.fv[i]); 85 } 86 if (f.copyAuxVars) { 87 FloatVarArgs fva; 88 for (int i = 0; i < f.fvAux.size(); i++) { 89 if (!f.fvAux[i].assigned()) { 90 fva << FloatVar(); 91 fva[fva.size() - 1].update(*this, f.fvAux[i]); 92 } 93 } 94 fvAux = FloatVarArray(*this, fva); 95 } 96#endif 97 98 optVarIsInt = f.optVarIsInt; 99 optVarIdx = f.optVarIdx; 100 copyAuxVars = f.copyAuxVars; 101 solveType = f.solveType; 102} 103 104Gecode::Space* FznSpace::copy() { return new FznSpace(*this); } 105 106void FznSpace::constrain(const Space& s) { 107 if (optVarIsInt) { 108 if (solveType == MiniZinc::SolveI::SolveType::ST_MIN) { 109 rel(*this, iv[optVarIdx], IRT_LE, static_cast<const FznSpace*>(&s)->iv[optVarIdx].val()); 110 } else if (solveType == MiniZinc::SolveI::SolveType::ST_MAX) { 111 rel(*this, iv[optVarIdx], IRT_GR, static_cast<const FznSpace*>(&s)->iv[optVarIdx].val()); 112 } 113 } else { 114#ifdef GECODE_HAS_FLOAT_VARS 115 if (solveType == MiniZinc::SolveI::SolveType::ST_MIN) { 116 rel(*this, fv[optVarIdx], FRT_LE, static_cast<const FznSpace*>(&s)->fv[optVarIdx].val()); 117 } else if (solveType == MiniZinc::SolveI::SolveType::ST_MAX) { 118 rel(*this, fv[optVarIdx], FRT_GR, static_cast<const FznSpace*>(&s)->fv[optVarIdx].val()); 119 } 120#endif 121 } 122} 123 124} // namespace MiniZinc