org.graphstream.algorithm

## Class Eccentricity

• java.lang.Object
• org.graphstream.algorithm.Eccentricity
• All Implemented Interfaces:
Algorithm

```public class Eccentricity
extends java.lang.Object
implements Algorithm```
Compute the eccentricity of a connected graph.

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).

## Requirements

This algorithm needs that APSP algorithm has been computed before its own computation.

## Example

``` 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
}
}
```
See Also:
`APSP.APSPInfo`
Computational Complexity:
O(n2)
Scientific Reference:
F. Harary, Graph Theory. Westview Press, Oct. 1969. [Online]. Available: http://www.amazon.com/exec/obidos/ redirect?tag=citeulike07-20\&path=ASIN/0201410338
• ### Constructor Summary

Constructors
Constructor and Description
`Eccentricity()`
Build a new eccentricity algorithm with default parameters.
`Eccentricity(java.lang.String eccentricityAttribute)`
Build a new eccentricity algorithm, specifying the attribute name of the computation result
```Eccentricity(java.lang.String eccentricityAttribute, java.lang.Object isInEccentricity, java.lang.Object isNotInEccentricity)```
Build a new eccentricity as in `Eccentricity(String)` but specifying values of eccentricity membership.
```Eccentricity(java.lang.String eccentricityAttribute, java.lang.Object isInEccentricity, java.lang.Object isNotInEccentricity, java.lang.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.
• ### Method Summary

All Methods
Modifier and Type Method and Description
`void` `compute()`
Run the algorithm.
`java.lang.String` `defaultResult()`
`java.lang.String` `getAPSPInfoAttribute()`
Get the APSP info attribute name.
`java.lang.String` `getEccentricityAttribute()`
Get the name of the attribute where computation result is stored.
`java.lang.Object` `getIsInEccentricityValue()`
Get the value of the eccentricity attribute when element is in the eccentricity.
`java.lang.Object` `getIsNotInEccentricityValue()`
Get the value of the eccentricity attribute when element is not in the eccentricity.
`void` `init(org.graphstream.graph.Graph graph)`
Initialization of the algorithm.
`void` `setAPSPInfoAttribute(java.lang.String attribute)`
Set the APSP info attribute name.
`void` `setEccentricityAttribute(java.lang.String eccentricityAttribute)`
Set the name of the attribute where computation result is stored.
`void` `setIsInEccentricityValue(java.lang.Object value)`
Set the value of the eccentricity attribute when element is in the eccentricity.
`void` `setIsNotInEccentricityValue(java.lang.Object value)`
Set the value of the eccentricity attribute when element is not in the eccentricity.
• ### Methods inherited from class java.lang.Object

`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`
• ### Constructor Detail

• #### Eccentricity

`public Eccentricity()`
Build a new eccentricity algorithm with default parameters.
• #### Eccentricity

`public Eccentricity(java.lang.String eccentricityAttribute)`
Build a new eccentricity algorithm, specifying the attribute name of the computation result
Parameters:
`eccentricityAttribute` - attribute name of the computation result.
• #### Eccentricity

```public Eccentricity(java.lang.String eccentricityAttribute,
java.lang.Object isInEccentricity,
java.lang.Object isNotInEccentricity)```
Build a new eccentricity as in `Eccentricity(String)` but specifying values of eccentricity membership.
Parameters:
`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.
• #### Eccentricity

```public Eccentricity(java.lang.String eccentricityAttribute,
java.lang.Object isInEccentricity,
java.lang.Object isNotInEccentricity,
java.lang.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.
Parameters:
`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 stored
• ### Method Detail

• #### init

`public void init(org.graphstream.graph.Graph graph)`
Description copied from interface: `Algorithm`
Initialization of the algorithm. This method has to be called before the `Algorithm.compute()` method to initialize or reset the algorithm according to the new given graph.
Specified by:
`init` in interface `Algorithm`
Parameters:
`graph` - The graph this algorithm is using.
• #### compute

`public void compute()`
Description copied from interface: `Algorithm`
Run the algorithm. The `Algorithm.init(Graph)` method has to be called before computing.
Specified by:
`compute` in interface `Algorithm`
See Also:
`Algorithm.init(Graph)`
• #### getAPSPInfoAttribute

`public java.lang.String getAPSPInfoAttribute()`
Get the APSP info attribute name.
Returns:
the name of the attribute where the APSP informations are stored.
• #### setAPSPInfoAttribute

`public void setAPSPInfoAttribute(java.lang.String attribute)`
Set the APSP info attribute name.
Parameters:
`attribute` - the name of the attribute where the APSP informations are stored.
• #### getIsInEccentricityValue

`public java.lang.Object getIsInEccentricityValue()`
Get the value of the eccentricity attribute when element is in the eccentricity. Default value is Boolean.TRUE.
Returns:
the value of elements eccentricity attribute when this element is in the eccentricity.
• #### setIsInEccentricityValue

`public void setIsInEccentricityValue(java.lang.Object value)`
Set the value of the eccentricity attribute when element is in the eccentricity. On computation, this value is used to set the eccentricity attribute.
Parameters:
`value` - the value of elements eccentricity attribute when this element is in the eccentricity.
• #### getIsNotInEccentricityValue

`public java.lang.Object getIsNotInEccentricityValue()`
Get the value of the eccentricity attribute when element is not in the eccentricity. Default value is Boolean.FALSE.
Returns:
the value of elements eccentricity attribute when this element is not in the eccentricity.
• #### setIsNotInEccentricityValue

`public void setIsNotInEccentricityValue(java.lang.Object value)`
Set the value of the eccentricity attribute when element is not in the eccentricity. On computation, this value is used to set the eccentricity attribute.
Parameters:
`value` - the value of elements eccentricity attribute when this element is not in the eccentricity.
• #### setEccentricityAttribute

`public void setEccentricityAttribute(java.lang.String eccentricityAttribute)`
Set the name of the attribute where computation result is stored.
Parameters:
`eccentricityAttribute` - the name of the element attribute where computation result is stored.
• #### defaultResult

`public java.lang.String defaultResult()`