1 | package de.ugoe.cs.eventbench.commands;
|
---|
2 |
|
---|
3 | import java.security.InvalidParameterException;
|
---|
4 | import java.util.HashSet;
|
---|
5 | import java.util.LinkedList;
|
---|
6 | import java.util.List;
|
---|
7 | import java.util.Set;
|
---|
8 |
|
---|
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 | public class CMDgenerateRandomSequences implements Command {
|
---|
16 |
|
---|
17 | @Override
|
---|
18 | public void run(List<Object> parameters) {
|
---|
19 | String modelname;
|
---|
20 | String sequencesName;
|
---|
21 | int numSessions;
|
---|
22 | long maxIter;
|
---|
23 | try {
|
---|
24 | modelname = (String) parameters.get(0);
|
---|
25 | sequencesName = (String) parameters.get(1);
|
---|
26 | numSessions = Integer.parseInt((String) parameters.get(2));
|
---|
27 | maxIter = numSessions*10;
|
---|
28 | if( parameters.size()==4 ) {
|
---|
29 | maxIter = Long.parseLong((String) parameters.get(3));
|
---|
30 | }
|
---|
31 | }
|
---|
32 | catch (Exception e) {
|
---|
33 | throw new InvalidParameterException();
|
---|
34 | }
|
---|
35 |
|
---|
36 | IStochasticProcess model = null;
|
---|
37 | Object dataObject = GlobalDataContainer.getInstance().getData(modelname);
|
---|
38 | if( dataObject==null ) {
|
---|
39 | Console.println("Model " + modelname + " not found in storage.");
|
---|
40 | }
|
---|
41 | else if( !(dataObject instanceof IStochasticProcess) ) {
|
---|
42 | Console.println("Object " + modelname + " not of type MarkovModel!");
|
---|
43 | } else {
|
---|
44 | model = (IStochasticProcess) dataObject;
|
---|
45 | Set<List<? extends Event<?>>> sequences = new HashSet<List<? extends Event<?>>>(numSessions);
|
---|
46 | long numIterations = 0;
|
---|
47 | while( sequences.size()<numSessions && numIterations<maxIter ) {
|
---|
48 | sequences.add(model.randomSequence());
|
---|
49 | numIterations++;
|
---|
50 | }
|
---|
51 | if( sequences.size() < numSessions ) {
|
---|
52 | Console.println("Only " + sequences.size() + " unique sessions generated after " + maxIter + " iterations");
|
---|
53 | }
|
---|
54 | if( GlobalDataContainer.getInstance().addData(sequencesName, sequences) ) {
|
---|
55 | Console.traceln("Old data \"" + sequencesName + "\" overwritten");
|
---|
56 | }
|
---|
57 | }
|
---|
58 | }
|
---|
59 |
|
---|
60 | @Override
|
---|
61 | public void help() {
|
---|
62 | Console.println("Usage: generateRandomSequenecs <modelName> <sequencesName> <numSessions> {<maxIter>}");
|
---|
63 | }
|
---|
64 |
|
---|
65 | }
|
---|