| 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.CoverageCalculatorObserved;
|
|---|
| 8 | import de.ugoe.cs.eventbench.coverage.CoverageCalculatorProcess;
|
|---|
| 9 | import de.ugoe.cs.eventbench.data.Event;
|
|---|
| 10 | import de.ugoe.cs.eventbench.data.GlobalDataContainer;
|
|---|
| 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 CMDcalcCoverage implements Command {
|
|---|
| 16 |
|
|---|
| 17 | @SuppressWarnings("unchecked")
|
|---|
| 18 | @Override
|
|---|
| 19 | public void run(List<Object> parameters) {
|
|---|
| 20 | String modelname;
|
|---|
| 21 | String[] sequenceNames;
|
|---|
| 22 | int minLength;
|
|---|
| 23 | int maxLength;
|
|---|
| 24 | String observedName = "sequences";
|
|---|
| 25 | try {
|
|---|
| 26 | modelname = (String) parameters.get(0);
|
|---|
| 27 | sequenceNames = (String[]) parameters.get(1);
|
|---|
| 28 | minLength = Integer.parseInt((String) parameters.get(2));
|
|---|
| 29 | maxLength = Integer.parseInt((String) parameters.get(3));
|
|---|
| 30 | if( parameters.size()==5 ) {
|
|---|
| 31 | observedName = (String) parameters.get(1);
|
|---|
| 32 | }
|
|---|
| 33 | }
|
|---|
| 34 | catch (Exception e) {
|
|---|
| 35 | throw new InvalidParameterException();
|
|---|
| 36 | }
|
|---|
| 37 |
|
|---|
| 38 | IStochasticProcess process = null;
|
|---|
| 39 | Collection<List<? extends Event<?>>> observedSequences = null;
|
|---|
| 40 | Collection<List<? extends Event<?>>> sequences = null;
|
|---|
| 41 | Object dataObjectProcess = GlobalDataContainer.getInstance().getData(modelname);
|
|---|
| 42 | Object dataObjectObserved = GlobalDataContainer.getInstance().getData(observedName);
|
|---|
| 43 | if( dataObjectProcess==null ) {
|
|---|
| 44 | Console.printerrln("Model " + modelname + " not found in storage.");
|
|---|
| 45 | return;
|
|---|
| 46 | }
|
|---|
| 47 | if( !(dataObjectProcess instanceof IStochasticProcess) ) {
|
|---|
| 48 | Console.printerrln("Object " + modelname + " not of type IStochasticProcess!");
|
|---|
| 49 | return;
|
|---|
| 50 | }
|
|---|
| 51 | if( dataObjectObserved==null ) {
|
|---|
| 52 | Console.printerrln("Observed sequences not found in storage.");
|
|---|
| 53 | return;
|
|---|
| 54 | }
|
|---|
| 55 | if( !(dataObjectObserved instanceof Collection<?>) ) {
|
|---|
| 56 | // weak instance check!
|
|---|
| 57 | Console.printerrln("Object " + observedName + " not a Collection!");
|
|---|
| 58 | return;
|
|---|
| 59 | }
|
|---|
| 60 | process = (IStochasticProcess) dataObjectProcess;
|
|---|
| 61 | observedSequences = (Collection<List<? extends Event<?>>>) dataObjectObserved;
|
|---|
| 62 |
|
|---|
| 63 |
|
|---|
| 64 | Console.print("seqName");
|
|---|
| 65 | for( int length=minLength ; length<=maxLength ; length++) {
|
|---|
| 66 | Console.print(";numObs_" + length);
|
|---|
| 67 | Console.print(";numCov_" + length);
|
|---|
| 68 | Console.print(";numNew_" + length);
|
|---|
| 69 | Console.print(";numPos_" + length);
|
|---|
| 70 | Console.print(";all_" + length);
|
|---|
| 71 | Console.print(";pos_" + length);
|
|---|
| 72 | Console.print(";poswei_" + length);
|
|---|
| 73 | Console.print(";obs_" + length);
|
|---|
| 74 | Console.print(";obswei_" + length);
|
|---|
| 75 | Console.print(";new_" + length);
|
|---|
| 76 | Console.print(";newpos_" + length);
|
|---|
| 77 | Console.print(";newposwei_" + length);
|
|---|
| 78 | }
|
|---|
| 79 | Console.println("");
|
|---|
| 80 | for( String sequenceName : sequenceNames ) {
|
|---|
| 81 | Object dataObjectSequences = GlobalDataContainer.getInstance().getData(sequenceName);
|
|---|
| 82 | if( dataObjectSequences==null ) {
|
|---|
| 83 | Console.println("Sequences " + sequenceName + " not found in storage.");
|
|---|
| 84 | }
|
|---|
| 85 | else if( !(dataObjectSequences instanceof Collection<?>) ) {
|
|---|
| 86 | // cannot really perform type check at runtime! this is an approximative substitute
|
|---|
| 87 | Console.printerrln("Object " + sequenceName + "not of type Collection<?>!");
|
|---|
| 88 | return;
|
|---|
| 89 | }
|
|---|
| 90 | sequences = (Collection<List<? extends Event<?>>>) dataObjectSequences;
|
|---|
| 91 | Console.print(sequenceName);
|
|---|
| 92 | for( int length=minLength ; length<=maxLength ; length++) {
|
|---|
| 93 | CoverageCalculatorProcess covCalcProc = new CoverageCalculatorProcess(process, sequences, length);
|
|---|
| 94 | CoverageCalculatorObserved covCalcObs = new CoverageCalculatorObserved(observedSequences, sequences, length);
|
|---|
| 95 | Console.print(";" + covCalcObs.getNumObserved());
|
|---|
| 96 | Console.print(";" + covCalcObs.getNumCovered());
|
|---|
| 97 | Console.print(";" + covCalcObs.getNumNew());
|
|---|
| 98 | Console.print(";" + covCalcProc.getNumPossible());
|
|---|
| 99 | Console.print(";" + covCalcProc.getCoverageAllNoWeight());
|
|---|
| 100 | Console.print(";" + covCalcProc.getCoveragePossibleNoWeight());
|
|---|
| 101 | Console.print(";" + covCalcProc.getCoveragePossibleWeight());
|
|---|
| 102 | Console.print(";" + covCalcObs.getCoverageObserved());
|
|---|
| 103 | Console.print(";" + covCalcObs.getCoverageObservedWeigth(process));
|
|---|
| 104 | Console.print(";" + covCalcObs.getNewPercentage());
|
|---|
| 105 | Console.print(";" + covCalcObs.getCoveragePossibleNew(process));
|
|---|
| 106 | Console.print(";" + covCalcObs.getCoveragePossibleNewWeight(process));
|
|---|
| 107 | }
|
|---|
| 108 | Console.println("");
|
|---|
| 109 | }
|
|---|
| 110 | }
|
|---|
| 111 |
|
|---|
| 112 | @Override
|
|---|
| 113 | public void help() {
|
|---|
| 114 | Console.println("Usage: calcCoverage <modelname> [sequenceNames] <minCovLength> <maxCovLength>");
|
|---|
| 115 | }
|
|---|
| 116 |
|
|---|
| 117 | }
|
|---|