1 | package de.ugoe.cs.eventbench.commands;
|
---|
2 |
|
---|
3 | import java.security.InvalidParameterException;
|
---|
4 | import java.util.Collection;
|
---|
5 | import java.util.LinkedList;
|
---|
6 | import java.util.List;
|
---|
7 |
|
---|
8 | import de.ugoe.cs.eventbench.ReplayGenerator;
|
---|
9 | import de.ugoe.cs.eventbench.data.GlobalDataContainer;
|
---|
10 | import de.ugoe.cs.eventbench.data.ReplayableEvent;
|
---|
11 | import de.ugoe.cs.eventbench.models.IStochasticProcess;
|
---|
12 | import de.ugoe.cs.util.console.Command;
|
---|
13 | import de.ugoe.cs.util.console.Console;
|
---|
14 |
|
---|
15 | /**
|
---|
16 | * <p>
|
---|
17 | * Command to create a replay file with randomly generated sessions.
|
---|
18 | * </p>
|
---|
19 | *
|
---|
20 | * @author Steffen Herbold
|
---|
21 | * @version 1.0
|
---|
22 | */
|
---|
23 | public class CMDgenerateRandomReplay implements Command {
|
---|
24 |
|
---|
25 | /*
|
---|
26 | * (non-Javadoc)
|
---|
27 | *
|
---|
28 | * @see de.ugoe.cs.util.console.Command#help()
|
---|
29 | */
|
---|
30 | @Override
|
---|
31 | public void help() {
|
---|
32 | Console.println("Usage: generateRandomReplay <modelName> <filename> {<numSessions>}");
|
---|
33 | }
|
---|
34 |
|
---|
35 | /*
|
---|
36 | * (non-Javadoc)
|
---|
37 | *
|
---|
38 | * @see de.ugoe.cs.util.console.Command#run(java.util.List)
|
---|
39 | */
|
---|
40 | @SuppressWarnings("unchecked")
|
---|
41 | @Override
|
---|
42 | public void run(List<Object> parameters) {
|
---|
43 | String modelname;
|
---|
44 | String filename;
|
---|
45 | int numSessions = 1;
|
---|
46 | try {
|
---|
47 | modelname = (String) parameters.get(0);
|
---|
48 | filename = (String) parameters.get(1);
|
---|
49 | if (parameters.size() < 3) {
|
---|
50 | numSessions = Integer.parseInt((String) parameters.get(2));
|
---|
51 | }
|
---|
52 | } catch (Exception e) {
|
---|
53 | throw new InvalidParameterException();
|
---|
54 | }
|
---|
55 |
|
---|
56 | IStochasticProcess model = null;
|
---|
57 | Object dataObject = GlobalDataContainer.getInstance()
|
---|
58 | .getData(modelname);
|
---|
59 | if (dataObject == null) {
|
---|
60 | Console.println("Model " + modelname + " not found in storage.");
|
---|
61 | return;
|
---|
62 | }
|
---|
63 | if (!(dataObject instanceof IStochasticProcess)) {
|
---|
64 | Console.println("Object " + modelname + " not of type MarkovModel!");
|
---|
65 | return;
|
---|
66 | }
|
---|
67 | model = (IStochasticProcess) dataObject;
|
---|
68 | Collection<List<ReplayableEvent<?>>> sequences = new LinkedList<List<ReplayableEvent<?>>>();
|
---|
69 | try {
|
---|
70 | for (int i = 0; i < numSessions; i++) {
|
---|
71 | sequences
|
---|
72 | .add((List<ReplayableEvent<?>>) model.randomSequence());
|
---|
73 | }
|
---|
74 | } catch (ClassCastException e) {
|
---|
75 | Console.println("Modeled events don't support replay.");
|
---|
76 | }
|
---|
77 | ReplayGenerator generator = new ReplayGenerator();
|
---|
78 | generator.createLogfileMultipleSessions(sequences, filename);
|
---|
79 | }
|
---|
80 |
|
---|
81 | }
|
---|