public class Node extends Object implements Networked<Node>, Comparable<Node>, Identifiable<NodeException>, Storable, Named
| Modifier and Type | Class and Description |
|---|---|
static class |
Node.Field
This is set of fields for input/output to XML and JSON format
|
static class |
Node.Type
These are Node types that correspond to AgenaRisk Desktop node types
|
| Modifier and Type | Method and Description |
|---|---|
protected boolean |
addLink(Link link)
Removes the Link object from the linksOut list.
|
int |
compareTo(Node o)
Compares this Node object to another based on the Id of this object.
|
boolean |
convertToSimulated()
Enables calculation simulation for the Node (only possible for ContinuousInterval or IntegerInterval nodes).
|
boolean |
convertToStatic(DataSet dataSet)
Disables simulation and converts dynamic states from the results of the provided DataSet into static permanent states.
Any VariableObservations in the DataSet will replace current Node variable defaults and will be replaced from the DataSet observations. |
protected static Node |
createNode(Network network,
org.json.JSONObject jsonNode)
Factory method to create a Node for use by the Network class.
|
protected static Node |
createNode(Network network,
org.json.JSONObject jsonNode,
boolean withTables)
Factory method to create a Node for use by the Network class.
|
protected static Node |
createNode(Network network,
String id,
String name,
Node.Type type)
Factory method to be called by a Network object that is trying to add a Node to itself.
|
Variable |
createVariable(String varName,
double defaultValue)
Creates a new node Variable.
|
boolean |
equals(Object obj)
Checks equality of a given object to this Node.
|
List<String> |
getAllowedFunctionTokens()
Returns a list of parent IDs, variable names etc to use as parseable function tokens.
|
Set<Node> |
getAncestors()
Builds and returns a set of ancestors for this Node.
Does not include itself. Does not follow cross-network links (only includes Nodes in the same Network). |
Set<Node> |
getChildren()
Builds and returns a set of Node's children, which is valid at the time of request.
|
Set<Node> |
getDescendants()
Builds and returns a set of descendants for this Node.
Does not include itself. Does not follow cross-network links (only includes Nodes in the same Network). |
String |
getDescription()
Gets the description of this node
|
String |
getId()
Gets the ID of this Node.
|
List<Link> |
getLinksIn()
Returns a copy of the list of incoming Links.
|
List<Link> |
getLinksOut()
Returns a copy of the list of outgoing Links.
|
uk.co.agena.minerva.model.extendedbn.ExtendedNode |
getLogicNode()
Returns the underlying ExtendedNode.
|
String |
getName()
Gets the name of this node.
|
Network |
getNetwork()
Returns the Network containing this Node.
|
Set<Node> |
getParents()
Builds and returns a set of Node's parents, which is valid at the time of request.
|
State |
getState(String label)
Find a state by given label in this Node's underlying logic node.
|
List<State> |
getStates()
Returns a representation of Node's states at the time of the request.
The list will not be updated to reflect any changes, and no changes to the list or the States will be reflected in the Model. |
NodeConfiguration.TableType |
getTableType()
Returns the type of the table configured for the Node.
Possible values are: • Manual • Expression • Partitioned |
Node.Type |
getType()
Gets the Type of this Node.
|
Variable |
getVariable(String varName)
Retrieves and returns the Variable by name.
|
List<Variable> |
getVariables()
Gets an unmodifiable list of all Variables.
Will not reflect Variables being added or deleted from the Node. |
int |
hashCode()
Returns a hash code value for this object.
|
boolean |
isConnectedInput()
Returns true if this Node has an incoming link from another Network.
|
boolean |
isConnectedOutput()
Returns true if this Node has an outgoing link to another Network.
|
boolean |
isNumericInterval()
Returns true if the Node is continuous or integer interval
|
boolean |
isSimulated()
Returns true if the Node is simulated and false otherwise.
|
Link |
linkFrom(Node parent)
Creates a simple Link from the given Node to this Node in the same Network.
|
static void |
linkNodes(Model model,
org.json.JSONArray jsonLinks)
Creates links from the given JSON.
|
static Link |
linkNodes(Node fromNode,
Node toNode)
Creates a simple Link between two nodes in the same Network.
|
static Link |
linkNodes(Node fromNode,
Node toNode,
CrossNetworkLink.Type type)
Creates a Link between two nodes in same or different Networks.
|
static Link |
linkNodes(Node fromNode,
Node toNode,
CrossNetworkLink.Type type,
String stateToPass)
Creates a Link between two nodes in same or different Networks.
|
Link |
linkTo(Node child)
Creates a simple Link from this Node to given Node in the same Network.
|
protected uk.co.agena.minerva.model.extendedbn.ExtendedNodeFunction |
parseAsFunction(String expression,
List<String> allowedTokens,
boolean relaxFunctionRequirements)
Parses the provided expression as an ExtendedNodeFunction
|
void |
partitionByParents(List<Node> partitionParents)
Sets node partitions based on the parent states.
|
protected boolean |
removeLink(Link link)
Removes the Link object from the linksOut list.
|
void |
removeVariable(String varName)
Removes Variable by name if it exists
|
void |
resetTable()
Attempts to reset node's table
|
void |
setDescription(String description)
Sets the description of this Node.
|
void |
setId(String newId)
Changes the ID of this Node to the provided ID, if the new ID is not already taken.
|
protected void |
setLogicNode(uk.co.agena.minerva.model.extendedbn.ExtendedNode logicNode)
Links this Node to an underlying Minerva Node object.
|
void |
setName(String name)
Sets the name of this Node.
|
void |
setStates(org.json.JSONArray jsonStates)
Replaces Node's states by the ones given in the JSON array.
|
void |
setStates(List<String> states)
Replaces Node's states by the ones given in the array.
|
void |
setStates(String[] states)
Replaces Node's states by the ones given in the array.
|
void |
setTable(org.json.JSONObject jsonTable)
Replaces the Node's probability table with one specified in the given JSON.
|
void |
setTableColumns(double[][] columns)
Sets the manual NPT according to columns provided.
|
void |
setTableFunction(String expression)
Sets Node function to the one provided.
|
void |
setTableFunction(String expression,
List<String> allowedTokens)
Sets Node function to the one provided.
|
protected void |
setTableFunction(String expression,
List<String> allowedTokens,
boolean relaxFunctionRequirements)
Sets Node function to the one provided.
|
void |
setTableFunctions(List<String> expressions,
List<Node> partitionParents)
Sets Node expressions to the ones provided.
|
protected void |
setTableFunctions(List<String> expressions,
List<String> allowedTokens,
boolean relaxFunctionRequirements,
List<Node> partitionParents)
Sets Node expressions to the ones provided.
|
void |
setTableRows(double[][] rows)
Sets the manual NPT according to rows provided.
|
boolean |
setTableUniform()
Resets the node NPT to a uniform table.
|
org.json.JSONObject |
toJson()
Creates a JSON representing this Node, ready for file storage.
|
String |
toString()
Returns JSON equivalent of this Node as a String.
|
String |
toStringExtra()
Returns `network`.`node` String representing this Node.
|
boolean |
unlink(Node linkedNode)
Removes a link between this Node and the linkedNode, if such link exists.
|
static boolean |
unlinkNodes(Node node1,
Node node2)
Checks that there is a Link between two nodes and destroys it.
|
clone, finalize, getClass, notify, notifyAll, wait, wait, waithasAncestor, hasDescendantpublic List<Link> getLinksIn()
getLinksIn in interface Networked<Node>public List<Link> getLinksOut()
getLinksOut in interface Networked<Node>public Set<Node> getParents()
getParents in interface Networked<Node>public Set<Node> getChildren()
getChildren in interface Networked<Node>protected final boolean addLink(Link link)
link - the Link to removeprotected final boolean removeLink(Link link)
link - the Link to removepublic Link linkTo(Node child) throws LinkException
child - the child NodeLinkException - if Link already exists, or a cross network link is being created (use Node.linkNodes() for that instead)public Link linkFrom(Node parent) throws LinkException
parent - the parent NodeLinkException - if Link already exists, or a cross network link is being created (use Node.linkNodes() for that instead)public static boolean unlinkNodes(Node node1, Node node2)
node1 - Node 1node2 - Node 2public static void linkNodes(Model model, org.json.JSONArray jsonLinks) throws org.json.JSONException, LinkException, NodeException
model - the model to create Links injsonLinks - configuration of the Linksorg.json.JSONException - if JSON structure is invalid or inconsistentLinkException - if a Link fails to be createdNodeException - if failed to create a link between nodespublic static Link linkNodes(Node fromNode, Node toNode) throws LinkException
fromNode - Node to link fromtoNode - Node to link toLinkException - if Link already exists, or a cross network link is being createdpublic static Link linkNodes(Node fromNode, Node toNode, CrossNetworkLink.Type type) throws LinkException
fromNode - Node to link fromtoNode - Node to link totype - type of CrossNetworkLink if applicableLinkException - if Link already exists, or a cross network link is being created with invalid argumentspublic static Link linkNodes(Node fromNode, Node toNode, CrossNetworkLink.Type type, String stateToPass) throws LinkException
fromNode - Node to link fromtoNode - Node to link totype - type of CrossNetworkLink if applicablestateToPass - if type is State, this specifies the state to passLinkException - if Link already exists, or a cross network link is being created with invalid argumentsprotected static Node createNode(Network network, String id, String name, Node.Type type)
network - the network to add a node toid - the ID of the nodename - the name of the nodetype - type of the Node to createprotected static Node createNode(Network network, org.json.JSONObject jsonNode) throws NodeException, org.json.JSONException
setTable(JSONObject) after all nodes, states, intra and cross network links had been created.network - Network that the Node will be added tojsonNode - configuration of the NodeNodeException - if failed to create the nodeorg.json.JSONException - if JSON configuration is incomplete or invalidsetTable(JSONObject)protected static Node createNode(Network network, org.json.JSONObject jsonNode, boolean withTables) throws NodeException, org.json.JSONException
setTable(JSONObject) after all nodes, states, intra and cross network links had been created.network - Network that the Node will be added tojsonNode - configuration of the NodewithTables - whether to load node tables from JSONNodeException - if failed to create the nodeorg.json.JSONException - if JSON configuration is incomplete or invalidsetTable(JSONObject)public void setTableColumns(double[][] columns)
throws NodeException
columns - 2D array where first dimension are the columns and second dimension are the cellsNodeException - if provided table size is wrong or Node does not allow manual NPTpublic void setTableRows(double[][] rows)
throws NodeException
rows - 2D array where first dimension are the rows and second dimension are the cellsNodeException - if provided table size is wrong or Node does not allow manual NPTpublic final boolean setTableUniform()
public void resetTable()
throws NodeException
NodeException - upon failurepublic void setTable(org.json.JSONObject jsonTable)
throws NodeException
jsonTable - configuration of the table in JSON formatNodeException - if:
public void setTableFunction(String expression) throws NodeException
expression - function to setNodeException - if function is invalidpublic List<String> getAllowedFunctionTokens()
public void setTableFunction(String expression, List<String> allowedTokens) throws NodeException
expression - function to setallowedTokens - list of parent IDs, variable names etc to add as parseable tokens; if null, all tokens are allowedNodeException - if function is invalidprotected void setTableFunction(String expression, List<String> allowedTokens, boolean relaxFunctionRequirements) throws NodeException
expression - function to setallowedTokens - list of parent IDs, variable names etc to add as parseable tokens; if null, all tokens are allowedrelaxFunctionRequirements - if true, all function requirements are lifted and any number of arguments are allowedNodeException - if function is invalidprotected uk.co.agena.minerva.model.extendedbn.ExtendedNodeFunction parseAsFunction(String expression, List<String> allowedTokens, boolean relaxFunctionRequirements)
expression - function to setallowedTokens - list of parent IDs, variable names etc to add as parseable tokens; if null, all tokens are allowedrelaxFunctionRequirements - if true, all function requirements are lifted and any number of arguments are allowedpublic void setTableFunctions(List<String> expressions, List<Node> partitionParents) throws NodeException
partitionByParents(java.util.List)expressions - expressions to setpartitionParents - discrete parents to partition byNodeException - if a function is invalidprotected void setTableFunctions(List<String> expressions, List<String> allowedTokens, boolean relaxFunctionRequirements, List<Node> partitionParents) throws NodeException
expressions - expressions to setallowedTokens - list of parent IDs, variable names etc to add as parseable tokens; if null, all tokens are allowedrelaxFunctionRequirements - if true, all function requirements are lifted and any number of arguments are allowedpartitionParents - discrete parents to partition by, ignored if null or emptyNodeException - if a function is invalidpublic void partitionByParents(List<Node> partitionParents) throws NodeException
partitionParents - parents to partition byNodeException - if one of the nodes in partitionParents is simulated or is not a parent of this Nodepublic void setStates(String[] states) throws NodeException
states - new Node's statesNodeException - if state is an invalid range; or if the Node is simulatedpublic void setStates(List<String> states) throws NodeException
states - new Node's statesNodeException - if state is an invalid range; or if the Node is simulatedpublic void setStates(org.json.JSONArray jsonStates)
throws NodeException
jsonStates - new Node's statesNodeException - if state is an invalid range; or if the Node is simulatedpublic boolean convertToSimulated()
throws NodeException
NodeExceptionpublic boolean convertToStatic(DataSet dataSet) throws NodeException
dataSet - DataSet to use for creating static states from resultsNodeException - if states could not be created from the DataSet resultspublic boolean isSimulated()
public boolean isNumericInterval()
public String toString()
public String toStringExtra()
public Network getNetwork()
public uk.co.agena.minerva.model.extendedbn.ExtendedNode getLogicNode()
public String getId()
getId in interface Identifiable<NodeException>public void setId(String newId) throws NodeException
setId in interface Identifiable<NodeException>newId - the new IDNodeException - if fails to change IDpublic void setName(String name)
public String getName()
public void setDescription(String description)
setDescription in interface Nameddescription - new descriptionpublic String getDescription()
getDescription in interface Namedpublic int compareTo(Node o)
compareTo in interface Comparable<Node>o - another Node objectpublic boolean equals(Object obj)
public int hashCode()
public boolean unlink(Node linkedNode)
public org.json.JSONObject toJson()
public State getState(String label)
label - label of the required statepublic List<State> getStates()
public Node.Type getType()
protected void setLogicNode(uk.co.agena.minerva.model.extendedbn.ExtendedNode logicNode)
logicNode - the logical nodepublic NodeConfiguration.TableType getTableType()
public boolean isConnectedInput()
public boolean isConnectedOutput()
public Set<Node> getAncestors()
public Set<Node> getDescendants()
public Variable createVariable(String varName, double defaultValue) throws NetworkException
varName - unique Variable name, only number, letters and underscores are allowed, but can't be just a numberdefaultValue - default value of the VariableNodeException - if a Variable with this name already exists in this NodeNetworkExceptionpublic Variable getVariable(String varName)
varName - name of the Variable to returnpublic void removeVariable(String varName)
varName - name of the Variable to removeCopyright © 2021. All rights reserved.