[927] | 1 | // Copyright 2012 Georg-August-Universität Göttingen, Germany
|
---|
| 2 | //
|
---|
| 3 | // Licensed under the Apache License, Version 2.0 (the "License");
|
---|
| 4 | // you may not use this file except in compliance with the License.
|
---|
| 5 | // You may obtain a copy of the License at
|
---|
| 6 | //
|
---|
| 7 | // http://www.apache.org/licenses/LICENSE-2.0
|
---|
| 8 | //
|
---|
| 9 | // Unless required by applicable law or agreed to in writing, software
|
---|
| 10 | // distributed under the License is distributed on an "AS IS" BASIS,
|
---|
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
| 12 | // See the License for the specific language governing permissions and
|
---|
| 13 | // limitations under the License.
|
---|
| 14 |
|
---|
[922] | 15 | package de.ugoe.cs.autoquest.commands.usage;
|
---|
[84] | 16 |
|
---|
[524] | 17 | import java.util.Collection;
|
---|
[84] | 18 | import java.util.List;
|
---|
| 19 |
|
---|
[922] | 20 | import de.ugoe.cs.autoquest.CommandHelpers;
|
---|
| 21 | import de.ugoe.cs.autoquest.eventcore.Event;
|
---|
| 22 | import de.ugoe.cs.autoquest.testgeneration.RandomWalkGenerator;
|
---|
| 23 | import de.ugoe.cs.autoquest.usageprofiles.IStochasticProcess;
|
---|
[84] | 24 | import de.ugoe.cs.util.console.Command;
|
---|
| 25 | import de.ugoe.cs.util.console.Console;
|
---|
[667] | 26 | import de.ugoe.cs.util.console.GlobalDataContainer;
|
---|
[84] | 27 |
|
---|
[171] | 28 | /**
|
---|
[209] | 29 | * <p>
|
---|
| 30 | * Command to generate random sessions.
|
---|
| 31 | * </p>
|
---|
| 32 | *
|
---|
[171] | 33 | * @author Steffen Herbold
|
---|
| 34 | * @version 1.0
|
---|
| 35 | */
|
---|
[84] | 36 | public class CMDgenerateRandomSequences implements Command {
|
---|
| 37 |
|
---|
[209] | 38 | /*
|
---|
| 39 | * (non-Javadoc)
|
---|
| 40 | *
|
---|
[171] | 41 | * @see de.ugoe.cs.util.console.Command#run(java.util.List)
|
---|
| 42 | */
|
---|
[84] | 43 | @Override
|
---|
| 44 | public void run(List<Object> parameters) {
|
---|
| 45 | String modelname;
|
---|
| 46 | String sequencesName;
|
---|
| 47 | int numSessions;
|
---|
[121] | 48 | int minLength = 0;
|
---|
| 49 | int maxLength = Integer.MAX_VALUE;
|
---|
[241] | 50 | long maxIter;
|
---|
[388] | 51 | boolean validEnd = true;
|
---|
[84] | 52 | try {
|
---|
| 53 | modelname = (String) parameters.get(0);
|
---|
| 54 | sequencesName = (String) parameters.get(1);
|
---|
| 55 | numSessions = Integer.parseInt((String) parameters.get(2));
|
---|
[241] | 56 | minLength = Integer.parseInt((String) parameters.get(3));
|
---|
| 57 | maxLength = Integer.parseInt((String) parameters.get(4));
|
---|
[209] | 58 | maxIter = numSessions * 10;
|
---|
| 59 | if (parameters.size() >= 5) {
|
---|
[241] | 60 | maxIter = Long.parseLong((String) parameters.get(5));
|
---|
[121] | 61 | }
|
---|
[388] | 62 | if (parameters.size() >= 6) {
|
---|
| 63 | validEnd = Boolean.parseBoolean((String) parameters.get(6));
|
---|
| 64 | }
|
---|
[209] | 65 | } catch (Exception e) {
|
---|
[766] | 66 | throw new IllegalArgumentException();
|
---|
[84] | 67 | }
|
---|
[209] | 68 |
|
---|
| 69 | IStochasticProcess model = null;
|
---|
| 70 | Object dataObject = GlobalDataContainer.getInstance()
|
---|
| 71 | .getData(modelname);
|
---|
| 72 | if (dataObject == null) {
|
---|
[240] | 73 | CommandHelpers.objectNotFoundMessage(modelname);
|
---|
[209] | 74 | return;
|
---|
[84] | 75 | }
|
---|
[209] | 76 | if (!(dataObject instanceof IStochasticProcess)) {
|
---|
[240] | 77 | CommandHelpers.objectNotType(modelname, "IStochasticProcess");
|
---|
[209] | 78 | return;
|
---|
| 79 | }
|
---|
| 80 | model = (IStochasticProcess) dataObject;
|
---|
[524] | 81 |
|
---|
| 82 | RandomWalkGenerator generator = new RandomWalkGenerator(numSessions,
|
---|
| 83 | minLength, maxLength, validEnd, maxIter);
|
---|
[547] | 84 | Collection<List<Event>> sequences = generator
|
---|
[524] | 85 | .generateTestSuite(model);
|
---|
| 86 |
|
---|
[209] | 87 | if (sequences.size() < numSessions) {
|
---|
| 88 | Console.println("Only " + sequences.size()
|
---|
| 89 | + " unique sessions generated after " + maxIter
|
---|
| 90 | + " iterations");
|
---|
| 91 | }
|
---|
[524] | 92 |
|
---|
[209] | 93 | if (GlobalDataContainer.getInstance().addData(sequencesName, sequences)) {
|
---|
[240] | 94 | CommandHelpers.dataOverwritten(sequencesName);
|
---|
[209] | 95 | }
|
---|
[84] | 96 | }
|
---|
| 97 |
|
---|
[209] | 98 | /*
|
---|
| 99 | * (non-Javadoc)
|
---|
| 100 | *
|
---|
[171] | 101 | * @see de.ugoe.cs.util.console.Command#help()
|
---|
| 102 | */
|
---|
[84] | 103 | @Override
|
---|
[664] | 104 | public String help() {
|
---|
[726] | 105 | return "generateRandomSequenecs <modelname> <sequencesName> <numSequences> <minlength> <maxlength> {<maxIter>} {<validEnd>}";
|
---|
[84] | 106 | }
|
---|
| 107 |
|
---|
| 108 | }
|
---|