1 | package de.ugoe.cs.eventbench.commands;
|
---|
2 |
|
---|
3 | import java.security.InvalidParameterException;
|
---|
4 | import java.util.LinkedList;
|
---|
5 | import java.util.List;
|
---|
6 |
|
---|
7 | import de.ugoe.cs.eventbench.data.GlobalDataContainer;
|
---|
8 | import de.ugoe.cs.eventbench.data.Event;
|
---|
9 | import de.ugoe.cs.eventbench.models.IStochasticProcess;
|
---|
10 | import de.ugoe.cs.util.console.Command;
|
---|
11 | import de.ugoe.cs.util.console.Console;
|
---|
12 |
|
---|
13 | public 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 | }
|
---|