1 | package de.ugoe.cs.eventbench.commands;
|
---|
2 |
|
---|
3 | import java.security.InvalidParameterException;
|
---|
4 | import java.util.Collection;
|
---|
5 | import java.util.List;
|
---|
6 |
|
---|
7 | import de.ugoe.cs.eventbench.coverage.CoverageCalculator;
|
---|
8 | import de.ugoe.cs.eventbench.data.Event;
|
---|
9 | import de.ugoe.cs.eventbench.data.GlobalDataContainer;
|
---|
10 | import de.ugoe.cs.eventbench.models.IStochasticProcess;
|
---|
11 | import de.ugoe.cs.util.console.Command;
|
---|
12 | import de.ugoe.cs.util.console.Console;
|
---|
13 |
|
---|
14 | public class CMDcalcCoverage implements Command {
|
---|
15 |
|
---|
16 | @SuppressWarnings("unchecked")
|
---|
17 | @Override
|
---|
18 | public void run(List<Object> parameters) {
|
---|
19 | String modelname;
|
---|
20 | String[] sequenceNames;
|
---|
21 | int minLength;
|
---|
22 | int maxLength;
|
---|
23 | try {
|
---|
24 | modelname = (String) parameters.get(0);
|
---|
25 | sequenceNames = (String[]) parameters.get(1);
|
---|
26 | minLength = Integer.parseInt((String) parameters.get(2));
|
---|
27 | maxLength = Integer.parseInt((String) parameters.get(3));
|
---|
28 | }
|
---|
29 | catch (Exception e) {
|
---|
30 | throw new InvalidParameterException();
|
---|
31 | }
|
---|
32 |
|
---|
33 | IStochasticProcess process = null;
|
---|
34 | Collection<List<? extends Event<?>>> sequences = null;
|
---|
35 | Object dataObjectProcess = GlobalDataContainer.getInstance().getData(modelname);
|
---|
36 | if( dataObjectProcess==null ) {
|
---|
37 | Console.println("Model " + modelname + " not found in storage.");
|
---|
38 | }
|
---|
39 | else if( !(dataObjectProcess instanceof IStochasticProcess) ) {
|
---|
40 | Console.println("Object " + modelname + " not of type MarkovModel!");
|
---|
41 | } else {
|
---|
42 | Console.print("seqName");
|
---|
43 | for( int length=minLength ; length<=maxLength ; length++) {
|
---|
44 | Console.print(";all_" + length);
|
---|
45 | Console.print(";pos_" + length);
|
---|
46 | Console.print(";wei_" + length);
|
---|
47 | }
|
---|
48 | Console.println("");
|
---|
49 | for( String sequenceName : sequenceNames ) {
|
---|
50 | Object dataObjectSequences = GlobalDataContainer.getInstance().getData(sequenceName);
|
---|
51 | if( dataObjectSequences==null ) {
|
---|
52 | Console.println("Sequences " + sequenceName + " not found in storage.");
|
---|
53 | }
|
---|
54 | else if( !(dataObjectSequences instanceof Collection<?>) ) {
|
---|
55 | // cannot really perform type check at runtime! this is an approximative substitute
|
---|
56 | Console.println("Object " + sequenceName + "not of type Collection<?>!");
|
---|
57 | }
|
---|
58 |
|
---|
59 | process = (IStochasticProcess) dataObjectProcess;
|
---|
60 | sequences = (Collection<List<? extends Event<?>>>) dataObjectSequences;
|
---|
61 | Console.print(sequenceName);
|
---|
62 | for( int length=minLength ; length<=maxLength ; length++) {
|
---|
63 | CoverageCalculator covCalc = new CoverageCalculator(process, sequences, length);
|
---|
64 | Console.print(";" + covCalc.getCoverageAllNoWeight());
|
---|
65 | Console.print(";" + covCalc.getCoveragePossibleNoWeight());
|
---|
66 | Console.print(";" + covCalc.getCoveragePossibleWeight());
|
---|
67 | }
|
---|
68 | Console.println("");
|
---|
69 | }
|
---|
70 | }
|
---|
71 | }
|
---|
72 |
|
---|
73 | @Override
|
---|
74 | public void help() {
|
---|
75 | Console.println("Usage: calcCoverage <modelname> [sequenceNames] <minCovLength> <maxCovLength>");
|
---|
76 | }
|
---|
77 |
|
---|
78 | }
|
---|