00001 /**** , [ OptVar.cc ], 00002 Copyright (c) 2008 Universite d'Orleans - Jeremie Vautard 00003 00004 Permission is hereby granted, free of charge, to any person obtaining a copy 00005 of this software and associated documentation files (the "Software"), to deal 00006 in the Software without restriction, including without limitation the rights 00007 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00008 copies of the Software, and to permit persons to whom the Software is 00009 furnished to do so, subject to the following conditions: 00010 00011 The above copyright notice and this permission notice shall be included in 00012 all copies or substantial portions of the Software. 00013 00014 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00015 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00016 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00017 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00018 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00019 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00020 THE SOFTWARE. 00021 *************************************************************************/ 00022 00023 #include "OptVar.hh" 00024 00025 ExistOptVar::ExistOptVar(int var,int scope) { 00026 varId = var; 00027 scopeId=scope; 00028 } 00029 00030 int ExistOptVar::getVal(Strategy s) { 00031 // cout<<"getval on existoptvar "<<varId<<" at scope "<<scopeId<<endl; 00032 if (s.isTrue()) {cout<<"EOV "<<varId<<" scope "<<scopeId<<" try to get opt value on TRUE"<<endl;abort();} 00033 if (s.isFalse()) {cout<<"EOV "<<varId<<" scope "<<scopeId<<"Try to get opt value on FALSE"<<endl;abort();} // (sub)Strategy must neither be false 00034 if (s.isDummy()) {cout<<"EOV "<<varId<<" scope "<<scopeId<<"Try to get opt value on Dummy"<<endl;abort();} // nor begin with a universal scope 00035 if (s.scope() > scopeId) {cout<<"EOV "<<varId<<" scope "<<scopeId<<"Try to get opt value on asubstrategy not containing opt variable"<<endl;abort();} // nor begin at a scope after the one we want ^^ 00036 00037 if (s.scope() == scopeId) return s.value(varId-s.VMin()); 00038 // s.getTag() < scope 00039 Strategy nextScope = s.getChild(0); 00040 00041 return getVal(nextScope); 00042 } 00043 00044 int ExistOptVar::getScope() {return scopeId;} 00045 00046 UnivOptVar::UnivOptVar(int scope,OptVar* zevar, Aggregator* agg) { 00047 var=zevar; 00048 fct=agg; 00049 scopeId=scope; 00050 } 00051 00052 int UnivOptVar::getVal(Strategy s) { 00053 // cout<<"getVal sur univoptvar "<<scopeId<<endl; 00054 vector<int> values; values.clear(); 00055 if (s.isFalse()) {cout<<"UOV Try to get opt value on FALSE"<<endl;abort();} 00056 if (s.isTrue()) return fct->eval(values); 00057 if (s.isDummy()) { 00058 for (int i=0;i<s.degree();i++) { 00059 values.push_back(var->getVal(s.getChild(i))); 00060 } 00061 return fct->eval(values); 00062 } 00063 00064 if (s.scope() == (scopeId-1)) { 00065 for (int i=0;i<s.degree();i++) { 00066 values.push_back(var->getVal(s.getChild(i))); 00067 } 00068 return fct->eval(values); 00069 } 00070 00071 if (s.scope() < (scopeId-1) ) { 00072 if (s.quantifier()) {cout<<"UOV universal scope too soon"<<endl;abort();} // universal quantifier too soon 00073 return getVal(s.getChild(0)); 00074 } 00075 // s.scope() > scope-1 -> too far away 00076 cout<<"UOV try to get aggregate on a substrategy not containing required scope"<<endl; 00077 abort(); 00078 return 0; // dummy return to avoid a compiler complain... 00079 } 00080 00081 00082 int UnivOptVar::getScope() {return scopeId;}