-
Notifications
You must be signed in to change notification settings - Fork 77
/
Copy pathOptVar.cc
82 lines (67 loc) · 3.33 KB
/
OptVar.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/**** , [ OptVar.cc ],
Copyright (c) 2008 Universite d'Orleans - Jeremie Vautard
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, 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 IN
THE 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;}