Changeset 524 for trunk/quest-ui-core
- Timestamp:
- 08/01/12 11:28:16 (12 years ago)
- Location:
- trunk/quest-ui-core
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/quest-ui-core/pom.xml
r520 r524 46 46 </dependency> 47 47 <dependency> 48 <groupId>de.ugoe.cs.quest</groupId> 49 <artifactId>quest-core-testgeneration</artifactId> 50 <version>0.0.1-SNAPSHOT</version> 51 </dependency> 52 <dependency> 48 53 <groupId>net.sf.jung</groupId> 49 54 <artifactId>jung-visualization</artifactId> -
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); -
trunk/quest-ui-core/src/main/java/de/ugoe/cs/quest/ui/commands/CMDgenerateHybrid.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.LinkedHashSet;7 5 import java.util.LinkedList; 8 6 import java.util.List; 9 import java.util.Random;10 7 11 8 import de.ugoe.cs.quest.CommandHelpers; 12 9 import de.ugoe.cs.quest.eventcore.Event; 10 import de.ugoe.cs.quest.testgeneration.HybridGenerator; 13 11 import de.ugoe.cs.quest.ui.GlobalDataContainer; 14 12 import de.ugoe.cs.quest.usageprofiles.IStochasticProcess; … … 78 76 } 79 77 model = (IStochasticProcess) dataObject; 80 Collection<List<? extends Event<?>>> sequences = new LinkedHashSet<List<? extends Event<?>>>(); 81 82 List<List<? extends Event<?>>> seqsTmp = new ArrayList<List<? extends Event<?>>>( 83 model.generateSequences(maxLengthAll + 1, true)); 84 85 Console.traceln("" + seqsTmp.size() + " of length " + maxLengthAll 86 + " possible"); 87 List<Double> probabilities = new ArrayList<Double>(seqsTmp.size()); 88 double probSum = 0.0; 89 for (List<? extends Event<?>> sequence : seqsTmp) { 90 double prob = model.getProbability(sequence); 91 probabilities.add(prob); 92 probSum += prob; 93 } 94 95 Random r = new Random(); 96 int j = 0; 97 while (sequences.size() < numSequences && j <= numSequences * 100) { 98 j++; 99 double randVal = r.nextDouble() * probSum; 100 double sum = 0.0d; 101 int index = -1; 102 while (sum < randVal) { 103 index++; 104 double currentProb = probabilities.get(index); 105 sum += currentProb; 106 } 107 List<? extends Event<?>> seqTmp = seqsTmp.get(index); 108 if (!Event.ENDEVENT.equals(seqTmp.get(seqTmp.size() - 1))) { 109 List<? extends Event<?>> sequence; 110 if (validEnd) { 111 sequence = finishSequence(seqTmp, model, length + 2, 112 validEnd); 113 if( sequence!= null && sequence.size()!=length+2 ) { 114 sequence = null; 115 } 116 } else { 117 sequence = finishSequence(seqTmp, model, length + 1, 118 validEnd); 119 if( sequence!= null && sequence.size()!=length+1 ) { 120 sequence = null; 121 } 122 } 123 if( sequence!=null ) { 124 sequences.add(sequence); 125 } 126 } 127 } 78 79 HybridGenerator generator = new HybridGenerator(numSequences, length, maxLengthAll, validEnd); 80 Collection<List<? extends Event<?>>> sequences = generator.generateTestSuite(model); 81 128 82 if (GlobalDataContainer.getInstance().addData(sequencesName, sequences)) { 129 83 CommandHelpers.dataOverwritten(sequencesName); 130 84 } 131 85 Console.println("" + sequences.size() + " sequences generated"); 132 }133 134 public List<? extends Event<?>> finishSequence(135 List<? extends Event<?>> sequence, IStochasticProcess model,136 int maxLength, boolean validEnd) {137 Random r = new Random();138 boolean endFound = false;139 List<Event<?>> sequenceCopy = new LinkedList<Event<?>>(sequence);140 final int maxIter = 30000;141 int iter = 0;142 while (!endFound && iter<maxIter) {143 iter++;144 sequenceCopy = new LinkedList<Event<?>>(sequence);145 while (!endFound && sequenceCopy.size() <= maxLength) {146 double randVal = r.nextDouble();147 double probSum = 0.0;148 for (Event<?> symbol : model.getEvents()) {149 probSum += model.getProbability(sequenceCopy, symbol);150 if (probSum >= randVal) {151 if (!(Event.STARTEVENT.equals(symbol) || (!validEnd && Event.ENDEVENT.equals(symbol)))) {152 // only add the symbol the sequence if it is not153 // START154 // or END155 sequenceCopy.add(symbol);156 }157 endFound = Event.ENDEVENT.equals(symbol)158 || (!validEnd && sequenceCopy.size() == maxLength);159 break;160 }161 }162 }163 }164 if( iter==maxIter ) {165 return null;166 }167 return sequenceCopy;168 86 } 169 87 -
trunk/quest-ui-core/src/main/java/de/ugoe/cs/quest/ui/commands/CMDgenerateRandomSequences.java
r434 r524 2 2 3 3 import java.security.InvalidParameterException; 4 import java.util. HashSet;4 import java.util.Collection; 5 5 import java.util.List; 6 import java.util.Set;7 6 8 7 import de.ugoe.cs.quest.CommandHelpers; 9 8 import de.ugoe.cs.quest.eventcore.Event; 9 import de.ugoe.cs.quest.testgeneration.RandomWalkGenerator; 10 10 import de.ugoe.cs.quest.ui.GlobalDataContainer; 11 11 import de.ugoe.cs.quest.usageprofiles.IStochasticProcess; … … 28 28 * @see de.ugoe.cs.util.console.Command#run(java.util.List) 29 29 */ 30 @SuppressWarnings("unchecked")31 30 @Override 32 31 public void run(List<Object> parameters) { … … 67 66 } 68 67 model = (IStochasticProcess) dataObject; 69 Set<List<? extends Event<?>>> sequences = new HashSet<List<? extends Event<?>>>( 70 numSessions); 71 long numIterations = 0; 72 while (sequences.size() < numSessions && numIterations < maxIter) { 73 List<? extends Event<?>> generatedSequence = model.randomSequence( 74 maxLength, validEnd); 75 if (generatedSequence.size() >= minLength 76 && generatedSequence.size() <= maxLength) { 77 ((List<Event<?>>) generatedSequence).add(0, Event.STARTEVENT); 78 if( validEnd ) { 79 ((List<Event<?>>) generatedSequence).add(Event.ENDEVENT); 80 } 81 sequences.add(generatedSequence); 82 } 83 numIterations++; 84 } 68 69 RandomWalkGenerator generator = new RandomWalkGenerator(numSessions, 70 minLength, maxLength, validEnd, maxIter); 71 Collection<List<? extends Event<?>>> sequences = generator 72 .generateTestSuite(model); 73 85 74 if (sequences.size() < numSessions) { 86 75 Console.println("Only " + sequences.size() … … 88 77 + " iterations"); 89 78 } 79 90 80 if (GlobalDataContainer.getInstance().addData(sequencesName, sequences)) { 91 81 CommandHelpers.dataOverwritten(sequencesName);
Note: See TracChangeset
for help on using the changeset viewer.