Changeset 294 for trunk/EventBenchConsole/src/de
- Timestamp:
- 12/12/11 13:52:31 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDgenerateGreedy.java
r293 r294 21 21 /** 22 22 * <p> 23 * Command to generate test suite with a greedy strategy to achieve a desired coverage. 23 * Command to generate test suite with a greedy strategy to achieve a desired 24 * coverage. 24 25 * </p> 26 * 25 27 * @author Steffen Herbold 26 28 * @version 1.0 27 29 */ 28 30 public class CMDgenerateGreedy implements Command { 29 31 32 /** 33 * <p> 34 * Tolerance for double comparisons 35 * </p> 36 */ 30 37 final double eps = 0.000000000001; 31 38 39 /* 40 * (non-Javadoc) 41 * 42 * @see de.ugoe.cs.util.console.Command#run(java.util.List) 43 */ 32 44 @Override 33 45 public void run(List<Object> parameters) { … … 60 72 } 61 73 model = (IStochasticProcess) dataObject; 62 74 63 75 // set up everything 64 76 List<List<? extends Event<?>>> allSequences = new ArrayList<List<? extends Event<?>>>(); … … 67 79 } 68 80 Console.traceln("" + allSequences.size() + " possible"); 69 70 Set<List<? extends Event<?>>> allSubSeqs = SequenceTools.containedSubSequences(allSequences, coverageDepth); 71 Map<List<? extends Event<?>>, Double> weightMap = SequenceTools.generateWeights(model, allSubSeqs); 81 82 Set<List<? extends Event<?>>> allSubSeqs = SequenceTools 83 .containedSubSequences(allSequences, coverageDepth); 84 Map<List<? extends Event<?>>, Double> weightMap = SequenceTools 85 .generateWeights(model, allSubSeqs); 72 86 Set<List<? extends Event<?>>> coveredSubSeqs = new LinkedHashSet<List<? extends Event<?>>>(); 73 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<?>>>(); 87 88 List<Set<List<? extends Event<?>>>> containedSubSeqs = new ArrayList<Set<List<? extends Event<?>>>>( 89 allSequences.size()); 90 for (List<? extends Event<?>> sequence : allSequences) { 91 List<List<? extends Event<?>>> wrapper = new LinkedList<List<? extends Event<?>>>(); 77 92 wrapper.add(sequence); 78 Set<List<? extends Event<?>>> currentSubSeqs = SequenceTools.containedSubSequences(wrapper, coverageDepth); 93 Set<List<? extends Event<?>>> currentSubSeqs = SequenceTools 94 .containedSubSequences(wrapper, coverageDepth); 79 95 containedSubSeqs.add(currentSubSeqs); 80 96 } 81 97 82 98 Double[] sequenceGain = new Double[allSequences.size()]; 83 99 List<List<? extends Event<?>>> testSuite = new LinkedList<List<? extends Event<?>>>(); 84 CoverageCalculatorProcess coverageCalculator = new CoverageCalculatorProcess(model, testSuite, coverageDepth); 100 CoverageCalculatorProcess coverageCalculator = new CoverageCalculatorProcess( 101 model, testSuite, coverageDepth); 85 102 double currentCoverage = 0.0d; 86 103 87 104 // Build test suite 88 while ( currentCoverage<desiredCoverage) {89 for ( int i=0 ; i<allSequences.size() ; i++) {105 while (currentCoverage < desiredCoverage) { 106 for (int i = 0; i < allSequences.size(); i++) { 90 107 double gain = 0.0d; 91 for ( List<? extends Event<?>> subSeq : containedSubSeqs.get(i)) {92 if ( !coveredSubSeqs.contains(subSeq)) {108 for (List<? extends Event<?>> subSeq : containedSubSeqs.get(i)) { 109 if (!coveredSubSeqs.contains(subSeq)) { 93 110 gain += weightMap.get(subSeq); 94 111 } … … 97 114 } 98 115 int maxIndex = ArrayTools.findMax(sequenceGain); 99 if ( sequenceGain[maxIndex] <= 0.0+eps) {116 if (sequenceGain[maxIndex] <= 0.0 + eps) { 100 117 Console.traceln("No gain anymore! Desired coverage cannot be satisfied!"); 101 118 break; … … 106 123 currentCoverage = coverageCalculator.getCoveragePossibleWeight(); 107 124 } 108 125 109 126 if (GlobalDataContainer.getInstance().addData(sequencesName, testSuite)) { 110 127 CommandHelpers.dataOverwritten(sequencesName); … … 114 131 } 115 132 133 /* 134 * (non-Javadoc) 135 * 136 * @see de.ugoe.cs.util.console.Command#help() 137 */ 116 138 @Override 117 139 public void help() {
Note: See TracChangeset
for help on using the changeset viewer.