public class Model extends Object implements IdContainer<ModelException>, Storable
| Modifier and Type | Class and Description |
|---|---|
static class |
Model.CalculationFlag |
static class |
Model.ExportFlag |
static class |
Model.Field
This is set of fields for input/output to XML and JSON format
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
absorb(org.json.JSONObject json)
Creates all the Model structure from the provided JSONObject.
|
void |
calculate()
Triggers propagation in this Model for all Networks and DataSets.
|
void |
calculate(Collection<Network> networks,
Collection<DataSet> dataSets,
Model.CalculationFlag... flags)
Triggers propagation in this model for provided Networks and DataSets.
If either is null, all Networks or DataSets will be used instead. |
void |
convertToStatic(DataSet dataSet)
Make all states of dynamically discretized nodes static as they currently are in the provided DataSet.
No action will be performed if no nodes are simulated. Any VariableObservations in the DataSet will replace current Node variable defaults and will be replaced from the DataSet observations. |
DataSet |
createDataSet(org.json.JSONObject jsonDataSet)
Creates a DataSet for this Model from JSON data.
|
DataSet |
createDataSet(String id)
Creates a new DataSet and adds it to this Model.
|
Link |
createLink(Node source,
Node target,
CrossNetworkLink.Type type)
Creates a Link between two nodes in same or different Networks.
|
Link |
createLink(Node source,
Node target,
State state)
Creates a CrossNetworkLink of type CrossNetworkLink.Type.State that passes the given state from source Node to target Node.
|
Link |
createLink(String sourceNetworkId,
String sourceNodeId,
String targetNetworkId,
String targetNodeId,
CrossNetworkLink.Type type)
Creates a CrossNetworkLink of given Type.
|
Link |
createLink(String sourceNetworkId,
String sourceNodeId,
String targetNetworkId,
String targetNodeId,
String stateLabel)
Creates a CrossNetworkLink of type CrossNetworkLink.Type.State that passes the given state from source Node to target Node.
|
static Model |
createModel()
Factory method to create an empty instance of a Model class.
|
static Model |
createModel(org.json.JSONObject json)
Factory method to create an instance of a Model from provided JSONObject.
|
static Model |
createModel(uk.co.agena.minerva.model.Model api1Model)
Creates a Model from a Minerva Model object.
|
Network |
createNetwork(org.json.JSONObject jsonNetwork)
Creates a Network and adds it to this Model.
|
Network |
createNetwork(org.json.JSONObject jsonNetwork,
boolean withTables)
Creates a Network and adds it to this Model.
|
Network |
createNetwork(String id)
Creates a new empty Network and adds it to this Model.
|
Network |
createNetwork(String id,
String name)
Creates a new empty Network and adds it to this Model.
|
org.json.JSONObject |
export(Model.ExportFlag... flags)
Returns the Model as a minimal JSON.
Keeps only elements essential for a clean calculation. |
boolean |
factorize()
Performs binary factorization on the model if there are any simulation nodes with more than 3 parents.
This involves the model being recreated from scratch and all previously held references to pre-existing objects in the Model will become invalid and should be released. |
String |
getAvailableDataSetId(String prefix)
Generates a new DataSet ID that is guaranteed to be available at the return time.
|
DataSet |
getDataSet(String id)
Looks up and returns a DataSet by its ID.
|
List<DataSet> |
getDataSetList()
Returns DataSets of this Model as a list
|
Map<String,DataSet> |
getDataSets()
Returns a copy of ID-Network map.
|
Map<Id,? extends Identifiable> |
getIdMap(Class<? extends Identifiable> idClassType)
Deprecated.
For internal use only
|
org.json.JSONObject |
getJsonAudit()
Returns audit stored as JSON
|
org.json.JSONObject |
getJsonGraphics()
Returns model graphics stored as JSON
|
org.json.JSONArray |
getJsonPictures()
Returns Risk Map pictures stored as JSON
|
org.json.JSONArray |
getJsonTexts()
Returns Risk Map texts stored as JSON
|
uk.co.agena.minerva.model.Model |
getLogicModel()
Returns the underlying ExtendedBN.
|
Network |
getNetwork(String id)
Looks up and returns a Network by its ID.
|
List<Network> |
getNetworkList()
Returns Networks of this Model as a list
|
Map<String,Network> |
getNetworks()
Returns a copy of ID-Network map.
|
Settings |
getSettings()
Returns Model Settings object.
|
boolean |
isCalculated()
Checks whether the model had been successfully calculated and requires no calculation at this time.
Model is considered calculated if all Networks had been calculated. |
static Model |
loadModel(String path)
Loads a Model from provided path
|
protected void |
loadQuestionnaire(org.json.JSONObject jsonQstnr)
Loads a Questionnaire from JSON
|
protected void |
loadRiskTable(org.json.JSONArray jsonRiskTable)
Loads Risk Table from JSON into the current Model
|
boolean |
removeDataSet(DataSet dataSet)
Removes the provided DataSet from the model
|
void |
removeNetwork(Network net)
Removes provided Network from this Model, breaks any existing links to and from this Network.
|
void |
removeNetwork(String netId)
Removes provided Network from this Model, breaks any existing links to and from this Network.
|
void |
reset()
Reset the model by removing all Networks, Links, DataSets etc
|
void |
save(String path)
Saves the Model to a file path specified.
Output format is determined by path extension: • AgenaRisk 7 CMP for "cmp" • XML for "xml" • JSON for everything else |
void |
saveEssentials(String path,
boolean keepMeta)
Saves the Model as a light-weight JSON.
Keeps only elements essential for a clean calculation. Drops: Graphics, RiskTable, DataSets, compiled non-manual NPTs, names, notes and descriptions. |
protected void |
setLogicModel(uk.co.agena.minerva.model.Model logicModel)
Links this Model to an underlying Minerva Model object.
|
void |
throwIdExistsException(String id)
Deprecated.
For internal use only
|
void |
throwOldIdNullException(String id)
Deprecated.
For internal use only
|
org.json.JSONObject |
toJson()
Creates a JSON representing this Network, ready for file storage.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitchangeContainedIdpublic static Model loadModel(String path) throws ModelException
path - path to model fileModelException - if failed to read the file; or if JSON was corrupt or missing required attributes; or if CMP could not be converted to JSONpublic static Model createModel()
public static Model createModel(uk.co.agena.minerva.model.Model api1Model) throws ModelException
api1Model - the logical Minerva ModelModelException - if Minerva Model fails to be converted to JSONpublic static Model createModel(org.json.JSONObject json) throws ModelException, org.json.JSONException
json - JSONObject representing this model, including structure, tables, graphics etcModelException - if failed to create any of the componentsorg.json.JSONException - if JSON structure is invalid or inconsistentprotected void absorb(org.json.JSONObject json)
throws ModelException,
org.json.JSONException
json - JSONObject representing this model, including structure, tables, graphics etcModelException - if failed to create any of the componentsorg.json.JSONException - if JSON structure is invalid or inconsistentpublic Network createNetwork(org.json.JSONObject jsonNetwork) throws NetworkException
setTable(JSONObject) after all nodes, states, intra and cross network links had been created.jsonNetwork - JSONObject representing the network, including structure, tables, graphics etcNetworkException - if failed to create the NetworkNode.setTable(JSONObject)public Network createNetwork(org.json.JSONObject jsonNetwork, boolean withTables) throws NetworkException
setTable(JSONObject) after all nodes, states, intra and cross network links had been created.jsonNetwork - JSONObject representing the network, including structure, tables, graphics etcwithTables - whether to load node tables from JSONNetworkException - if failed to create the NetworkNode.setTable(JSONObject)public Network createNetwork(String id) throws NetworkException
id - unique ID of the NetworkNetworkException - if a Network with this ID already existspublic Network createNetwork(String id, String name) throws NetworkException
id - unique ID of the Networkname - non-unique name of the NetworkNetworkException - if a Network with this ID already existspublic void removeNetwork(Network net)
net - Network to removepublic void removeNetwork(String netId)
netId - ID of the Network to removepublic org.json.JSONObject toJson()
toJson in interface StorableAgenaRiskRuntimeException - if failed to convert model to JSON@Deprecated public Map<Id,? extends Identifiable> getIdMap(Class<? extends Identifiable> idClassType) throws ModelException
IdContainergetIdMap in interface IdContainer<ModelException>idClassType - the class of identifiable objectModelException - when invalid type requested@Deprecated public void throwIdExistsException(String id) throws ModelException
IdContainerthrowIdExistsException in interface IdContainer<ModelException>id - ID of the existing objectModelException - when invoked@Deprecated public void throwOldIdNullException(String id) throws ModelException
IdContainerthrowOldIdNullException in interface IdContainer<ModelException>id - ID of the existing objectModelException - when invokedpublic Network getNetwork(String id)
id - the ID of the Network to returnpublic Map<String,Network> getNetworks()
public List<Network> getNetworkList()
public uk.co.agena.minerva.model.Model getLogicModel()
public void calculate()
throws CalculationException
CalculationException - if calculation failedInconsistentEvidenceException - specifically in case inconsistent evidence was detectedpublic void calculate(Collection<Network> networks, Collection<DataSet> dataSets, Model.CalculationFlag... flags) throws CalculationException
networks - Networks to calculate, can be null for all NetworksdataSets - DataSets to calculate, can be null for all DataSetsflags - Calculation flagsCalculationException - if calculation failedInconsistentEvidenceException - specifically in case inconsistent evidence was detectedpublic void save(String path) throws FileIOException
path - the file path to save toFileIOException - if saving failspublic org.json.JSONObject export(Model.ExportFlag... flags) throws AdapterException
flags - flags specifying which attributes to keepAdapterException - if conversion to JSON failspublic void saveEssentials(String path, boolean keepMeta) throws FileIOException
path - the file path to save tokeepMeta - Keep meta, names, notes and descriptions of Model, Networks and NodesFileIOException - if saving failspublic DataSet createDataSet(String id) throws DataSetException
id - unique ID of the DataSetDataSetException - if a DataSet with this ID already existsprotected void loadRiskTable(org.json.JSONArray jsonRiskTable)
jsonRiskTable - the Risk Table dataprotected void loadQuestionnaire(org.json.JSONObject jsonQstnr)
jsonQstnr - the Questionnaire datapublic DataSet createDataSet(org.json.JSONObject jsonDataSet) throws ModelException
jsonDataSet - the JSON dataModelException - if a DataSet with this ID already exists or if JSON was corrupt or missing required attributespublic Map<String,DataSet> getDataSets()
public List<DataSet> getDataSetList()
public Link createLink(Node source, Node target, CrossNetworkLink.Type type) throws LinkException
source - Node to link fromtarget - Node to link totype - type of CrossNetworkLink; Type can not be CrossNetworkLink.Type.State, use createCrossNetworkLink(Node, Node, String) insteadLinkException - if Link already exists, or a cross network link is being created with invalid argumentspublic Link createLink(String sourceNetworkId, String sourceNodeId, String targetNetworkId, String targetNodeId, CrossNetworkLink.Type type) throws LinkException
sourceNetworkId - ID of source Network of the linksourceNodeId - ID of source Node of the linktargetNetworkId - ID of target Network of the linktargetNodeId - ID of target Node of the linktype - type of the message for the link to pass; Type can not be CrossNetworkLink.Type.State, use createCrossNetworkLink(Node, Node, String) insteadLinkException - if both Nodes are in the same Network; invalid Type given, or source Node already has incoming links or if Network with this ID does not existpublic Link createLink(Node source, Node target, State state) throws LinkException
source - source Node of the linktarget - target Node of the linkstate - the state from source Node for the link to pass to target NodeLinkException - if both Nodes are in the same Network; invalid state given, or source Node already has incoming linkspublic Link createLink(String sourceNetworkId, String sourceNodeId, String targetNetworkId, String targetNodeId, String stateLabel) throws ModelException
sourceNetworkId - ID of source Network of the linksourceNodeId - ID of source Node of the linktargetNetworkId - ID of target Network of the linktargetNodeId - ID of target Node of the linkstateLabel - the label of the state from source Node for the link to pass to target NodeModelException - if both Nodes are in the same Network; invalid state given, or source Node already has incoming linksNullPointerException - if Network with this ID does not existpublic org.json.JSONArray getJsonTexts()
public org.json.JSONArray getJsonPictures()
public org.json.JSONObject getJsonGraphics()
public org.json.JSONObject getJsonAudit()
protected void setLogicModel(uk.co.agena.minerva.model.Model logicModel)
logicModel - the logical modelpublic DataSet getDataSet(String id)
id - the ID of the DataSet to returnpublic boolean factorize()
throws ModelException
ModelException - if failed to factorizepublic boolean removeDataSet(DataSet dataSet)
dataSet - DataSet to removepublic void convertToStatic(DataSet dataSet) throws NodeException, AgenaRiskRuntimeException
dataSet - DataSet to use for creating static states from resultsAgenaRiskRuntimeException - if failed to regenerate NPTs after conversionNodeException - if failed for other reasonspublic void reset()
public Settings getSettings()
public boolean isCalculated()
Copyright © 2021. All rights reserved.