Package ons.util
Class WeightedGraph
java.lang.Object
ons.util.WeightedGraph
- All Implemented Interfaces:
java.io.Serializable
- Direct Known Subclasses:
WeightedGraphLPCandidates
public class WeightedGraph
extends java.lang.Object
implements java.io.Serializable
A weighted graph associates a label (weight) with every edge in the graph.
If a pair of nodes has weight equal to zero, it means the edge between them
doesn't exist.
- See Also:
- Serialized Form
-
Field Summary
-
Constructor Summary
Constructors Constructor Description WeightedGraph(int n)
Creates a new WeightedGraph object with no edges,WeightedGraph(WeightedGraph g)
Creates a new WeightedGraph object, based on an already existing weighted graph. -
Method Summary
Modifier and Type Method Description void
addEdge(int source, int target, double w)
Creates a new edge within the graph, which requires its two vertexes and its weight.void
addNode()
Creates a new node in graph.double
getAverageClusteringCoefficient()
Retrieves the average clustering coefficient of this graph.double
getAveragePathLength()
Retrieves the Average path length of this graph.double
getClusteringCoefficient(int node)
Retrieves the clustering coefficient of this node.double
getGlobalClusteringCoefficient()
Retrieves the global clustering coefficient of this graph.double
getGraphDiameter()
Retrieves the diameter of this graph.double
getGraphDiameter_mod(int k)
Retornas a maior rota das k-5 menoresdouble
getMaxClusteringCoefficient()
Retrieves the max local clustering coefficient in this graph.double
getMaxPossiblePathWeight(int k)
Retrieves the max possible wheight by 'k' hopsdouble
getSumClusteringCoefficient()
Retrieves the sum of all local clustering coefficient in this graph.double
getWeight(int source, int target)
Retrieves the weight of a given edge on the graph.boolean
isEdge(int source, int target)
Says whether or not a given pair of nodes has an edge between them.int[]
neighbors(int vertex)
Retrieves the neighbors of a given vertex.int[]
neighbors2(int vertex)
Retrieves the neighbors of a given vertex.void
removeEdge(int source, int target)
Removes a given edge from the graph by simply attributing zero to its source and target coordinates within the matrix of edges.void
removeNode(int node)
Remove node in graphvoid
removeNodeEdge(int node)
Remode all edges nodevoid
setWeight(int source, int target, 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.java.lang.String
toString()
Prints all information related to the weighted graph.
-
Field Details
-
Constructor Details
-
WeightedGraph
public WeightedGraph(int n)Creates a new WeightedGraph object with no edges,- Parameters:
n
- number of nodes the new graph will have
-
WeightedGraph
Creates a new WeightedGraph object, based on an already existing weighted graph.- Parameters:
g
- the graph that will be copied into the new one
-
-
Method Details
-
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 graph
-
addEdge
public void addEdge(int source, int target, double w)Creates a new edge within the graph, which requires its two vertexes and its weight.- Parameters:
source
- the edge's source nodetarget
- the edge's destination nodew
- the value of the edge's weight
-
isEdge
public boolean isEdge(int source, int target)Says whether or not a given pair of nodes has an edge between them.- Parameters:
source
- the source nodetarget
- the destination node- Returns:
- true if the edge exists, or false otherwise
-
removeEdge
public void removeEdge(int source, int target)Removes a given edge from the graph by simply attributing zero to its source and target coordinates within the matrix of edges.- Parameters:
source
- the edge's source nodetarget
- the edge's destination node
-
getWeight
public double getWeight(int source, int target)Retrieves the weight of a given edge on the graph.- Parameters:
source
- the edge's source nodetarget
- the edge's destination node- Returns:
- the value of the edge's weight
-
setWeight
public void setWeight(int source, int target, double w)Sets a determined weight to a given edge on the graph.- Parameters:
source
- the edge's source nodetarget
- the edge's destination nodew
- the value of the weight
-
neighbors
public int[] neighbors(int vertex)Retrieves the neighbors of a given vertex. The vertices that are reachable by this vertex- Parameters:
vertex
- index of the vertex within the matrix of edges- Returns:
- list with indexes of the vertex's neighbors
-
neighbors2
public int[] neighbors2(int vertex)Retrieves the neighbors of a given vertex. The vertices that reach this vertex- Parameters:
vertex
- index of the vertex within the matrix of edges- Returns:
- list with indexes of the vertex's neighbors
-
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
-
removeNodeEdge
public void removeNodeEdge(int node)Remode all edges node- Parameters:
node
- the node
-
removeNode
public void removeNode(int node)Remove node in graph- Parameters:
node
- the node
-
addNode
public void addNode()Creates a new node in graph. -
getGraphDiameter
public double getGraphDiameter()Retrieves the diameter of this graph.- Returns:
- the longest of all the calculated shortest paths in a network
-
getGraphDiameter_mod
public double getGraphDiameter_mod(int k)Retornas a maior rota das k-5 menores- Returns:
- a maior rota das k-5 menores
-
getClusteringCoefficient
public double getClusteringCoefficient(int node)Retrieves the clustering coefficient of this node. The clustering coefficient of a node is the ratio of existing links connecting a node's neighbors to each other to the maximum possible number of such links.- Parameters:
node
- the node- Returns:
- the clustering coefficient
-
getMaxClusteringCoefficient
public double getMaxClusteringCoefficient()Retrieves the max local clustering coefficient in this graph.- Returns:
- the max local clustering coefficient
-
getSumClusteringCoefficient
public double getSumClusteringCoefficient()Retrieves the sum of all local clustering coefficient in this graph.- Returns:
- the sum of all local clustering coefficient
-
getAverageClusteringCoefficient
public double getAverageClusteringCoefficient()Retrieves the average clustering coefficient of this graph.- Returns:
- the average clustering coefficient
-
getGlobalClusteringCoefficient
public double getGlobalClusteringCoefficient()Retrieves the global clustering coefficient of this graph.- Returns:
- the global clustering coefficient
-
getAveragePathLength
public double getAveragePathLength()Retrieves the Average path length of this graph. Average path length is calculated by finding the shortest path between all pairs of nodes, adding them up, and then dividing by the total number of pairs.- Returns:
- the average path length of this graph
-
getMaxPossiblePathWeight
public double getMaxPossiblePathWeight(int k)Retrieves the max possible wheight by 'k' hops- Parameters:
k
- the k of YensKSP algorithm- Returns:
- the max possible weight
-