Changeset 524 for trunk/quest-ui-core/src/main/java/de/ugoe/cs/quest/ui/commands/CMDgenerateFixedLengthSequences.java
- Timestamp:
- 08/01/12 11:28:16 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/quest-ui-core/src/main/java/de/ugoe/cs/quest/ui/commands/CMDgenerateFixedLengthSequences.java
r434 r524 2 2 3 3 import java.security.InvalidParameterException; 4 import java.util.ArrayList;5 4 import java.util.Collection; 6 import java.util.HashSet;7 import java.util.LinkedHashSet;8 import java.util.LinkedList;9 5 import java.util.List; 10 import java.util.Random;11 import java.util.Set;12 6 13 7 import de.ugoe.cs.quest.CommandHelpers; 14 8 import de.ugoe.cs.quest.eventcore.Event; 9 import de.ugoe.cs.quest.testgeneration.DrawFromAllSequencesGenerator; 15 10 import de.ugoe.cs.quest.ui.GlobalDataContainer; 16 11 import de.ugoe.cs.quest.usageprofiles.IStochasticProcess; … … 71 66 } 72 67 model = (IStochasticProcess) dataObject; 73 Collection<List<? extends Event<?>>> sequences = new LinkedHashSet<List<? extends Event<?>>>(); 74 for (int length = minLength; length <= maxLength; length++) { 75 if( validEnd ) { 76 sequences.addAll(model.generateValidSequences(length + 2)); 77 } else { 78 sequences.addAll(model.generateSequences(length + 1, true)); 79 } 80 } 81 Console.traceln("" + sequences.size() + " possible"); 82 if (!all && numSequences < sequences.size()) { 83 List<Double> probabilities = new ArrayList<Double>(sequences.size()); 84 double probSum = 0.0; 85 for (List<? extends Event<?>> sequence : sequences) { 86 double prob = model.getProbability(sequence); 87 probabilities.add(prob); 88 probSum += prob; 89 } 90 Set<Integer> drawnSequences = new HashSet<Integer>(numSequences); 91 Random r = new Random(); 92 while (drawnSequences.size() < numSequences) { 93 double randVal = r.nextDouble() * probSum; 94 double sum = 0.0d; 95 int index = -1; 96 while (sum < randVal) { 97 index++; 98 double currentProb = probabilities.get(index); 99 sum += currentProb; 100 } 101 if (!drawnSequences.contains(index)) { 102 drawnSequences.add(index); 103 probSum -= probabilities.get(index); 104 probabilities.set(index, 0.0d); 105 } 106 } 107 Collection<List<? extends Event<?>>> retainedSequences = new LinkedList<List<? extends Event<?>>>(); 108 int index = 0; 109 for (List<? extends Event<?>> sequence : sequences) { 110 if (drawnSequences.contains(index)) { 111 retainedSequences.add(sequence); 112 } 113 index++; 114 } 115 sequences = retainedSequences; 116 } 68 DrawFromAllSequencesGenerator generator = new DrawFromAllSequencesGenerator( 69 numSequences, minLength, maxLength, validEnd, all); 70 Collection<List<? extends Event<?>>> sequences = generator 71 .generateTestSuite(model); 72 117 73 if (GlobalDataContainer.getInstance().addData(sequencesName, sequences)) { 118 74 CommandHelpers.dataOverwritten(sequencesName);
Note: See TracChangeset
for help on using the changeset viewer.