Project

General

Profile

Statistics
| Branch: | Revision:

cool / src / lib / GMLMIP-0.1 / rules / premise.h @ 7c4d2eb4

History | View | Annotate | Download (1.67 KB)

1
#ifndef PREMISE_HH
2
#define PREMISE_HH
3

    
4
#include <iostream>
5
#include <sstream>
6
#include <string>
7

    
8
#include <ext/hash_map>
9

    
10
#include "../formulas/rational.h"
11

    
12
using __gnu_cxx::hash;
13
using namespace std;
14

    
15
template<class T>
16
class Premise {
17
        protected:
18
                // Naming follows from the names of the rules - kept as one letter for succinctness.
19
                int n; // number of positive
20
                int m; // number of negative
21
                int total_valuations;
22
                T* a;  // modal indicies - positive
23
                T* b;  // modal indicies - negative
24
                
25
        public:
26
                Premise();
27
                Premise(int _n, int _m, T* _a, T* _b);                
28
                Premise(const Premise<T>& p);
29
                Premise<T>& operator=(const Premise<T>& p);
30
                ~Premise();
31
                
32
                int get_n(){ return n; };
33
                int get_m(){ return m; };
34
                int get_total_valuations(){ return total_valuations; };
35
                T get_a_i(int i);
36
                T get_b_i(int i);
37
                
38
                struct Premise_hash {
39
                        hash <const char*> charhash;
40
                        size_t operator ()(const Premise<T>& p) const {
41
                                stringstream ss;
42
                                string s;
43
                                ss << p.n << " " << p.m << " ";
44
                                for(int i=0; i < p.n; i++)
45
                                        ss << p.a[i] << " ";
46
                                for(int j=0; j < p.m; j++)
47
                                        ss << p.b[j] << " ";
48
                                ss << '\0';
49
                                s = ss.str();
50
                                char buf[s.size()+1];
51
                                for(unsigned int i=0; i < s.size(); i++)
52
                                        buf[i] = s[i];
53
                                buf[s.size()]='\0';
54
                                return charhash(buf);
55
                        }        
56
                };
57
                
58
        struct Premise_equal {         //TODO: this could be improved if we sort them as we input them
59
                bool operator()(const Premise<T>& p1, const Premise<T>& p2) const{
60
                        if(p1.n!=p2.n)
61
                                return false;
62
                        if(p1.m!=p2.m)
63
                                return false;
64
                        for(int i=0; i < p1.n; i++)
65
                                if(p1.a[i]!=p2.a[i])
66
                                        return false;
67
                        for(int j=0; j < p1.m; j++)
68
                                if(p1.b[j]!=p2.b[j])
69
                                        return false;
70
                        return true;
71
                }
72
        };        
73
};
74

    
75

    
76
#endif