| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
#ifndef TBRANCHINGCONTEXT_H |
| 21 |
#define TBRANCHINGCONTEXT_H |
| 22 |
|
| 23 |
#include "ConceptWithDep.h" |
| 24 |
|
| 25 |
class DlCompletionTree; |
| 26 |
|
| 27 |
|
| 28 |
class BranchingContext |
| 29 |
{ |
| 30 |
public: |
| 31 |
|
| 32 |
DlCompletionTree* curNode = nullptr; |
| 33 |
|
| 34 |
ConceptWDep curConcept {bpINVALID}; |
| 35 |
|
| 36 |
size_t pUsedIndex = 0, nUsedIndex = 0; |
| 37 |
|
| 38 |
size_t SGsize = 0; |
| 39 |
|
| 40 |
DepSet branchDep; |
| 41 |
|
| 42 |
public: |
| 43 |
|
| 44 |
BranchingContext() = default; |
| 45 |
|
| 46 |
BranchingContext ( const BranchingContext& ) = delete; |
| 47 |
|
| 48 |
BranchingContext& operator = ( const BranchingContext& ) = delete; |
| 49 |
|
| 50 |
virtual ~BranchingContext() = default; |
| 51 |
|
| 52 |
|
| 53 |
virtual void init ( void ) {} |
| 54 |
|
| 55 |
virtual void nextOption ( void ) {} |
| 56 |
}; |
| 57 |
|
| 58 |
|
| 59 |
class BCOr: public BranchingContext |
| 60 |
{ |
| 61 |
public: |
| 62 |
|
| 63 |
typedef std::vector<BipolarPointer> OrIndex; |
| 64 |
|
| 65 |
typedef OrIndex::const_iterator or_iterator; |
| 66 |
|
| 67 |
public: |
| 68 |
|
| 69 |
OrIndex applicableOrEntries; |
| 70 |
|
| 71 |
size_t branchIndex = 0; |
| 72 |
|
| 73 |
public: |
| 74 |
|
| 75 |
void init ( void ) override { branchIndex = 0; } |
| 76 |
|
| 77 |
void nextOption ( void ) override { ++branchIndex; } |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
bool isLastOrEntry ( void ) const { return applicableOrEntries.size() == branchIndex+1; } |
| 83 |
|
| 84 |
or_iterator orBeg ( void ) const { return applicableOrEntries.begin(); } |
| 85 |
|
| 86 |
or_iterator orCur ( void ) const { return orBeg() + branchIndex; } |
| 87 |
}; |
| 88 |
|
| 89 |
|
| 90 |
class BCChoose: public BranchingContext |
| 91 |
{ |
| 92 |
}; |
| 93 |
|
| 94 |
|
| 95 |
class BCNN: public BranchingContext |
| 96 |
{ |
| 97 |
public: |
| 98 |
|
| 99 |
unsigned int value = 0; |
| 100 |
|
| 101 |
public: |
| 102 |
|
| 103 |
void init ( void ) override { value = 1; } |
| 104 |
|
| 105 |
void nextOption ( void ) override { ++value; } |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
bool noMoreNNOptions ( unsigned int n ) const { return value > n; } |
| 111 |
}; |
| 112 |
|
| 113 |
|
| 114 |
template <typename T> |
| 115 |
class BCLE: public BranchingContext |
| 116 |
{ |
| 117 |
public: |
| 118 |
|
| 119 |
|
| 120 |
typedef unsigned short int CRIndex; |
| 121 |
|
| 122 |
typedef std::vector<T*> EdgeVector; |
| 123 |
|
| 124 |
public: |
| 125 |
|
| 126 |
EdgeVector ItemsToMerge; |
| 127 |
|
| 128 |
CRIndex toIndex = 0; |
| 129 |
|
| 130 |
CRIndex fromIndex = 0; |
| 131 |
|
| 132 |
public: |
| 133 |
|
| 134 |
void init ( void ) override |
| 135 |
{ |
| 136 |
toIndex = 0; |
| 137 |
fromIndex = 0; |
| 138 |
} |
| 139 |
|
| 140 |
void resetMCI ( void ) { fromIndex = static_cast<CRIndex>(ItemsToMerge.size() - 1); } |
| 141 |
|
| 142 |
void nextOption ( void ) override |
| 143 |
{ |
| 144 |
--fromIndex; |
| 145 |
if ( fromIndex == toIndex ) |
| 146 |
{ |
| 147 |
++toIndex; |
| 148 |
resetMCI(); |
| 149 |
} |
| 150 |
} |
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
T* getFrom ( void ) const { return ItemsToMerge[fromIndex]; } |
| 156 |
|
| 157 |
T* getTo ( void ) const { return ItemsToMerge[toIndex]; } |
| 158 |
|
| 159 |
bool noMoreLEOptions ( void ) const { return fromIndex <= toIndex; } |
| 160 |
}; |
| 161 |
|
| 162 |
|
| 163 |
class BCBarrier: public BranchingContext |
| 164 |
{ |
| 165 |
}; |
| 166 |
|
| 167 |
#endif |