source: trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDgenerateRandomSequences.java @ 118

Last change on this file since 118 was 84, checked in by sherbold, 13 years ago

+ added command generateRandomSequences

  • changed command generateReplayfile such that it accepts an optional parameter with the name of the sequences that are to be written, to allow writing sequences generated with generateRandomSequences
  • minor output changes
  • Property svn:mime-type set to text/plain
File size: 1.7 KB
Line 
1package de.ugoe.cs.eventbench.commands;
2
3import java.security.InvalidParameterException;
4import java.util.LinkedList;
5import java.util.List;
6
7import de.ugoe.cs.eventbench.data.GlobalDataContainer;
8import de.ugoe.cs.eventbench.data.Event;
9import de.ugoe.cs.eventbench.models.IStochasticProcess;
10import de.ugoe.cs.util.console.Command;
11import de.ugoe.cs.util.console.Console;
12
13public class CMDgenerateRandomSequences implements Command {
14
15        @Override
16        public void run(List<Object> parameters) {
17                String modelname;
18                String sequencesName;
19                int numSessions;
20                try {
21                        modelname = (String) parameters.get(0);
22                        sequencesName = (String) parameters.get(1);
23                        numSessions = Integer.parseInt((String) parameters.get(2));
24                }
25                catch (Exception e) {
26                        throw new InvalidParameterException();
27                }
28               
29                IStochasticProcess model = null;
30                Object dataObject = GlobalDataContainer.getInstance().getData(modelname);
31                if( dataObject==null ) {
32                        Console.println("Model " + modelname + " not found in storage.");
33                }
34                else if( !(dataObject instanceof IStochasticProcess) ) {
35                        Console.println("Object " + modelname + " not of type MarkovModel!");
36                } else {
37                        model = (IStochasticProcess) dataObject;
38                        List<List<? extends Event<?>>> sequences = new LinkedList<List<? extends Event<?>>>();
39                        for( int i=0 ; i<numSessions ; i++ ) {
40                                sequences.add(model.randomSequence());
41                        }
42                        if( GlobalDataContainer.getInstance().addData(sequencesName, sequences) ) {
43                                Console.traceln("Old data \"" + sequencesName + "\" overwritten");
44                        }
45                }
46        }
47
48        @Override
49        public void help() {
50                Console.println("Usage: generateRandomSequenecs <modelName> <sequencesName> <numSessions>");
51        }
52
53}
Note: See TracBrowser for help on using the repository browser.