-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGraphProcessor.cpp
145 lines (114 loc) · 4.28 KB
/
GraphProcessor.cpp
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/***************************************************************************
* Copyright (C) 2014 by Mushthofa *
* unintendedchoice@gmail.com *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
/**
* @brief GraphProcessor.cpp
* Provides a class to perform evaluation along the components dep. graph
* Assuming that the components is already given in a topological ordering
*
* @author Mushthofa
*/
#include "GraphProcessor.h"
//#include "EvalComp.h"
GraphProcessor::GraphProcessor(DependencyGraph* dg)//, ASPSolverEngine* se)//, Eval* eval, int k)
// :solver_engine(se)//, ev(eval), step(k)
:found(false)
{
components = dg->getComponents();
/* Set up array for storing individual AS */
for(int i=0; i<components.size(); i++)
{
Program cur = components[i]->getBottom();
if(cur.size()>0)
compPrograms.push_back(cur);
}
numComp = compPrograms.size();
globalAS.resize(numComp);
}
GraphProcessor::~GraphProcessor()
{
}
FAnswerSet GraphProcessor::getInput(unsigned idx)
{
//std::cout<<"Get input "<<idx<<": "<<std::endl;
FAnswerSet result;
/* Merge all fuzzy answer set from previous components (number < idx) into one answer set
* Note: take care of finding the largest truth value among atoms a s.t. I(a)>0
*/
if(idx == 0)
{
return result;
}
for(unsigned i=0; i<idx; i++)
{
FAnswerSet cur = globalAS[i];
//std::cout<<"cur = "<<cur<<std::endl;
result = result.merge(cur);
}
//std::cout<<result<<std::endl;
return result;
}
void GraphProcessor::eval(unsigned idx)
{
// Get the input
FAnswerSet input = getInput(idx);
// Get the current component's program
Program currentComp = compPrograms[idx];
// Add the current input
currentComp = currentComp + input.getFacts();
// Decide what evaluation method we should call
//std::cout<<"Evaluating component "<<idx<<": " << std::endl;
//std::cout<<currentComp<<std::endl;
//std::cout <<"with input "<< std::endl << input << std::endl;
FAnswerSet currentAS;
int maxk = Globals::Instance()->intOption("maxk");
int maxtime = Globals::Instance()->intOption("maxt");
//bool printAS = !Globals::Instance()->boolOption("check");
stop_t stop = std::make_pair(maxk, maxtime);
int step = lcm(ConstantAtom::denomList);
step = lcm(step, input.getDenomLCM());
ASPSolverEngine* eng = new CLSolverEngine();
Eval* evaluator;
//bool needcheck = !components[idx]->isSRCF() && components[idx]->isDisjunctive();
evaluator = new ASPEval(eng, currentComp, stop, step, step);
//found = false;
while(!found && evaluator->answersetsLeft())
{
if(idx == numComp-1)
{
// Last component to be evaluated
// Just stream it out
// std::cout<<"Reached last component, streaming answer set: "<<std::endl;
currentAS = evaluator->getNextAnswerSet();
std::cout<<currentAS.getStrClean()<<std::endl;
//std::cout<<"<<Consistent>>"<<std::endl;
found = true;
}
else
{
// Call eval recursively for the next components
currentAS = evaluator->getNextAnswerSet();
//std::cout <<" Answer set of component " <<idx<<std::endl<<currentAS<<std::endl;
globalAS[idx] = currentAS;
eval(idx+1);
}
}
//delete evaluator;
}
//end