this repo has no description
1/*****************************************************************[myspace.cc] 2Copyright (c) 2007, Universite d'Orleans - Jeremie Vautard, Marco Benedetti, 3Arnaud Lallouet. 4 5Permission is hereby granted, free of charge, to any person obtaining a copy 6of this software and associated documentation files (the "Software"), to deal 7in the Software without restriction, including without limitation the rights 8to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9copies of the Software, and to permit persons to whom the Software is 10furnished to do so, subject to the following conditions: 11 12The above copyright notice and this permission notice shall be included in 13all copies or substantial portions of the Software. 14 15THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21THE SOFTWARE. 22*****************************************************************************/ 23#include "./myspace.hh" 24#include <iostream> 25 26 27using namespace std; 28 29MySpace::MySpace(unsigned int nv) : Space() { 30 // cout <<"Space with "<<nv<<" variables"<<endl; 31 n=nv; 32 v=new void*[nv]; 33 type_of_v=new VarType[nv]; 34} 35 36 37MySpace::~MySpace() { 38 for (int i=0;i<n;i++) 39 switch (type_of_v[i]) { 40 case VTYPE_INT : 41 delete static_cast<IntVar*>(v[i]); 42 break; 43 case VTYPE_BOOL : 44 delete static_cast<BoolVar*>(v[i]); 45 break; 46 default : 47 cout<<"Unsupported variable type"<<endl; 48 abort(); 49 } 50 51 delete[] v; 52 delete[] type_of_v; 53} 54 55 56MySpace::MySpace(bool share,MySpace& ms) : Space(share,ms) { 57 n=ms.n; 58 v=new void*[n]; 59 type_of_v=new VarType[n]; 60 for (int i=0;i<n;i++) { 61 type_of_v[i] = ms.type_of_v[i]; 62 switch (type_of_v[i]) { 63 case VTYPE_INT : 64 v[i] = new IntVar(*(static_cast<IntVar*>(ms.v[i]))); 65 (static_cast<IntVar*>(v[i]))->update(*this,share,*(static_cast<IntVar*>(ms.v[i]))); 66 break; 67 case VTYPE_BOOL : 68 v[i] = new BoolVar(*(static_cast<BoolVar*>(ms.v[i]))); 69 (static_cast<BoolVar*>(v[i]))->update(*this,share,*(static_cast<BoolVar*>(ms.v[i]))); 70 break; 71 default: 72 cout<<"Unsupported variable type"<<endl; 73 abort(); 74 } 75 } 76} 77 78 79MySpace* MySpace::copy(bool share) {return new MySpace(share,*this);} 80 81IntVarArgs MySpace::getIntVars(unsigned int idMax) { 82 int cpt=0; 83 int i=0; 84 if (n<idMax) idMax=n; 85 86 for (int i=0;i<idMax;i++) { 87 if (type_of_v[i]==VTYPE_INT) cpt++; 88 } 89 IntVarArgs ret(cpt); 90 cpt=0; 91 for (i=0;i<idMax;i++) { 92 if (type_of_v[i]==VTYPE_INT) { 93 ret[cpt]=*(static_cast<IntVar*>(v[i])); 94 cpt++; 95 } 96 } 97 98 return ret; 99} 100 101BoolVarArgs MySpace::getBoolVars(unsigned int idMax) { 102 int cpt=0; 103 int i=0; 104 if (n<idMax) idMax=n; 105 106 for (int i=0;i<idMax;i++) { 107 if (type_of_v[i]==VTYPE_BOOL) cpt++; 108 } 109 BoolVarArgs ret(cpt); 110 cpt=0; 111 for (i=0;i<idMax;i++) { 112 if (type_of_v[i]==VTYPE_BOOL) { 113 ret[cpt]=*(static_cast<BoolVar*>(v[i])); 114 cpt++; 115 } 116 } 117 118 return ret; 119}