|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectbcds.phison.GraphUtil
public abstract class GraphUtil
This class provides utility functions for creating new graph object, computing a number of metrics, writing or reading topology files, among others.
By design, this is a non-instantiatable class. All public methods must be static.
Constructor Summary | |
---|---|
GraphUtil()
|
Method Summary | ||
---|---|---|
static
|
assortativity(SimGraph<V,E> g)
Returns graph's assortativity coefficient. |
|
static
|
asUndirectedGraph(SimGraph<V,E> g)
Returns a new subgraph in which the edges are only those considered as canonic in the graph g . |
|
static
|
booleanRandomTrafficMatrix(SimGraph<V,E> g,
java.util.Random rnd)
Generates a random traffic matrix consisting of 0s and 1s. |
|
static
|
canonicEdge(SimGraph<V,E> g,
E e)
Deprecated. It is better to use g.canonicEdge(e) directly. |
|
static
|
clusteringCoefficients(SimGraph<V,E> g)
Deprecated. New code should use the ClusteringCoeff class directly. |
|
static
|
constantEdgeCost(SimGraph<V,E> g,
double c)
Returns a HashMap in which the keys are the edges of graph g , all of them with value c . |
|
static
|
createGraphReader(java.lang.String fname,
SimGraph<V,E> g)
Instantiates a new graph reader based on the filename extension. |
|
static
|
createGraphWriter(java.io.PrintStream out,
java.lang.String ftype,
SimGraph<V,E> g)
Creates a GraphWriter tied to a
java.io.PrintStream object. |
|
static
|
createGraphWriter(java.lang.String fname,
SimGraph<V,E> g)
Instantiates a new graph writer based on the filename extension. |
|
static
|
createGraphWriter(java.io.Writer out,
java.lang.String ftype,
SimGraph<V,E> g)
Creates a GraphWriter tied to a
java.io.Writer object. |
|
static
|
createNodeLabelToIdMap(SimGraph<V,E> g)
Returns a HashMap that associats node labels to node ids, as in ("Athens" : 0), ("Berlin" : 14), etc. |
|
static
|
fillWithLatticeTopology(SimGraph<V,E> g,
int num_rows,
int num_cols)
Removes all the links and nodes in the graph g and inserts
new ones so that the result is a two-dimensional grid topology
(a lattice). |
|
static
|
fillWithRingTopology(SimGraph<V,E> g,
int num_nodes)
Removes all the links and nodes in the graph g and inserts
new ones so that the result is ring topology. |
|
static
|
filterOutBidiLinks(SimGraph<V,E> g,
Path<V,E> path)
Returns a subgraph in which the edges of path do not appear. |
|
static
|
filterOutIntermediateNodes(SimGraph<V,E> g,
Path<V,E> path)
Returns a subgraph in which the non-end of path
are absent. |
|
static
|
isStronglyConnected(SimGraph<V,E> g)
Returns true if g is a strongly-connected graph
and false otherwise. |
|
static
|
networkDiameter(SimGraph<V,E> g)
Returns information about the network diameter and shortest path lengths when the link cost is 1, that is, when path length is measured in number of hops. |
|
static
|
networkDiameter(SimGraph<V,E> g,
java.util.Map<E,N> cost)
Computes the network diameter and the average path length, and returns information about these two measures in an array. |
|
static
|
newGraph(java.lang.Class<V> node_cls,
java.lang.Class<E> link_cls)
Creates a new graph whose nodes and links will be of the given types. |
|
static
|
nodalDegreeFreq(SimGraph<V,E> g)
Returns the frequency distribution of the nodal degrees of the graph g . |
|
static
|
pathContainsBidiLink(SimGraph<V,E> g,
E e,
Path<V,E> path)
Returns true if path contains the link e ,
either as e itself or as reverse(e). |
|
static
|
reverseEdge(SimGraph<V,E> g,
E e)
Deprecated. Better use g.reverseEdge() directly. |
|
static
|
splitProtAndUnprotParts(Path<V,E> pri,
Path<V,E> sec)
Given two paths pri and sec , of which the first
is the primary path
and the second the backup path, returns pri
split into two segments, the unprotected and protected parts. |
|
static
|
twoTerminalReliability(SimGraph<V,E> g)
Returns the average two-terminal reliability. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public GraphUtil()
Method Detail |
---|
public static <V,E> SimGraph<V,E> newGraph(java.lang.Class<V> node_cls, java.lang.Class<E> link_cls)
SdiGraph
.
public static <V,E> E reverseEdge(SimGraph<V,E> g, E e)
e
.
public static <V,E> E canonicEdge(SimGraph<V,E> g, E e)
e
.
public static <V,E> SimGraph<V,E> asUndirectedGraph(SimGraph<V,E> g)
g
.
Beware that the returned graph is not, strictly speaking, undirected; it is just graph in which each pair of neighbours has at most one directed link.
The subgraph is created by calling
SimGraph.createSubgraph(java.util.Set
.
public static <V,E> SimGraph<V,E> filterOutBidiLinks(SimGraph<V,E> g, Path<V,E> path)
path
do not appear.
If the edges in path
have two directions, both are removed.
The subgraph is created by calling
SimGraph.createSubgraph(java.util.Set
.
public static <V,E> SimGraph<V,E> filterOutIntermediateNodes(SimGraph<V,E> g, Path<V,E> path)
path
are absent. If path consists of only one link,
no "intermediate" node exists, and so no nodes are excluded
from the output.
The subgraph is created by calling
SimGraph.createSubgraph(java.util.Set
.
public static <V,E> SimplePair<Path<V,E>,Path<V,E>> splitProtAndUnprotParts(Path<V,E> pri, Path<V,E> sec)
pri
and sec
, of which the first
is the primary path
and the second the backup path, returns pri
split into two segments, the unprotected and protected parts.
Example:
a ---- b ----- c ---- d ---- e ---- f ---- g ---- h ---- i \ / \ / n ---- m ------ o ---- pIn this example, node c is the split point, whereas g is the merge point. The two parts returned are:
sec
must "touch" the path pri
at exactly
two nodes.
Note the objects returned are of type bcds.phison.Path, but the caller must see them simply as list of edges. In particular, as the example illustrates, the unprotected part in fact more than one subpath.
java.lang.IllegalArgumentException
- if sec does not comply with
the requirement that it has exactly two nodes in common with pri.public static <V,E> boolean pathContainsBidiLink(SimGraph<V,E> g, E e, Path<V,E> path)
path
contains the link e
,
either as e itself or as reverse(e).
If path is null, returns false.
public static <V,E,N extends java.lang.Number> java.lang.Object[] networkDiameter(SimGraph<V,E> g, java.util.Map<E,N> cost)
cost
.
The returned array elements are:
This method is a wrapper on Diameter
.
public static <V,E> java.lang.Object[] networkDiameter(SimGraph<V,E> g)
networkDiameter(SimGraph, Map)
.
public static <V,E> java.util.Map<V,java.lang.Float> clusteringCoefficients(SimGraph<V,E> g)
ClusteringCoeff
.
public static <V,E> java.util.Map<E,java.lang.Double> constantEdgeCost(SimGraph<V,E> g, double c)
g
, all of them with value c
.
This method should be used when it is anticipated that the
values in the map will change. If they will not, it is more
efficient to use an instance of
MapToConst
.
public static <V,E> boolean isStronglyConnected(SimGraph<V,E> g)
g
is a strongly-connected graph
and false otherwise. It uses
ConnectedComponents
.
public static <V,E> java.util.Map<SimplePair<V,V>,java.lang.Double> booleanRandomTrafficMatrix(SimGraph<V,E> g, java.util.Random rnd)
rnd
is not null, that object is
used to draw random numbers. Otherwise, Math.ramdom()
The returned matrix is not symmetric, that is, the traffic between the pair (a, b) might not match that of the pair (b, a).
public static <V,E> FreqTable<java.lang.Integer> nodalDegreeFreq(SimGraph<V,E> g)
g
. It is assumed that g is directed
and that both directions of each link are present.
public static <V extends GraphIONode,E> GraphReader<V,E> createGraphReader(java.lang.String fname, SimGraph<V,E> g)
fname
is stdin, that is, -, the
new reader object references Java's System.in.
Please note that generic parameter V, the type of
nodes, must be a class that implements
GraphIONode
. Otherwise, the compiler
reports that the method does not exist. The same is applicable
to createGraphWriter(java.lang.String, bcds.phison.SimGraph
.
java.lang.IllegalArgumentException
- if the file type cannot be determined,
for example because the filename does not include an "extension".public static <V extends GraphIONode,E> GraphWriter<V,E> createGraphWriter(java.lang.String fname, SimGraph<V,E> g)
fname
is stdout, that is, -, the
new reader object references Java's System.in.
java.lang.IllegalArgumentException
- if the file type cannot be determined,
for example because the filename does not include an "extension".
java.io.IOException
- wrapped in a AnyException if any
IOException occurs during object instantiation.public static <V extends GraphIONode,E> GraphWriter<V,E> createGraphWriter(java.io.PrintStream out, java.lang.String ftype, SimGraph<V,E> g)
GraphWriter
tied to a
java.io.PrintStream object. This method is equivalent to
createGraphWriter(new OutputStreamWriter(out), ftype, g).
public static <V extends GraphIONode,E> GraphWriter<V,E> createGraphWriter(java.io.Writer out, java.lang.String ftype, SimGraph<V,E> g)
GraphWriter
tied to a
java.io.Writer object. The parameter ftype
indicates the "extension", for example ".net" or ".sgf", not
a filenane. The supported extensions are the ones given
in createGraphWriter(String, SimGraph)
.
This method calls
createGraphWriter(Writer, String, SimGraph)
and thus
throws the same exceptions thrown there.
note that a dot is expected in ftype
. Thus,
".sgf" is recognized while "sgf" is not.
public static <V,E> void fillWithLatticeTopology(SimGraph<V,E> g, int num_rows, int num_cols)
g
and inserts
new ones so that the result is a two-dimensional grid topology
(a lattice).
public static <V,E> void fillWithRingTopology(SimGraph<V,E> g, int num_nodes)
g
and inserts
new ones so that the result is ring topology.
public static <V extends GraphIONode,E> java.util.Map<java.lang.String,java.lang.String> createNodeLabelToIdMap(SimGraph<V,E> g)
public static <V,E> float twoTerminalReliability(SimGraph<V,E> g)
AvgTwoTermReliability
.
public static <V,E> double assortativity(SimGraph<V,E> g)
Assortativity
.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |