Package ons.util
Class LayeredGraph
java.lang.Object
ons.util.LayeredGraph
public class LayeredGraph
extends java.lang.Object
The "layered graph" is constructed from some weighted graphs your edges is
constructed between layers (weighted graphs).
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
LayeredGraph.LayeredGraphEdges
The edges between layers in LayeredGraph. -
Constructor Summary
Constructors Constructor Description LayeredGraph(int l, int n)
Creates a new LayeredGraph object with no edges in any layer,LayeredGraph(java.util.ArrayList<WeightedGraph> graphs)
Creates a new LayeredGraph object, based on an already existing weighteds graphs.LayeredGraph(java.util.ArrayList<WeightedGraph> graphs, java.util.ArrayList<java.lang.Long> tags)
Creates a new LayeredGraph object, based on an already existing weighteds graphs and put its tags.LayeredGraph(WeightedGraph eletricalLayer, WeightedGraph subTransponderLayer, WeightedGraph transponderLayer)
Creates a new LayeredGraph object, based on an already existing weighteds graphs. -
Method Summary
Modifier and Type Method Description void
addEdge(int layerSource, int layerTarget, int nodeSource, int nodeTarget, double w)
Creates a new edge between layer, which requires two layers, two vertexes and its weight.void
addLayer(WeightedGraph l)
Creates a new layer in LayeredGraph.WeightedGraph
getBigGraph()
Get WeightedGraph from the LayeredGraph.WeightedMultiGraph
getBigGraph2()
java.util.ArrayList<LayeredGraph.LayeredGraphEdges>
getEdges(int layerSource, int layerTarget)
Get the edges connecting a pair of layers.WeightedGraph
getLayer(int l)
Retrieves the layer of the LayeredGraph.long
getLayerGraphTag(int layer)
Retrieves the tag of this layer.int
getNumberLayer()
Retrieves the number of layers of the LayeredGraph.int[]
getShortestPath(int src, int dst)
Get shortest Path from the layered graph using the Dijkstra and it is assumed that the source and destination are in the first layer of the graph.double
getWeight(int layerSource, int layerTarget, int nodeSource, int nodeTarget)
Retrieves the weight of a given edge on the graph.boolean
isEdge(int layerSource, int layerTarget)
Says to exist or not an edge connecting a pair of layers.boolean
isEdge(int layer, int nodeSource, int nodeTarget)
Says to exist or not an edge connecting a pair of nodes in this layer.boolean
isEdge(int layerSource, int layerTarget, int nodeSource, int nodeTarget)
Says to exist or not an edge connecting a pair of nodes from different layers.int[]
mapping(int node)
Maps the node in bigGraph for layer and node in LayeredGraph.void
removeEdge(int layerSource, int layerTarget, int nodeSource, int nodeTarget)
Removes a given edge from the graph by simply attributingvoid
removeEdge(LayeredGraph.LayeredGraphEdges edge)
Removes a given edge from the graph by simply attributingvoid
removeEdgeLayer(int l)
Remove all edges connecting this layervoid
removeEdgeLayerNode(int l, int n)
Remove all edges connecting this node in this layervoid
removeLayer(int layer)
Remove layer in graphvoid
setLayerGraphTag(int layer, long tag)
Set the tag in this specific layer.void
setWeight(int layerSource, int layerTarget, int nodeSource, int nodeTarget, double w)
Sets a determined weight to a given edge on the graph.int
size()
Retrieves the size of the graph, i.e., the amount of vertexes it has.int
size(int l)
Retrieves the size of the graph in layer, i.e., the amount of vertexes it has.java.lang.String
toString()
Prints all information related to the weighted graph.
-
Constructor Details
-
LayeredGraph
public LayeredGraph(int l, int n)Creates a new LayeredGraph object with no edges in any layer,- Parameters:
l
- number of layers the new graph will haven
- number of nodes the each graph will have
-
LayeredGraph
Creates a new LayeredGraph object, based on an already existing weighteds graphs.- Parameters:
graphs
- the graph that will be copied into the new one
-
LayeredGraph
public LayeredGraph(java.util.ArrayList<WeightedGraph> graphs, java.util.ArrayList<java.lang.Long> tags)Creates a new LayeredGraph object, based on an already existing weighteds graphs and put its tags.- Parameters:
graphs
- the graph that will be copied into the new onetags
- the tags of each layer
-
LayeredGraph
public LayeredGraph(WeightedGraph eletricalLayer, WeightedGraph subTransponderLayer, WeightedGraph transponderLayer)Creates a new LayeredGraph object, based on an already existing weighteds graphs. The layered graph with 3 layers: Eletrical layer, Sub-transponder layer and Transponder layer.- Parameters:
eletricalLayer
- the Eletrical layersubTransponderLayer
- the Sub-transponder layertransponderLayer
- the Transponder layer
-
-
Method Details
-
getLayerGraphTag
public long getLayerGraphTag(int layer)Retrieves the tag of this layer.- Parameters:
layer
- the layer- Returns:
- the tag of this layer.
-
setLayerGraphTag
public void setLayerGraphTag(int layer, long tag)Set the tag in this specific layer.- Parameters:
layer
- the layer where will be set the tagtag
- the tag that will be set
-
size
public int size()Retrieves the size of the graph, i.e., the amount of vertexes it has.- Returns:
- integer with the quantity of nodes in the all graphs
-
size
public int size(int l)Retrieves the size of the graph in layer, i.e., the amount of vertexes it has.- Parameters:
l
- the layer- Returns:
- integer with the quantity of nodes in the layer
-
addLayer
Creates a new layer in LayeredGraph.- Parameters:
l
- the layer
-
getNumberLayer
public int getNumberLayer()Retrieves the number of layers of the LayeredGraph.- Returns:
- the numeber of layers
-
getLayer
Retrieves the layer of the LayeredGraph.- Parameters:
l
- the layer- Returns:
- the layer
-
addEdge
public void addEdge(int layerSource, int layerTarget, int nodeSource, int nodeTarget, double w)Creates a new edge between layer, which requires two layers, two vertexes and its weight.- Parameters:
layerSource
- the layer sourcelayerTarget
- the layer destinationnodeSource
- the node source in WeightedGraph "layerSource"nodeTarget
- the node destination in WeightedGraph "layerTarget"w
- the value of the edge's weight
-
isEdge
public boolean isEdge(int layerSource, int layerTarget)Says to exist or not an edge connecting a pair of layers.- Parameters:
layerSource
- the source layerlayerTarget
- the destination layer- Returns:
- true if the edge exists, or false otherwise
-
isEdge
public boolean isEdge(int layerSource, int layerTarget, int nodeSource, int nodeTarget)Says to exist or not an edge connecting a pair of nodes from different layers.- Parameters:
layerSource
- the source layerlayerTarget
- the destination layernodeSource
- the node source in WeightedGraph "layerSource"nodeTarget
- the node destination in WeightedGraph "layerTarget"- Returns:
- true if the edge exists, or false otherwise
-
isEdge
public boolean isEdge(int layer, int nodeSource, int nodeTarget)Says to exist or not an edge connecting a pair of nodes in this layer.- Parameters:
layer
- the layernodeSource
- the node source in WeightedGraph "layerSource"nodeTarget
- the node destination in WeightedGraph "layerTarget"- Returns:
- true if the edge exists, or false otherwise
-
getEdges
public java.util.ArrayList<LayeredGraph.LayeredGraphEdges> getEdges(int layerSource, int layerTarget)Get the edges connecting a pair of layers.- Parameters:
layerSource
- the source layerlayerTarget
- the destination layer- Returns:
- the edges
-
removeEdge
public void removeEdge(int layerSource, int layerTarget, int nodeSource, int nodeTarget)Removes a given edge from the graph by simply attributing- Parameters:
layerSource
- the source layerlayerTarget
- the destination layernodeSource
- the node source in WeightedGraph "layerSource"nodeTarget
- the node destination in WeightedGraph "layerTarget"
-
removeEdge
Removes a given edge from the graph by simply attributing- Parameters:
edge
- the edge
-
getWeight
public double getWeight(int layerSource, int layerTarget, int nodeSource, int nodeTarget)Retrieves the weight of a given edge on the graph.- Parameters:
layerSource
- the source layerlayerTarget
- the destination layernodeSource
- the node source in WeightedGraph "layerSource"nodeTarget
- the node destination in WeightedGraph "layerTarget"- Returns:
- the value of the edge's weight
-
setWeight
public void setWeight(int layerSource, int layerTarget, int nodeSource, int nodeTarget, double w)Sets a determined weight to a given edge on the graph.- Parameters:
layerSource
- the source layerlayerTarget
- the destination layernodeSource
- the node source in WeightedGraph "layerSource"nodeTarget
- the node destination in WeightedGraph "layerTarget"w
- the value of the weight
-
toString
public java.lang.String toString()Prints all information related to the weighted graph. For each vertex, shows the vertexes is is adjacent to and the weight of each edge.- Overrides:
toString
in classjava.lang.Object
- Returns:
- string containing the edges of each vertex
-
removeEdgeLayer
public void removeEdgeLayer(int l)Remove all edges connecting this layer- Parameters:
l
- the layer
-
removeEdgeLayerNode
public void removeEdgeLayerNode(int l, int n)Remove all edges connecting this node in this layer- Parameters:
l
- the layern
- the node
-
removeLayer
public void removeLayer(int layer)Remove layer in graph- Parameters:
layer
- the layer
-
getBigGraph
Get WeightedGraph from the LayeredGraph.- Returns:
- the WeightedGraph from this LayeredGraph
-
getBigGraph2
-
getShortestPath
public int[] getShortestPath(int src, int dst)Get shortest Path from the layered graph using the Dijkstra and it is assumed that the source and destination are in the first layer of the graph.- Parameters:
src
-dst
-- Returns:
-
mapping
public int[] mapping(int node)Maps the node in bigGraph for layer and node in LayeredGraph.- Parameters:
node
- the node- Returns:
- the array with 2 positions: the layer and the node
-