public void compileSSBNAndPropagateFindings(SSBN ssbn) throws Exception {
// use DMP instead of Junction tree.
IInferenceAlgorithm dmp = getBNInferenceAlgorithm();
// if we are calling this algorithm from GUI, set up the whole BN module instead of just the inference algorithm
NetworkWindow bnModule = null; // this is going to hold the BN module (NetworkWindow is a UnBBayesModule)
if (getMediator() != null) {
// Instantiate a new BN module
bnModule = new NetworkWindow(ssbn.getNetwork());
// extract controller from BN module
NetworkController controller = bnModule.getController();
dmp.setMediator(controller);
controller.setInferenceAlgorithm(dmp);
// Make sure the tree (JTree in the left side of compilation panel) is updated with the network changes, if there is any.
controller.getScreen().getEvidenceTree().resetTree();
}
if (this.isToCompileFinalSSBN() ) {
// this is the actual BN (i.e. SSBN) to compile
Network bn = ssbn.getNetwork();
// If it is a SingleEntityNetwork, make sure all variables are properly initialized
if (bn instanceof SingleEntityNetwork) {
SingleEntityNetwork singleEntityNetwork = (SingleEntityNetwork) bn;
singleEntityNetwork.resetNodesCopy();
singleEntityNetwork.resetEvidences();
}
// actually compile network using dmp
dmp.setNetwork(bn);
dmp.run();
if (dmp.getNetwork() != null && (dmp.getNetwork() instanceof Network)) {
// dmp creates new network. SSBN must be linked to the new network
ssbn.setNetwork((Network) dmp.getNetwork());
}
// if we instantiated a BN module previously, then change it to the "compiled" view instead of "edit" view
if (bnModule != null) {
bnModule.changeToPNCompilationPane();
}
// fill findings and propagate again
this.setUpFindings(ssbn, dmp);
}
// popup network
// TODO migrate this logic to showSSBN(SSBN ssbn), but in a thread-safe, state-insensitive way
if (getMediator() != null) {
if (getMediator() instanceof IMEBNMediator) {
// the following code forces GUI to understand that it should not display an SSBN in its card layout panel
// this is because the network is displayed as a popup
((IMEBNMediator)getMediator()).setToTurnToSSBNMode(false);
((IMEBNMediator)getMediator()).setSpecificSituationBayesianNetwork(null); // free any previous ssbn
}
// add/show popup
getMediator().getScreen().getUnbbayesFrame().addWindow(bnModule);
bnModule.setVisible(true);
bnModule.updateUI();
getMediator().getScreen().getUnbbayesFrame().repaint();
bnModule.repaint();
}
}