-
Notifications
You must be signed in to change notification settings - Fork 1
/
proofchecker.h
81 lines (72 loc) · 2.98 KB
/
proofchecker.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#ifndef PROOFCHECKER_H
#define PROOFCHECKER_H
#include "actionset.h"
#include "knowledge.h"
#include "stateset.h"
#include "task.h"
#include <deque>
#include <memory>
#include <sstream>
#include <string>
#include <vector>
class ProofChecker
{
private:
Task task;
std::deque<std::unique_ptr<StateSet>> statesets;
std::deque<std::unique_ptr<ActionSet>> actionsets;
std::deque<std::unique_ptr<Knowledge>> knowledgebase;
bool unsolvability_proven;
void add_knowledge(std::unique_ptr<Knowledge> entry, KnowledgeID id);
public:
ProofChecker(std::string &task_file);
void add_state_set(std::stringstream &line);
void add_action_set(std::stringstream &line);
void verify_knowledge(std::stringstream &line);
bool is_unsolvability_proven();
template<class T, typename std::enable_if<std::is_base_of<ActionSet, T>::value>::type * = nullptr>
const T *get_set(SetID set_id) const {
if (set_id < 0 || set_id >= actionsets.size() || !actionsets[set_id]) {
throw std::runtime_error("Action set expression #" +
std::to_string(set_id) +
" does not exist.");
}
const T* ret= dynamic_cast<const T *>(actionsets[set_id].get());
if (!ret) {
throw std::runtime_error("Action set expression #" +
std::to_string(set_id) +
" is not of type " + typeid(T).name());
}
return ret;
}
template<class T, typename std::enable_if<std::is_base_of<StateSet, T>::value>::type * = nullptr>
const T *get_set(SetID set_id) const {
if (set_id < 0 || set_id >= statesets.size() || !statesets[set_id]) {
throw std::runtime_error("State set expression #" +
std::to_string(set_id) +
" does not exist.");
}
const T* ret= dynamic_cast<const T *>(statesets[set_id].get());
if (!ret) {
throw std::runtime_error("State set expression #" +
std::to_string(set_id) +
" is not of type " + typeid(T).name());
}
return ret;
}
template<class T, typename std::enable_if<std::is_base_of<Knowledge, T>::value>::type * = nullptr>
const T *get_knowledge(KnowledgeID knowledge_id) const {
if (knowledge_id < 0 || knowledge_id >= knowledgebase.size()
|| !knowledgebase[knowledge_id]) {
throw std::runtime_error("Knowledge #" + std::to_string(knowledge_id) +
" does not exist.");
}
const T* ret= dynamic_cast<const T *>(knowledgebase[knowledge_id].get());
if (!ret) {
throw std::runtime_error("Knowledge #" + std::to_string(knowledge_id) +
" is not of type " + typeid(T).name());
}
return ret;
}
};
#endif // PROOFCHECKER_H