| 1 | #ifndef _SGRAPH_HH | 
|---|
| 2 | #define _SGRAPH_HH | 
|---|
| 3 |  | 
|---|
| 4 | #include <stdio.h> | 
|---|
| 5 |  | 
|---|
| 6 | #include <list> | 
|---|
| 7 | #include <vector> | 
|---|
| 8 | #include <bitset> | 
|---|
| 9 |  | 
|---|
| 10 | #include "const.hh" | 
|---|
| 11 | #include "thesymbols.hh" | 
|---|
| 12 |  | 
|---|
| 13 |  | 
|---|
| 14 | class MNode; | 
|---|
| 15 |  | 
|---|
| 16 |  | 
|---|
| 17 | struct Arc | 
|---|
| 18 | { | 
|---|
| 19 |   int dst; | 
|---|
| 20 |   Role role; | 
|---|
| 21 |   int anc; | 
|---|
| 22 |   | 
|---|
| 23 |   Arc(int d, Role r, int a) : dst(d), role(r), anc(a) {}; | 
|---|
| 24 |  }; | 
|---|
| 25 |  | 
|---|
| 26 |  | 
|---|
| 27 | struct NodeProp | 
|---|
| 28 | { | 
|---|
| 29 |   bitset<MAXTYPES> required; | 
|---|
| 30 |   bitset<MAXTYPES> forbidden; | 
|---|
| 31 |  | 
|---|
| 32 |   bool operator==(const NodeProp& p) | 
|---|
| 33 |   { return required==p.required && forbidden==p.forbidden; } | 
|---|
| 34 |  | 
|---|
| 35 |   void clear() | 
|---|
| 36 |   { required.reset(), forbidden.reset(); } | 
|---|
| 37 |  | 
|---|
| 38 | }; | 
|---|
| 39 |  | 
|---|
| 40 |  | 
|---|
| 41 | struct SNode | 
|---|
| 42 | { | 
|---|
| 43 |    | 
|---|
| 44 |   MNode* mnode; | 
|---|
| 45 |  | 
|---|
| 46 |   NodeProp prop; | 
|---|
| 47 |  | 
|---|
| 48 |   bitset<MAXNODES> LV; | 
|---|
| 49 |   bitset<MAXNODES> LH; | 
|---|
| 50 |   bitset<MAXNODES> LD; | 
|---|
| 51 |   bool in_LH; | 
|---|
| 52 |  | 
|---|
| 53 |   vector<Arc> heads; | 
|---|
| 54 |   vector<Arc> deps; | 
|---|
| 55 |  | 
|---|
| 56 |   void clear()      { prop.clear(), LV.reset(), LD.reset(), LH.reset(), heads.clear(), deps.clear(); } | 
|---|
| 57 |   bool saturated()  { return prop.required.none(); } | 
|---|
| 58 | }; | 
|---|
| 59 |  | 
|---|
| 60 |  | 
|---|
| 61 |  | 
|---|
| 62 | class SGraph | 
|---|
| 63 | { | 
|---|
| 64 | public: | 
|---|
| 65 |  | 
|---|
| 66 |   SNode nodes[MAXNODES]; | 
|---|
| 67 |   int n; // number of nodes | 
|---|
| 68 |  | 
|---|
| 69 |   enum Output { HEADS=1, DEPS=2, SETS=4, CONSTRAINTS=8 }; | 
|---|
| 70 |  | 
|---|
| 71 |   SGraph() : n(0) {} | 
|---|
| 72 |  | 
|---|
| 73 |   void clear() { n=0; } | 
|---|
| 74 |   | 
|---|
| 75 |   int add_base_snode(MNode* mn); | 
|---|
| 76 |   int clone(int ancind, NodeProp newprop); | 
|---|
| 77 |   void update_left(int headind, int depind); | 
|---|
| 78 |   void update_right(int headind, int depind); | 
|---|
| 79 |  | 
|---|
| 80 |   bool visible(int left, int right); | 
|---|
| 81 |   bool saturated(int node); | 
|---|
| 82 |  | 
|---|
| 83 |   //-------------------------------------------------------------------- | 
|---|
| 84 |  | 
|---|
| 85 |   void read(FILE* f); | 
|---|
| 86 |   void write(FILE* f, list<int> nodelist, unsigned int info); | 
|---|
| 87 |  | 
|---|
| 88 |   int sprint_node(char* buf, int n, unsigned int info); | 
|---|
| 89 |   int print_node(FILE* f, int n, unsigned int info); | 
|---|
| 90 |   int sprint_node_debug(char* buf, const char* pref, int n); | 
|---|
| 91 |   int print_node_debug(FILE* f, const char* pref, int n); | 
|---|
| 92 |  | 
|---|
| 93 |   void print_arc(FILE* f, int left, int right, Role role, int dir); // 0 - left, 1 - right | 
|---|
| 94 |  | 
|---|
| 95 | }; | 
|---|
| 96 |  | 
|---|
| 97 |  | 
|---|
| 98 | inline bool SGraph::visible(int left, int right) | 
|---|
| 99 | { | 
|---|
| 100 |   return nodes[right].LV[left]; | 
|---|
| 101 | } | 
|---|
| 102 |  | 
|---|
| 103 | inline bool SGraph::saturated(int node) | 
|---|
| 104 | { | 
|---|
| 105 |   return nodes[node].saturated(); | 
|---|
| 106 | } | 
|---|
| 107 |  | 
|---|
| 108 | #endif | 
|---|