Changeset 252 for trunk/EventBenchCore
- Timestamp:
- 10/12/11 22:25:10 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/EventBenchCore/src/de/ugoe/cs/eventbench/models/TrieBasedModel.java
r248 r252 4 4 import java.util.ArrayList; 5 5 import java.util.Collection; 6 import java.util.HashSet; 6 7 import java.util.LinkedHashSet; 7 8 import java.util.LinkedList; … … 104 105 */ 105 106 public void update(Collection<List<Event<?>>> sequences) { 107 if (sequences == null) { 108 return; 109 } 106 110 if (trie == null) { 107 111 trie = new Trie<Event<?>>(); … … 125 129 public List<? extends Event<?>> randomSequence() { 126 130 List<Event<?>> sequence = new LinkedList<Event<?>>(); 127 128 IncompleteMemory<Event<?>> context = new IncompleteMemory<Event<?>>( 129 trieOrder - 1); 130 context.add(Event.STARTEVENT); 131 132 Event<?> currentState = Event.STARTEVENT; 133 134 boolean endFound = false; 135 136 while (!endFound) { 137 double randVal = r.nextDouble(); 138 double probSum = 0.0; 139 List<Event<?>> currentContext = context.getLast(trieOrder); 140 for (Event<?> symbol : trie.getKnownSymbols()) { 141 probSum += getProbability(currentContext, symbol); 142 if (probSum >= randVal) { 143 endFound = (symbol == Event.ENDEVENT); 144 if (!(symbol == Event.STARTEVENT || symbol == Event.ENDEVENT)) { 145 // only add the symbol the sequence if it is not START 146 // or END 147 context.add(symbol); 148 currentState = symbol; 149 sequence.add(currentState); 131 if( trie!=null ) { 132 IncompleteMemory<Event<?>> context = new IncompleteMemory<Event<?>>( 133 trieOrder - 1); 134 context.add(Event.STARTEVENT); 135 136 Event<?> currentState = Event.STARTEVENT; 137 138 boolean endFound = false; 139 140 while (!endFound) { 141 double randVal = r.nextDouble(); 142 double probSum = 0.0; 143 List<Event<?>> currentContext = context.getLast(trieOrder); 144 for (Event<?> symbol : trie.getKnownSymbols()) { 145 probSum += getProbability(currentContext, symbol); 146 if (probSum >= randVal) { 147 endFound = (symbol == Event.ENDEVENT); 148 if (!(symbol == Event.STARTEVENT || symbol == Event.ENDEVENT)) { 149 // only add the symbol the sequence if it is not START 150 // or END 151 context.add(symbol); 152 currentState = symbol; 153 sequence.add(currentState); 154 } 155 break; 150 156 } 151 break;152 157 } 153 158 } … … 164 169 */ 165 170 public String getTrieDotRepresentation() { 166 return trie.getDotRepresentation(); 171 if (trie == null) { 172 return ""; 173 } else { 174 return trie.getDotRepresentation(); 175 } 167 176 } 168 177 … … 176 185 */ 177 186 public Tree<TrieVertex, Edge> getTrieGraph() { 178 return trie.getGraph(); 187 if (trie == null) { 188 return null; 189 } else { 190 return trie.getGraph(); 191 } 179 192 } 180 193 … … 189 202 @Override 190 203 public String toString() { 191 return trie.toString(); 204 if (trie == null) { 205 return ""; 206 } else { 207 return trie.toString(); 208 } 192 209 } 193 210 … … 199 216 @Override 200 217 public int getNumSymbols() { 201 return trie.getNumSymbols(); 218 if (trie == null) { 219 return 0; 220 } else { 221 return trie.getNumSymbols(); 222 } 202 223 } 203 224 … … 209 230 @Override 210 231 public String[] getSymbolStrings() { 232 if (trie == null) { 233 return new String[0]; 234 } 211 235 String[] stateStrings = new String[getNumSymbols()]; 212 236 int i = 0; … … 225 249 @Override 226 250 public Collection<? extends Event<?>> getEvents() { 227 return trie.getKnownSymbols(); 251 if (trie == null) { 252 return new HashSet<Event<?>>(); 253 } else { 254 return trie.getKnownSymbols(); 255 } 228 256 } 229 257 … … 334 362 @Override 335 363 public int getNumFOMStates() { 336 return trie.getNumLeafAncestors(); 364 if (trie == null) { 365 return 0; 366 } else { 367 return trie.getNumLeafAncestors(); 368 } 337 369 } 338 370 … … 344 376 @Override 345 377 public int getNumTransitions() { 346 return trie.getNumLeafs(); 378 if (trie == null) { 379 return 0; 380 } else { 381 return trie.getNumLeafs(); 382 } 347 383 } 348 384 }
Note: See TracChangeset
for help on using the changeset viewer.