1 | package de.ugoe.cs.eventbench.commands;
|
---|
2 |
|
---|
3 | import java.security.InvalidParameterException;
|
---|
4 | import java.util.HashSet;
|
---|
5 | import java.util.List;
|
---|
6 | import java.util.Set;
|
---|
7 |
|
---|
8 | import de.ugoe.cs.eventbench.CommandHelpers;
|
---|
9 | import de.ugoe.cs.eventbench.data.GlobalDataContainer;
|
---|
10 | import de.ugoe.cs.eventbench.data.Event;
|
---|
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 generate random sessions.
|
---|
18 | * </p>
|
---|
19 | *
|
---|
20 | * @author Steffen Herbold
|
---|
21 | * @version 1.0
|
---|
22 | */
|
---|
23 | public class CMDgenerateRandomSequences implements Command {
|
---|
24 |
|
---|
25 | /*
|
---|
26 | * (non-Javadoc)
|
---|
27 | *
|
---|
28 | * @see de.ugoe.cs.util.console.Command#run(java.util.List)
|
---|
29 | */
|
---|
30 | @Override
|
---|
31 | public void run(List<Object> parameters) {
|
---|
32 | String modelname;
|
---|
33 | String sequencesName;
|
---|
34 | int numSessions;
|
---|
35 | int minLength = 0;
|
---|
36 | int maxLength = Integer.MAX_VALUE;
|
---|
37 | long maxIter;
|
---|
38 | boolean validEnd = true;
|
---|
39 | try {
|
---|
40 | modelname = (String) parameters.get(0);
|
---|
41 | sequencesName = (String) parameters.get(1);
|
---|
42 | numSessions = Integer.parseInt((String) parameters.get(2));
|
---|
43 | minLength = Integer.parseInt((String) parameters.get(3));
|
---|
44 | maxLength = Integer.parseInt((String) parameters.get(4));
|
---|
45 | maxIter = numSessions * 10;
|
---|
46 | if (parameters.size() >= 5) {
|
---|
47 | maxIter = Long.parseLong((String) parameters.get(5));
|
---|
48 | }
|
---|
49 | if (parameters.size() >= 6) {
|
---|
50 | validEnd = Boolean.parseBoolean((String) parameters.get(6));
|
---|
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 | CommandHelpers.objectNotFoundMessage(modelname);
|
---|
61 | return;
|
---|
62 | }
|
---|
63 | if (!(dataObject instanceof IStochasticProcess)) {
|
---|
64 | CommandHelpers.objectNotType(modelname, "IStochasticProcess");
|
---|
65 | return;
|
---|
66 | }
|
---|
67 | model = (IStochasticProcess) dataObject;
|
---|
68 | Set<List<? extends Event<?>>> sequences = new HashSet<List<? extends Event<?>>>(
|
---|
69 | numSessions);
|
---|
70 | long numIterations = 0;
|
---|
71 | while (sequences.size() < numSessions && numIterations < maxIter) {
|
---|
72 | List<? extends Event<?>> generatedSequence = model.randomSequence(
|
---|
73 | maxLength, validEnd);
|
---|
74 | if (generatedSequence.size() >= minLength
|
---|
75 | && generatedSequence.size() <= maxLength) {
|
---|
76 | sequences.add(generatedSequence);
|
---|
77 | }
|
---|
78 | numIterations++;
|
---|
79 | }
|
---|
80 | if (sequences.size() < numSessions) {
|
---|
81 | Console.println("Only " + sequences.size()
|
---|
82 | + " unique sessions generated after " + maxIter
|
---|
83 | + " iterations");
|
---|
84 | }
|
---|
85 | if (GlobalDataContainer.getInstance().addData(sequencesName, sequences)) {
|
---|
86 | CommandHelpers.dataOverwritten(sequencesName);
|
---|
87 | }
|
---|
88 | }
|
---|
89 |
|
---|
90 | /*
|
---|
91 | * (non-Javadoc)
|
---|
92 | *
|
---|
93 | * @see de.ugoe.cs.util.console.Command#help()
|
---|
94 | */
|
---|
95 | @Override
|
---|
96 | public void help() {
|
---|
97 | Console.println("Usage: generateRandomSequenecs <modelName> <sequencesName> <numSessions> <minLength> <maxLength> {<maxIter>} {<validEnd>}");
|
---|
98 | }
|
---|
99 |
|
---|
100 | }
|
---|