public class Eccentricity extends Object implements Algorithm
In a graph G, if d(u,v) is the shortest length between two nodes u and v (ie the number of edges of the shortest path) let e(u) be the d(u,v) such that v is the farthest of u. Eccentricity of a graph G is a subgraph induced by vertices u with minimum e(u).
This algorithm needs that APSP algorithm has been computed before its own computation.
import java.io.StringReader; import java.io.IOException; import org.graphstream.algorithm.Centroid; import org.graphstream.graph.Graph; import org.graphstream.graph.implementations.DefaultGraph; import org.graphstream.stream.file.FileSourceDGS; // +--- E // A --- B --- C -- D -|--- F // +--- G public class EccentriciyTest { static String my_graph = "DGS004\n" + "my 0 0\n" + "an A \n" + "an B \n" + "an C \n" + "an D \n" + "an E \n" + "an F \n" + "an G \n" + "ae AB A B \n" + "ae BC B C \n" + "ae CD C D \n" + "ae DE D E \n" + "ae DF D F \n" + "ae DG D G \n"; public static void main(String[] args) throws IOException { Graph graph = new DefaultGraph("Centroid Test"); StringReader reader = new StringReader(my_graph); FileSourceDGS source = new FileSourceDGS(); source.addSink(graph); source.readAll(reader); APSP apsp = new APSP(); apsp.init(graph); apsp.compute(); Eccentricity eccentricity = new Eccentricity(); eccentricity.init(graph); eccentricity.compute(); for (Node n : graph.getEachNode()) { Boolean in = n.getAttribute("eccentricity"); System.out.printf("%s is%s in the eccentricity.\n", n.getId(), in ? "" : " not"); } // Output will be : // // A is not in the eccentricity // B is not in the eccentricity // C is in the eccentricity // D is not in the eccentricity // E is not in the eccentricity // F is not in the eccentricity // G is not in the eccentricity } }
APSP.APSPInfo
Modifier and Type | Field and Description |
---|---|
protected String |
apspInfoAttribute
Attribute in which APSPInfo are stored.
|
protected String |
eccentricityAttribute
Attribute to store eccentricity information.
|
protected Graph |
graph
The graph on which centroid is computed.
|
protected Object |
isInEccentricity
Value of the attribute if node is in the eccentricity.
|
protected Object |
isNotInEccentricity
Value of the attribute if node is not in the eccentricity.
|
Constructor and Description |
---|
Eccentricity()
Build a new eccentricity algorithm with default parameters.
|
Eccentricity(String eccentricityAttribute)
Build a new eccentricity algorithm, specifying the attribute name of the
computation result
|
Eccentricity(String eccentricityAttribute,
Object isInEccentricity,
Object isNotInEccentricity)
Build a new eccentricity as in
Eccentricity(String) but
specifying values of eccentricity membership. |
Eccentricity(String eccentricityAttribute,
Object isInEccentricity,
Object isNotInEccentricity,
String apspInfoAttribute)
Build a new eccentricity algorithm as in
Eccentricity(String, Object, Object) but specifying the name of
the attribute where the APSP informations are stored. |
Modifier and Type | Method and Description |
---|---|
void |
compute()
Run the algorithm.
|
String |
getAPSPInfoAttribute()
Get the APSP info attribute name.
|
String |
getEccentricityAttribute()
Get the name of the attribute where computation result is stored.
|
Object |
getIsInEccentricityValue()
Get the value of the eccentricity attribute when element is in the
eccentricity.
|
Object |
getIsNotInEccentricityValue()
Get the value of the eccentricity attribute when element is not in the
eccentricity.
|
void |
init(Graph graph)
Initialization of the algorithm.
|
void |
setAPSPInfoAttribute(String attribute)
Set the APSP info attribute name.
|
void |
setEccentricityAttribute(String eccentricityAttribute)
Set the name of the attribute where computation result is stored.
|
void |
setIsInEccentricityValue(Object value)
Set the value of the eccentricity attribute when element is in the
eccentricity.
|
void |
setIsNotInEccentricityValue(Object value)
Set the value of the eccentricity attribute when element is not in the
eccentricity.
|
protected String apspInfoAttribute
protected String eccentricityAttribute
protected Object isInEccentricity
protected Object isNotInEccentricity
public Eccentricity()
public Eccentricity(String eccentricityAttribute)
eccentricityAttribute
- attribute name of the computation result.public Eccentricity(String eccentricityAttribute, Object isInEccentricity, Object isNotInEccentricity)
Eccentricity(String)
but
specifying values of eccentricity membership.eccentricityAttribute
- attribute name of the computation result.isInEccentricity
- the value of elements eccentricity attribute when this element
is in the eccentricity.isNotInEccentricity
- the value of elements eccentricity attribute when this element
is not in the eccentricity.public Eccentricity(String eccentricityAttribute, Object isInEccentricity, Object isNotInEccentricity, String apspInfoAttribute)
Eccentricity(String, Object, Object)
but specifying the name of
the attribute where the APSP informations are stored.eccentricityAttribute
- attribute name of the computation result.isInEccentricity
- the value of elements eccentricity attribute when this element
is in the eccentricity.isNotInEccentricity
- the value of elements eccentricity attribute when this element
is not in the eccentricity.apspInfoAttribute
- the name of the attribute where the APSP informations are
storedpublic void init(Graph graph)
Algorithm
Algorithm.compute()
method to initialize or reset the algorithm according
to the new given graph.public void compute()
Algorithm
Algorithm.init(Graph)
method has to be called
before computing.compute
in interface Algorithm
Algorithm.init(Graph)
public String getAPSPInfoAttribute()
public void setAPSPInfoAttribute(String attribute)
attribute
- the name of the attribute where the APSP informations are
stored.public Object getIsInEccentricityValue()
public void setIsInEccentricityValue(Object value)
value
- the value of elements eccentricity attribute when this element
is in the eccentricity.public Object getIsNotInEccentricityValue()
public void setIsNotInEccentricityValue(Object value)
value
- the value of elements eccentricity attribute when this element
is not in the eccentricity.public String getEccentricityAttribute()
getIsInEccentricityValue()
if the
element is in the eccentricity, getIsNotInEccentricityValue()
else.public void setEccentricityAttribute(String eccentricityAttribute)
eccentricityAttribute
- the name of the element attribute where computation result is
stored.WebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses