this repo has no description
1/**** , [ OptVar.cc ],
2Copyright (c) 2008 Universite d'Orleans - Jeremie Vautard
3
4Permission is hereby granted, free of charge, to any person obtaining a copy
5of this software and associated documentation files (the "Software"), to deal
6in the Software without restriction, including without limitation the rights
7to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8copies of the Software, and to permit persons to whom the Software is
9furnished to do so, subject to the following conditions:
10
11The above copyright notice and this permission notice shall be included in
12all copies or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20THE SOFTWARE.
21 *************************************************************************/
22
23#include "OptVar.hh"
24
25ExistOptVar::ExistOptVar(int var,int scope) {
26 varId = var;
27 scopeId=scope;
28}
29
30int ExistOptVar::getVal(Strategy s) {
31// cout<<"getval on existoptvar "<<varId<<" at scope "<<scopeId<<endl;
32 if (s.isTrue()) {cout<<"EOV "<<varId<<" scope "<<scopeId<<" try to get opt value on TRUE"<<endl;abort();}
33 if (s.isFalse()) {cout<<"EOV "<<varId<<" scope "<<scopeId<<"Try to get opt value on FALSE"<<endl;abort();} // (sub)Strategy must neither be false
34 if (s.isDummy()) {cout<<"EOV "<<varId<<" scope "<<scopeId<<"Try to get opt value on Dummy"<<endl;abort();} // nor begin with a universal scope
35 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 ^^
36
37 if (s.scope() == scopeId) return s.value(varId-s.VMin());
38 // s.getTag() < scope
39 Strategy nextScope = s.getChild(0);
40
41 return getVal(nextScope);
42}
43
44int ExistOptVar::getScope() {return scopeId;}
45
46UnivOptVar::UnivOptVar(int scope,OptVar* zevar, Aggregator* agg) {
47 var=zevar;
48 fct=agg;
49 scopeId=scope;
50}
51
52int UnivOptVar::getVal(Strategy s) {
53// cout<<"getVal sur univoptvar "<<scopeId<<endl;
54 vector<int> values; values.clear();
55 if (s.isFalse()) {cout<<"UOV Try to get opt value on FALSE"<<endl;abort();}
56 if (s.isTrue()) return fct->eval(values);
57 if (s.isDummy()) {
58 for (int i=0;i<s.degree();i++) {
59 values.push_back(var->getVal(s.getChild(i)));
60 }
61 return fct->eval(values);
62 }
63
64 if (s.scope() == (scopeId-1)) {
65 for (int i=0;i<s.degree();i++) {
66 values.push_back(var->getVal(s.getChild(i)));
67 }
68 return fct->eval(values);
69 }
70
71 if (s.scope() < (scopeId-1) ) {
72 if (s.quantifier()) {cout<<"UOV universal scope too soon"<<endl;abort();} // universal quantifier too soon
73 return getVal(s.getChild(0));
74 }
75 // s.scope() > scope-1 -> too far away
76 cout<<"UOV try to get aggregate on a substrategy not containing required scope"<<endl;
77 abort();
78 return 0; // dummy return to avoid a compiler complain...
79}
80
81
82int UnivOptVar::getScope() {return scopeId;}