Changeset 209 for trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDgenerateRandomSequences.java
- Timestamp:
- 09/28/11 03:03:13 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDgenerateRandomSequences.java
r171 r209 13 13 14 14 /** 15 * <p>Command to generate random sessions.</p> 15 * <p> 16 * Command to generate random sessions. 17 * </p> 18 * 16 19 * @author Steffen Herbold 17 20 * @version 1.0 … … 19 22 public class CMDgenerateRandomSequences implements Command { 20 23 21 /* (non-Javadoc) 24 /* 25 * (non-Javadoc) 26 * 22 27 * @see de.ugoe.cs.util.console.Command#run(java.util.List) 23 28 */ … … 34 39 sequencesName = (String) parameters.get(1); 35 40 numSessions = Integer.parseInt((String) parameters.get(2)); 36 maxIter = numSessions *10;37 if ( parameters.size()>=4) {41 maxIter = numSessions * 10; 42 if (parameters.size() >= 4) { 38 43 maxIter = Long.parseLong((String) parameters.get(3)); 39 44 } 40 if ( parameters.size()>=5) {45 if (parameters.size() >= 5) { 41 46 minLength = Integer.parseInt((String) parameters.get(4)); 42 47 } 43 if ( parameters.size()>=6) {48 if (parameters.size() >= 6) { 44 49 maxLength = Integer.parseInt((String) parameters.get(5)); 45 50 } 46 } 47 catch (Exception e) { 51 } catch (Exception e) { 48 52 throw new InvalidParameterException(); 49 53 } 50 51 IStochasticProcess model = null; 52 Object dataObject = GlobalDataContainer.getInstance().getData(modelname); 53 if( dataObject==null ) { 54 55 IStochasticProcess model = null; 56 Object dataObject = GlobalDataContainer.getInstance() 57 .getData(modelname); 58 if (dataObject == null) { 54 59 Console.println("Model " + modelname + " not found in storage."); 60 return; 55 61 } 56 else if( !(dataObject instanceof IStochasticProcess)) {62 if (!(dataObject instanceof IStochasticProcess)) { 57 63 Console.println("Object " + modelname + " not of type MarkovModel!"); 58 } else { 59 model = (IStochasticProcess) dataObject; 60 Set<List<? extends Event<?>>> sequences = new HashSet<List<? extends Event<?>>>(numSessions); 61 long numIterations = 0; 62 while( sequences.size()<numSessions && numIterations<maxIter ) { 63 List<? extends Event<?>> generatedSequence = model.randomSequence(); 64 if( generatedSequence.size()>=minLength && generatedSequence.size()<=maxLength ) { 65 sequences.add(generatedSequence); 66 } 67 numIterations++; 64 return; 65 } 66 model = (IStochasticProcess) dataObject; 67 Set<List<? extends Event<?>>> sequences = new HashSet<List<? extends Event<?>>>( 68 numSessions); 69 long numIterations = 0; 70 while (sequences.size() < numSessions && numIterations < maxIter) { 71 List<? extends Event<?>> generatedSequence = model.randomSequence(); 72 if (generatedSequence.size() >= minLength 73 && generatedSequence.size() <= maxLength) { 74 sequences.add(generatedSequence); 68 75 } 69 if( sequences.size() < numSessions ) { 70 Console.println("Only " + sequences.size() + " unique sessions generated after " + maxIter + " iterations"); 71 } 72 if( GlobalDataContainer.getInstance().addData(sequencesName, sequences) ) { 73 Console.traceln("Old data \"" + sequencesName + "\" overwritten"); 74 } 76 numIterations++; 77 } 78 if (sequences.size() < numSessions) { 79 Console.println("Only " + sequences.size() 80 + " unique sessions generated after " + maxIter 81 + " iterations"); 82 } 83 if (GlobalDataContainer.getInstance().addData(sequencesName, sequences)) { 84 Console.traceln("Old data \"" + sequencesName + "\" overwritten"); 75 85 } 76 86 } 77 87 78 /* (non-Javadoc) 88 /* 89 * (non-Javadoc) 90 * 79 91 * @see de.ugoe.cs.util.console.Command#help() 80 92 */
Note: See TracChangeset
for help on using the changeset viewer.