Changeset 293 for trunk/EventBenchConsole
- Timestamp:
- 12/12/11 11:52:35 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDgenerateGreedy.java
r288 r293 2 2 3 3 import java.security.InvalidParameterException; 4 import java.util. Collection;4 import java.util.ArrayList; 5 5 import java.util.LinkedHashSet; 6 import java.util.LinkedList; 6 7 import java.util.List; 8 import java.util.Map; 9 import java.util.Set; 7 10 8 11 import de.ugoe.cs.eventbench.CommandHelpers; 12 import de.ugoe.cs.eventbench.coverage.CoverageCalculatorProcess; 13 import de.ugoe.cs.eventbench.coverage.SequenceTools; 9 14 import de.ugoe.cs.eventbench.data.Event; 10 15 import de.ugoe.cs.eventbench.data.GlobalDataContainer; 11 16 import de.ugoe.cs.eventbench.models.IStochasticProcess; 17 import de.ugoe.cs.util.ArrayTools; 12 18 import de.ugoe.cs.util.console.Command; 13 19 import de.ugoe.cs.util.console.Console; … … 21 27 */ 22 28 public class CMDgenerateGreedy implements Command { 29 30 final double eps = 0.000000000001; 23 31 24 32 @Override … … 28 36 int minLength; 29 37 int maxLength; 38 int coverageDepth; 30 39 float desiredCoverage; 31 40 try { … … 34 43 minLength = Integer.parseInt((String) parameters.get(2)); 35 44 maxLength = Integer.parseInt((String) parameters.get(3)); 36 desiredCoverage = Float.parseFloat((String) parameters.get(4)); 45 coverageDepth = Integer.parseInt((String) parameters.get(4)); 46 desiredCoverage = Float.parseFloat((String) parameters.get(5)); 37 47 } catch (Exception e) { 38 48 throw new InvalidParameterException(); … … 50 60 } 51 61 model = (IStochasticProcess) dataObject; 52 Collection<List<? extends Event<?>>> sequences = new LinkedHashSet<List<? extends Event<?>>>(); 62 63 // set up everything 64 List<List<? extends Event<?>>> allSequences = new ArrayList<List<? extends Event<?>>>(); 53 65 for (int length = minLength; length <= maxLength; length++) { 54 sequences.addAll(model.generateValidSequences(length + 2));66 allSequences.addAll(model.generateValidSequences(length + 2)); 55 67 } 56 Console.traceln("" + sequences.size() + " possible");68 Console.traceln("" + allSequences.size() + " possible"); 57 69 70 Set<List<? extends Event<?>>> allSubSeqs = SequenceTools.containedSubSequences(allSequences, coverageDepth); 71 Map<List<? extends Event<?>>, Double> weightMap = SequenceTools.generateWeights(model, allSubSeqs); 72 Set<List<? extends Event<?>>> coveredSubSeqs = new LinkedHashSet<List<? extends Event<?>>>(); 58 73 59 // TODO implement sequence selection 74 List<Set<List<? extends Event<?>>>> containedSubSeqs = new ArrayList<Set<List<? extends Event<?>>>>(allSequences.size()); 75 for( List<? extends Event<?>> sequence : allSequences ) { 76 List<List<? extends Event<?>>> wrapper = new LinkedList<List<? extends Event<?>>>(); 77 wrapper.add(sequence); 78 Set<List<? extends Event<?>>> currentSubSeqs = SequenceTools.containedSubSequences(wrapper, coverageDepth); 79 containedSubSeqs.add(currentSubSeqs); 80 } 60 81 61 if (GlobalDataContainer.getInstance().addData(sequencesName, sequences)) { 82 Double[] sequenceGain = new Double[allSequences.size()]; 83 List<List<? extends Event<?>>> testSuite = new LinkedList<List<? extends Event<?>>>(); 84 CoverageCalculatorProcess coverageCalculator = new CoverageCalculatorProcess(model, testSuite, coverageDepth); 85 double currentCoverage = 0.0d; 86 87 // Build test suite 88 while( currentCoverage<desiredCoverage ) { 89 for( int i=0 ; i<allSequences.size() ; i++ ) { 90 double gain = 0.0d; 91 for( List<? extends Event<?>> subSeq : containedSubSeqs.get(i) ) { 92 if( !coveredSubSeqs.contains(subSeq) ) { 93 gain += weightMap.get(subSeq); 94 } 95 } 96 sequenceGain[i] = gain; 97 } 98 int maxIndex = ArrayTools.findMax(sequenceGain); 99 if( sequenceGain[maxIndex] <= 0.0+eps ) { 100 Console.traceln("No gain anymore! Desired coverage cannot be satisfied!"); 101 break; 102 } 103 testSuite.add(allSequences.get(maxIndex)); 104 coveredSubSeqs.addAll(containedSubSeqs.get(maxIndex)); 105 coverageCalculator.setSequences(testSuite); 106 currentCoverage = coverageCalculator.getCoveragePossibleWeight(); 107 } 108 109 if (GlobalDataContainer.getInstance().addData(sequencesName, testSuite)) { 62 110 CommandHelpers.dataOverwritten(sequencesName); 63 111 } 64 Console.println("" + sequences.size() + " sequences generated"); 112 Console.println("" + testSuite.size() + " sequences generated"); 113 Console.println("" + currentCoverage + " coverage achieved"); 65 114 } 66 115 67 116 @Override 68 117 public void help() { 69 Console.println("generateGreedy <modelname> <sequencesName> <minLength> <maxLength> < desiredCoverage>");118 Console.println("generateGreedy <modelname> <sequencesName> <minLength> <maxLength> <coverageDepth> <desiredCoverage>"); 70 119 } 71 120
Note: See TracChangeset
for help on using the changeset viewer.