Changeset 386
- Timestamp:
- 02/20/12 11:40:29 (13 years ago)
- Location:
- trunk/EventBenchCore/src/de/ugoe/cs/eventbench/models
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/EventBenchCore/src/de/ugoe/cs/eventbench/models/IStochasticProcess.java
r342 r386 59 59 */ 60 60 public List<? extends Event<?>> randomSequence(); 61 62 /** 63 * <p> 64 * Generates a random sequence of events. The sequence starts with 65 * {@link Event#STARTEVENT} and finishes with 66 * <ul> 67 * <li>{@link Event#ENDEVENT} if validEnd==true.</li> 68 * <li>b) if a generated sequences reaches {@link Event#ENDEVENT} before 69 * maxLength, the sequence finishes and is shorter than maxLenght. 70 * Otherwise, the sequence finishes as soon as maxLength is reached and the 71 * final event of the sequence must not be {@link Event#ENDEVENT}.</li> 72 * </ul> 73 * </p> 74 * 75 * @param maxLength 76 * maximum length of the generated sequence 77 * @param validEnd 78 * if true, only sequences that finish with 79 * {@link Event#ENDEVENT} are generated 80 * @return randomly generated sequence 81 * 82 */ 83 public List<? extends Event<?>> randomSequence(int maxLength, 84 boolean validEnd); 61 85 62 86 /** -
trunk/EventBenchCore/src/de/ugoe/cs/eventbench/models/TrieBasedModel.java
r342 r386 143 143 @Override 144 144 public List<? extends Event<?>> randomSequence() { 145 return randomSequence(Integer.MAX_VALUE, true); 146 } 147 148 /* 149 * (non-Javadoc) 150 * 151 * @see de.ugoe.cs.eventbench.models.IStochasticProcess#randomSequence() 152 */ 153 @Override 154 public List<? extends Event<?>> randomSequence(int maxLength, 155 boolean validEnd) { 145 156 List<Event<?>> sequence = new LinkedList<Event<?>>(); 146 157 if (trie != null) { 147 IncompleteMemory<Event<?>> context = new IncompleteMemory<Event<?>>(148 trieOrder - 1);149 context.add(Event.STARTEVENT);150 151 Event<?> currentState = Event.STARTEVENT;152 153 158 boolean endFound = false; 154 155 while (!endFound) { 156 double randVal = r.nextDouble(); 157 double probSum = 0.0; 158 List<Event<?>> currentContext = context.getLast(trieOrder); 159 for (Event<?> symbol : trie.getKnownSymbols()) { 160 probSum += getProbability(currentContext, symbol); 161 if (probSum >= randVal) { 162 endFound = (symbol == Event.ENDEVENT); 163 if (!(symbol == Event.STARTEVENT || symbol == Event.ENDEVENT)) { 164 // only add the symbol the sequence if it is not 165 // START 166 // or END 167 context.add(symbol); 168 currentState = symbol; 169 sequence.add(currentState); 159 while (!endFound) { // outer loop for length checking 160 sequence = new LinkedList<Event<?>>(); 161 IncompleteMemory<Event<?>> context = new IncompleteMemory<Event<?>>( 162 trieOrder - 1); 163 context.add(Event.STARTEVENT); 164 165 Event<?> currentState = Event.STARTEVENT; 166 167 while (!endFound && sequence.size() < maxLength) { 168 double randVal = r.nextDouble(); 169 double probSum = 0.0; 170 List<Event<?>> currentContext = context.getLast(trieOrder); 171 for (Event<?> symbol : trie.getKnownSymbols()) { 172 probSum += getProbability(currentContext, symbol); 173 if (probSum >= randVal) { 174 if (!(symbol == Event.STARTEVENT || symbol == Event.ENDEVENT)) { 175 // only add the symbol the sequence if it is not 176 // START or END 177 context.add(symbol); 178 currentState = symbol; 179 sequence.add(currentState); 180 } 181 endFound = (symbol == Event.ENDEVENT) 182 || (!validEnd && sequence.size() == maxLength); 183 break; 170 184 } 171 break;172 185 } 173 186 } … … 252 265 int i = 0; 253 266 for (Event<?> symbol : trie.getKnownSymbols()) { 254 stateStrings[i] = symbol.toString(); 267 if (symbol.toString() == null) { 268 stateStrings[i] = "null"; 269 } else { 270 stateStrings[i] = symbol.toString(); 271 } 255 272 i++; 256 273 }
Note: See TracChangeset
for help on using the changeset viewer.