Ignore:
Timestamp:
08/01/12 11:28:16 (12 years ago)
Author:
sherbold
Message:
  • the commands generateFixedLengthSequences, generateHybrid, and generateRandomSequences now quest-core-testgeneration for the generation of test suites instead of local implementations.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/quest-ui-core/src/main/java/de/ugoe/cs/quest/ui/commands/CMDgenerateFixedLengthSequences.java

    r434 r524  
    22 
    33import java.security.InvalidParameterException; 
    4 import java.util.ArrayList; 
    54import java.util.Collection; 
    6 import java.util.HashSet; 
    7 import java.util.LinkedHashSet; 
    8 import java.util.LinkedList; 
    95import java.util.List; 
    10 import java.util.Random; 
    11 import java.util.Set; 
    126 
    137import de.ugoe.cs.quest.CommandHelpers; 
    148import de.ugoe.cs.quest.eventcore.Event; 
     9import de.ugoe.cs.quest.testgeneration.DrawFromAllSequencesGenerator; 
    1510import de.ugoe.cs.quest.ui.GlobalDataContainer; 
    1611import de.ugoe.cs.quest.usageprofiles.IStochasticProcess; 
     
    7166                } 
    7267                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 
    11773                if (GlobalDataContainer.getInstance().addData(sequencesName, sequences)) { 
    11874                        CommandHelpers.dataOverwritten(sequencesName); 
Note: See TracChangeset for help on using the changeset viewer.