77import java .io .IOException ;
88import java .util .ArrayList ;
99import java .util .Arrays ;
10+ import java .util .Collections ;
1011import java .util .List ;
1112import java .util .Properties ;
1213
1617import org .deckfour .xes .classification .XEventNameClassifier ;
1718import org .deckfour .xes .info .XLogInfoFactory ;
1819import org .deckfour .xes .model .XLog ;
19- import org .processmining .acceptingpetrinet .models .AcceptingPetriNet ;
20- import org .processmining .acceptingpetrinet .models .impl .AcceptingPetriNetImpl ;
2120import org .processmining .contexts .uitopia .UIPluginContext ;
2221import org .processmining .framework .plugin .PluginContext ;
2322import org .processmining .models .connections .GraphLayoutConnection ;
3736import qut .pm .prom .helpers .HeadlessUIPluginContext ;
3837import qut .pm .prom .helpers .PetrinetExportUtils ;
3938import qut .pm .spm .AcceptingStochasticNet ;
39+ import qut .pm .spm .AcceptingStochasticNetImpl ;
4040import qut .pm .spm .Measure ;
4141import qut .pm .spm .PetrinetSource ;
4242import qut .pm .spm .RunState ;
@@ -89,6 +89,7 @@ private static enum Classifier{
8989 private boolean exportDOT = false ;
9090 private int kfoldLogs = 1 ;
9191 private int kfoldLogsStart = 1 ;
92+ // private String modelInputFileName = "";
9293 private List <StochasticNetLogMiner > miners ;
9394 private List <PetrinetSource > models ;
9495 private List <SPNQualityCalculator > calculators ;
@@ -140,26 +141,26 @@ private void configureModels(Properties cfg) throws Exception{
140141 for (String modelFile : modelFiles ) {
141142 String fname = modelPath + File .separator + modelFile .trim ();
142143 LOGGER .info ("Loading model from {}" ,fname );
143- AcceptingPetriNet net = loadNet (new File (fname ));
144- String shortName = modelFile .replace ("omodel_" , "" );
145- shortName = shortName .substring (0 , shortName .indexOf ("_" ) );
146- LOGGER .info ("Short name {}" ,shortName );
147- models .add ( new PetrinetSource (net ,shortName ) );
144+ AcceptingStochasticNet net = loadNet (new File (fname ));
145+ models .add ( new PetrinetSource (net ,net .getId ()) );
148146 }
149147 }
150148
151- private static AcceptingPetriNet loadNet (File file ) throws Exception {
152- PluginContext context =
153- new HeadlessDefinitelyNotUIPluginContext (new ConsoleUIPluginContext (), "modelrunner_loadnet" );
149+ private AcceptingStochasticNet loadNet (File file ) throws Exception {
150+ PluginContext context = new HeadlessDefinitelyNotUIPluginContext (new ConsoleUIPluginContext (),
151+ "modelrunner_loadnet" );
152+ String shortName = file .getName ().replace ("osmodel_" , "" );
153+ shortName = shortName .substring (0 , shortName .indexOf ("_" ) );
154+ LOGGER .info ("Short name {}" ,shortName );
154155 Serializer serializer = new Persister ();
155156 PNMLRoot pnml = serializer .read (PNMLRoot .class , file );
156157 StochasticNetDeserializer converter = new StochasticNetDeserializer ();
157158 Object [] objs = converter .convertToNet (context , pnml , file .getName (), true );
158- AcceptingPetriNet apn = new AcceptingPetriNetImpl ( (StochasticNet ) objs [0 ],
159- (Marking )objs [1 ],( Marking )objs [2 ]);
159+ AcceptingStochasticNet apn = new AcceptingStochasticNetImpl ( shortName , (StochasticNet ) objs [0 ],
160+ (Marking ) objs [1 ], Collections . singleton (( Marking ) objs [2 ]) );
160161 return apn ;
161162 }
162-
163+
163164
164165 private void configureMiners (Properties cfg ) {
165166 miners = new ArrayList <>();
@@ -241,17 +242,17 @@ private void runSingleMinerRun(StochasticNetLogMiner miner, String inputLogName,
241242 throws Exception
242243 {
243244 UIPluginContext uipc =
244- new HeadlessUIPluginContext (new ConsoleUIPluginContext (), "spmrunner_logparser " );
245+ new HeadlessUIPluginContext (new ConsoleUIPluginContext (), "tp_runnerlogparser " );
245246 final String SEP = " -- " ;
246247 noteRunStart (miner , inputLogName , SEP );
247248 String inputLogPrefix = logPrefix (inputLogName );
248- String outputModelName = nameFile (inputLogPrefix ,miner .getShortID (),"omodel " ,PNML );
249+ String outputModelName = nameFile (inputLogPrefix ,miner .getShortID (),"osmodel " ,PNML );
249250 RunStats runStats = new RunStats (inputLogName ,outputModelName , miner .getReadableID ());
250251 TaskStats stats = new TaskStats ("spmlogparser" );
251252 stats .markRunning ();
252253 try {
253254 XLog log = loadLog (uipc , inputLogName , stats );
254- uipc = new HeadlessUIPluginContext (new ConsoleUIPluginContext (), "spmrunner_mining " );
255+ uipc = new HeadlessUIPluginContext (new ConsoleUIPluginContext (), "tp_runnermining " );
255256 stats = closeTaskAndMakeNew (runStats , stats , "miner" );
256257 LOGGER .debug (stats .formatStats ());
257258 File modelFile = new File (outputModelName );
@@ -265,7 +266,7 @@ private void runSingleMinerRun(StochasticNetLogMiner miner, String inputLogName,
265266 stats = makeNewTask ("visualize" );
266267 exportVisualization (miner ,inputLogPrefix );
267268 stats .markEnd ();
268- uipc = new HeadlessUIPluginContext (new ConsoleUIPluginContext (), "spmrunner_postrun " );
269+ uipc = new HeadlessUIPluginContext (new ConsoleUIPluginContext (), "tp_runnerpostrun " );
269270 if (miner .isStochasticNetProducer ()) {
270271 TaskStats compStats = new TaskStats ("complog" );
271272 // note these log count stats in compStats currently unused
@@ -407,14 +408,66 @@ private void noteRunEnd(StochasticNetLogMiner artifactRun, String inputLogPrefix
407408 }
408409 }
409410
411+ private TaskStats makeNewTask (RunStats runStats , String newTaskName ) {
412+ TaskStats newTaskStats = new TaskStats (newTaskName );
413+ newTaskStats .markRunning ();
414+ runStats .addTask (newTaskStats );
415+ return newTaskStats ;
416+ }
417+
418+
419+ private void calculatePostStats (PluginContext context , String inputLogPrefix ,
420+ PetrinetSource model , XLog log , RunStats runStats )
421+ throws Exception
422+ {
423+ TaskStats stats = null ;
424+ for (SPNQualityCalculator calc : calculators ) {
425+ stats = makeNewTask ("calculate " + calc .getReadableId ());
426+ calc .calculate (context , model .getAcceptingPetriNet (), log ,
427+ classifierFor (log ), stats );
428+ closeTask (runStats ,stats );
429+ // Conservatively export stats after every run
430+ LOGGER .info (runStats .formatStats ());
431+ exportRun (model .getSourceId (), inputLogPrefix , runStats );
432+ }
433+ }
434+
435+
436+ public void runPredefinedModelVsLog (PetrinetSource model , String inputLogName ) throws Exception {
437+ UIPluginContext uipc =
438+ new HeadlessUIPluginContext (new ConsoleUIPluginContext (), "tp_runnermvl" );
439+ RunStats runStats = new RunStats (inputLogName ,model .getNet ().getLabel (), model .getSourceId ());
440+ String df = logPrefix (inputLogName );
441+ // RunStats runStats = initPredefRunStats(model, "predef");
442+ TaskStats stats = makeNewTask (runStats , "tpmlogparser" );
443+ try {
444+ XLog log = loadLog (uipc , inputLogName , stats );
445+ calculatePostStats (uipc , df , model , log , runStats );
446+ } catch (Exception e ) {
447+ exportRun (model .getSourceId (), df , runStats );
448+ throw new RuntimeException (e );
449+ }
450+ }
451+
410452
453+
454+ public void runPredefinedModelCollectionVsLog () throws Exception {
455+ for (String df : dataFiles ) {
456+ for (PetrinetSource model : models ) {
457+ runPredefinedModelVsLog (model ,df );
458+ }
459+ }
460+ }
411461
412462 public void runAll () throws Exception {
413463 for (String df : dataFiles ) {
414464 // Basic sanity checks happen already at config load time
415465 if (!miners .isEmpty ()) {
416466 runAllMiners (df );
417467 }
468+ if (miners .isEmpty () && !models .isEmpty ()) {
469+ runPredefinedModelCollectionVsLog ();
470+ }
418471 }
419472 }
420473
0 commit comments