-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.h
57 lines (49 loc) · 1.88 KB
/
Program.h
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
#ifndef PASPPROGRAM_H
#define PASPPROGRAM_H
#include <string>
#include <map>
#include <set>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <Eigen/Core>
#include "c++11_warning.h"
#include "Rule.h"
class Bridge;
using namespace std;
struct SecondElementComparator {
bool operator() (const pair<Literal, double>& lhs, const pair<Literal, double>& rhs) const { return lhs.second > rhs.second; }
};
/* Represents a program */
class Program {
public:
Program (Bridge *b) : bridge(b) {};
virtual ~Program() {};
void addRule(Rule_ptr);
list<Rule_ptr>::const_iterator rulesBeginIterator() const;
list<Rule_ptr>::const_iterator rulesEndIterator() const;
void nameLiteral(const Literal& l, const string& n);
void assignProbability(const string& literalName, double n);
string getLiteralName(const Literal& l) const;
double getLiteralProbability(const Literal& l) const;
unsigned int numProbabilities() const;
void initializeBase(Eigen::MatrixXd& m) const;
bool consistent() const;
bool consistent(const Eigen::VectorXd &v) const;
pair<Eigen::MatrixXd, Eigen::VectorXd> solve() const;
list<Literal> positiveTargets;
list<Literal> negativeTargets;
private:
void setInitialBase(Eigen::MatrixXd &m) const;
Eigen::VectorXd selectColumn(const Eigen::MatrixXd&, const double, const Eigen::VectorXd &) const;
void changeBase(Eigen::MatrixXd&, Eigen::MatrixXd&, const Eigen::VectorXd&, const Eigen::VectorXd&, Eigen::VectorXd&) const;
Eigen::VectorXd answerSetToVector(const unordered_set<Literal>&) const;
list<Rule_ptr> rules;
unordered_map<Literal, string> symTable;
/* This must be in a descending order. That's the reason for this type */
set<pair<Literal, double>, SecondElementComparator> probabilityTable;
Bridge *bridge;
friend class ProgramTest;
};
#endif /* PASPPROGRAM_H */