source: trunk/autoquest-ui-core/src/main/java/de/ugoe/cs/autoquest/commands/usage/CMDgenerateRandomSequences.java @ 927

Last change on this file since 927 was 927, checked in by sherbold, 12 years ago
  • added copyright under the Apache License, Version 2.0
  • Property svn:mime-type set to text/plain
File size: 3.3 KB
Line 
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
15package de.ugoe.cs.autoquest.commands.usage;
16
17import java.util.Collection;
18import java.util.List;
19
20import de.ugoe.cs.autoquest.CommandHelpers;
21import de.ugoe.cs.autoquest.eventcore.Event;
22import de.ugoe.cs.autoquest.testgeneration.RandomWalkGenerator;
23import de.ugoe.cs.autoquest.usageprofiles.IStochasticProcess;
24import de.ugoe.cs.util.console.Command;
25import de.ugoe.cs.util.console.Console;
26import de.ugoe.cs.util.console.GlobalDataContainer;
27
28/**
29 * <p>
30 * Command to generate random sessions.
31 * </p>
32 *
33 * @author Steffen Herbold
34 * @version 1.0
35 */
36public class CMDgenerateRandomSequences implements Command {
37
38        /*
39         * (non-Javadoc)
40         *
41         * @see de.ugoe.cs.util.console.Command#run(java.util.List)
42         */
43        @Override
44        public void run(List<Object> parameters) {
45                String modelname;
46                String sequencesName;
47                int numSessions;
48                int minLength = 0;
49                int maxLength = Integer.MAX_VALUE;
50                long maxIter;
51                boolean validEnd = true;
52                try {
53                        modelname = (String) parameters.get(0);
54                        sequencesName = (String) parameters.get(1);
55                        numSessions = Integer.parseInt((String) parameters.get(2));
56                        minLength = Integer.parseInt((String) parameters.get(3));
57                        maxLength = Integer.parseInt((String) parameters.get(4));
58                        maxIter = numSessions * 10;
59                        if (parameters.size() >= 5) {
60                                maxIter = Long.parseLong((String) parameters.get(5));
61                        }
62                        if (parameters.size() >= 6) {
63                                validEnd = Boolean.parseBoolean((String) parameters.get(6));
64                        }
65                } catch (Exception e) {
66                        throw new IllegalArgumentException();
67                }
68
69                IStochasticProcess model = null;
70                Object dataObject = GlobalDataContainer.getInstance()
71                                .getData(modelname);
72                if (dataObject == null) {
73                        CommandHelpers.objectNotFoundMessage(modelname);
74                        return;
75                }
76                if (!(dataObject instanceof IStochasticProcess)) {
77                        CommandHelpers.objectNotType(modelname, "IStochasticProcess");
78                        return;
79                }
80                model = (IStochasticProcess) dataObject;
81
82                RandomWalkGenerator generator = new RandomWalkGenerator(numSessions,
83                                minLength, maxLength, validEnd, maxIter);
84                Collection<List<Event>> sequences = generator
85                                .generateTestSuite(model);
86
87                if (sequences.size() < numSessions) {
88                        Console.println("Only " + sequences.size()
89                                        + " unique sessions generated after " + maxIter
90                                        + " iterations");
91                }
92
93                if (GlobalDataContainer.getInstance().addData(sequencesName, sequences)) {
94                        CommandHelpers.dataOverwritten(sequencesName);
95                }
96        }
97
98        /*
99         * (non-Javadoc)
100         *
101         * @see de.ugoe.cs.util.console.Command#help()
102         */
103        @Override
104        public String help() {
105                return "generateRandomSequenecs <modelname> <sequencesName> <numSequences> <minlength> <maxlength> {<maxIter>} {<validEnd>}";
106        }
107
108}
Note: See TracBrowser for help on using the repository browser.