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.ReplayGenerator;
|
---|
8 | import de.ugoe.cs.eventbench.data.GlobalDataContainer;
|
---|
9 | import de.ugoe.cs.eventbench.data.ReplayableEvent;
|
---|
10 | import de.ugoe.cs.eventbench.models.IStochasticProcess;
|
---|
11 | import de.ugoe.cs.util.console.Command;
|
---|
12 | import de.ugoe.cs.util.console.Console;
|
---|
13 |
|
---|
14 | public class CMDgenerateRandomReplay implements Command {
|
---|
15 |
|
---|
16 | @Override
|
---|
17 | public void help() {
|
---|
18 | Console.println("Usage: generateRandomReplay <modelName> <filename> {<numSessions>}");
|
---|
19 | }
|
---|
20 |
|
---|
21 | @SuppressWarnings("unchecked")
|
---|
22 | @Override
|
---|
23 | public void run(List<Object> parameters) {
|
---|
24 | String modelname;
|
---|
25 | String filename;
|
---|
26 | int numSessions = 1;
|
---|
27 | try {
|
---|
28 | modelname = (String) parameters.get(0);
|
---|
29 | filename = (String) parameters.get(1);
|
---|
30 | if( parameters.size()<3 ) {
|
---|
31 | numSessions = Integer.parseInt((String) parameters.get(2));
|
---|
32 | }
|
---|
33 | }
|
---|
34 | catch (Exception e) {
|
---|
35 | throw new InvalidParameterException();
|
---|
36 | }
|
---|
37 |
|
---|
38 | IStochasticProcess model = null;
|
---|
39 | Object dataObject = GlobalDataContainer.getInstance().getData(modelname);
|
---|
40 | if( dataObject==null ) {
|
---|
41 | Console.println("Model " + modelname + " not found in storage.");
|
---|
42 | }
|
---|
43 | else if( !(dataObject instanceof IStochasticProcess) ) {
|
---|
44 | Console.println("Object " + modelname + " not of type MarkovModel!");
|
---|
45 | } else {
|
---|
46 | model = (IStochasticProcess) dataObject;
|
---|
47 | List<List<ReplayableEvent<?>>> sequences = new LinkedList<List<ReplayableEvent<?>>>();
|
---|
48 | try {
|
---|
49 | for( int i=0 ; i<numSessions ; i++ ) {
|
---|
50 | sequences.add((List<ReplayableEvent<?>>) model.randomSequence());
|
---|
51 | }
|
---|
52 | } catch (ClassCastException e) {
|
---|
53 | Console.println("Modeled events don't support replay.");
|
---|
54 | }
|
---|
55 | ReplayGenerator generator = new ReplayGenerator();
|
---|
56 | generator.createLogfileMultipleSessions(sequences, filename);
|
---|
57 | }
|
---|
58 | }
|
---|
59 |
|
---|
60 | }
|
---|