Something went wrong. Try again.
This repository has no description
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283/**** , [ OptVar.cc ],Copyright (c) 2008 Universite d'Orleans - Jeremie Vautard
Permission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included inall copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHERLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS INTHE SOFTWARE. *************************************************************************/
#include "OptVar.hh"
ExistOptVar::ExistOptVar(int var,int scope) { varId = var; scopeId=scope;}
int ExistOptVar::getVal(Strategy s) {// cout<<"getval on existoptvar "<<varId<<" at scope "<<scopeId<<endl; if (s.isTrue()) {cout<<"EOV "<<varId<<" scope "<<scopeId<<" try to get opt value on TRUE"<<endl;abort();} if (s.isFalse()) {cout<<"EOV "<<varId<<" scope "<<scopeId<<"Try to get opt value on FALSE"<<endl;abort();} // (sub)Strategy must neither be false if (s.isDummy()) {cout<<"EOV "<<varId<<" scope "<<scopeId<<"Try to get opt value on Dummy"<<endl;abort();} // nor begin with a universal scope 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 ^^
if (s.scope() == scopeId) return s.value(varId-s.VMin()); // s.getTag() < scope Strategy nextScope = s.getChild(0);
return getVal(nextScope);}
int ExistOptVar::getScope() {return scopeId;}
UnivOptVar::UnivOptVar(int scope,OptVar* zevar, Aggregator* agg) { var=zevar; fct=agg; scopeId=scope;}
int UnivOptVar::getVal(Strategy s) {// cout<<"getVal sur univoptvar "<<scopeId<<endl; vector<int> values; values.clear(); if (s.isFalse()) {cout<<"UOV Try to get opt value on FALSE"<<endl;abort();} if (s.isTrue()) return fct->eval(values); if (s.isDummy()) { for (int i=0;i<s.degree();i++) { values.push_back(var->getVal(s.getChild(i))); } return fct->eval(values); }
if (s.scope() == (scopeId-1)) { for (int i=0;i<s.degree();i++) { values.push_back(var->getVal(s.getChild(i))); } return fct->eval(values); }
if (s.scope() < (scopeId-1) ) { if (s.quantifier()) {cout<<"UOV universal scope too soon"<<endl;abort();} // universal quantifier too soon return getVal(s.getChild(0)); } // s.scope() > scope-1 -> too far away cout<<"UOV try to get aggregate on a substrategy not containing required scope"<<endl; abort(); return 0; // dummy return to avoid a compiler complain...}
int UnivOptVar::getScope() {return scopeId;}