public class GrphBasedGraph extends Object implements GraphBuilder
| Modifier and Type | Field and Description |
|---|---|
protected ArrayList<Integer> |
edgeTypes |
protected int[] |
entranceNodes
Entrance nodes of this graph.
|
protected static int |
EXTERNAL_NODE_GRAPH_ID_INDEX
Index of the graph ID in the array used as value in
externalNodes. |
protected static int |
EXTERNAL_NODE_NODE_ID_INDEX
Index of the external node ID in the array used as value in
externalNodes. |
protected Map<Integer,int[]> |
externalNodes
Storage of additional information (graph ID and node ID in this graph) of
external nodes.
|
protected grph.Grph |
graph |
INTERNAL_NODE_GRAPH_ID| Constructor and Description |
|---|
GrphBasedGraph()
Constructor for an empty GraphBuilder.
|
GrphBasedGraph(Graph other)
Clones speficied graph's data into this GraphBuilder.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
addEdge(int sourceId,
int targetId,
int typeId)
Adds a new edge with the given information if possible.
|
int |
addNode()
Adds a new node to the graph and returns its ID.
|
boolean |
addNode(int nodeId)
Adds a new node with specified ID to the graph.
|
int[] |
addNodes(int nodeCount)
Adds the given number of nodes to the graph and returns the range of node
IDs.
|
private int |
getEdgeType(int edge)
Given an edge ID, returns type of that edge.
|
int[] |
getEntranceNodes()
Returns the IDs of the entrance nodes (i.e., nodes from which all other nodes
can be reached).
|
int |
getExternalNodeId(int nodeId)
Returns the ID of the node in the external graph if this node is an external
node.
|
int |
getGraphId(int nodeId)
Returns the ID of the graph the given node is part of.
|
int |
getNumberOfEdges()
Returns the number of edges of this graph.
|
int |
getNumberOfNodes()
Returns the number of nodes of this graph.
|
int[] |
incomingEdgeSources(int nodeId)
Returns an array containing the source node IDs of the edges that have the
given node as target.
|
int[] |
incomingEdgeTypes(int nodeId)
Returns an array containing the types of the incoming edges of the given
node.
|
private IntStream |
orderedIncomingEdges(int nodeId)
Returns a Stream containing edges that have the given node as target sorted
by edge ID.
|
private IntStream |
orderedOutgoingEdges(int nodeId)
Returns a Stream containing edges that have the given node as source sorted
by edge ID.
|
int[] |
outgoingEdgeTargets(int nodeId)
Returns an array containing the target node IDs of the edges that have the
given node as source.
|
int[] |
outgoingEdgeTypes(int nodeId)
Returns an array containing the types of the outgoing edges of the given
node.
|
void |
setEntranceNodes(int[] entranceNodes)
Sets the IDs of the entrance nodes (i.e., nodes from which all other nodes
can be reached).
|
void |
setGraphIdOfNode(int nodeId,
int graphId,
int externalId)
Sets the graph ID of the given node.
|
String |
toString() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitbuildprotected static final int EXTERNAL_NODE_GRAPH_ID_INDEX
externalNodes.protected static final int EXTERNAL_NODE_NODE_ID_INDEX
externalNodes.protected grph.Grph graph
protected int[] entranceNodes
public GrphBasedGraph()
public GrphBasedGraph(Graph other)
private int getEdgeType(int edge)
edge - the edge IDprivate IntStream orderedOutgoingEdges(int nodeId)
nodeId - the source node ID of the edgesprivate IntStream orderedIncomingEdges(int nodeId)
nodeId - the target node ID of the edgespublic int[] outgoingEdgeTargets(int nodeId)
GraphGraph.outgoingEdgeTypes(int) method.outgoingEdgeTargets in interface GraphnodeId - the source node ID of the edges for which the target IDs should be
returnedpublic int[] outgoingEdgeTypes(int nodeId)
GraphGraph.outgoingEdgeTargets(int) method.outgoingEdgeTypes in interface GraphnodeId - the source node ID of the edges for which the type IDs should be
returnedpublic int[] incomingEdgeSources(int nodeId)
GraphGraph.incomingEdgeTypes(int) method.incomingEdgeSources in interface GraphnodeId - the target node ID of the edges for which the source IDs should be
returnedpublic int[] incomingEdgeTypes(int nodeId)
GraphGraph.incomingEdgeSources(int) method.incomingEdgeTypes in interface GraphnodeId - the target node ID of the edges for which the type IDs should be
returnedpublic int getNumberOfNodes()
GraphgetNumberOfNodes in interface Graphpublic int getNumberOfEdges()
GraphgetNumberOfEdges in interface Graphpublic boolean addEdge(int sourceId,
int targetId,
int typeId)
GraphBuildertrue
if the edge could be added.addEdge in interface GraphBuildersourceId - the id of the source nodetargetId - the id of the target nodetypeId - the type id of the edgetrue if the edge could be added. Otherwise false is
returned.public int addNode()
GraphBuilderaddNode in interface GraphBuilderpublic boolean addNode(int nodeId)
true if the
node could be added.nodeId - the id of the nodetrue if the node could be added. Otherwise false is
returned.public int[] addNodes(int nodeCount)
GraphBuilderaddNodes in interface GraphBuildernodeCount - the number of nodes that should be addedpublic void setEntranceNodes(int[] entranceNodes)
GraphBuildersetEntranceNodes in interface GraphBuilderentranceNodes - the IDs of the entrance nodespublic int[] getEntranceNodes()
GraphgetEntranceNodes in interface Graphpublic int getGraphId(int nodeId)
GraphGraph.INTERNAL_NODE_GRAPH_ID=-1. If the given node is an
external node, i.e., the node is not part of this graph but there is an edge
from one of the internal nodes to this node, the method returns the ID of the
external graph.getGraphId in interface GraphnodeId - the ID of the node that should be checked.Graph.INTERNAL_NODE_GRAPH_ID=-1) or the ID of
the external graph the node belongs to.public int getExternalNodeId(int nodeId)
GraphgetExternalNodeId in interface GraphnodeId - the ID of the node that should be checked.public void setGraphIdOfNode(int nodeId,
int graphId,
int externalId)
GraphBuilderGraph.INTERNAL_NODE_GRAPH_ID as graph ID meaning that they are part of this
graph. However, to mark external nodes (i.e., nodes that are not part of this
graph but are linked from one of the nodes of this graph), this method can be
used to store their graph ID as well as their ID in the other graph.setGraphIdOfNode in interface GraphBuildernodeId - the ID of the node in this graphgraphId - the ID of the graph in the other graph. Use
Graph.INTERNAL_NODE_GRAPH_ID to delete the marking of a node being
external.externalId - the ID of this node inside the other graph (only used if the
graphID != Graph.INTERNAL_NODE_GRAPH_ID)Copyright © 2019–2020. All rights reserved.