Commit 23fdb7ce authored by Guilhelm Savin's avatar Guilhelm Savin

Add more option for normalization in centrality measures.

parent ed28f227
......@@ -33,6 +33,7 @@ package org.graphstream.algorithm.measure.demo;
import org.graphstream.algorithm.generator.BarabasiAlbertGenerator;
import org.graphstream.algorithm.measure.ClosenessCentrality;
import org.graphstream.algorithm.measure.AbstractCentrality.NormalizationMode;
import org.graphstream.graph.Graph;
import org.graphstream.graph.implementations.AdjacencyListGraph;
......@@ -59,8 +60,8 @@ public class ClosenessCentralityDemo {
gen.nextEvents();
gen.end();
ClosenessCentrality cc = new ClosenessCentrality("ui.color", true,
true, true);
ClosenessCentrality cc = new ClosenessCentrality("ui.color",
NormalizationMode.MAX_1_MIN_0, true, true);
cc.init(g);
cc.compute();
......
......@@ -33,6 +33,7 @@ package org.graphstream.algorithm.measure.demo;
import org.graphstream.algorithm.generator.BarabasiAlbertGenerator;
import org.graphstream.algorithm.measure.DegreeCentrality;
import org.graphstream.algorithm.measure.AbstractCentrality.NormalizationMode;
import org.graphstream.graph.Graph;
import org.graphstream.graph.implementations.AdjacencyListGraph;
......@@ -59,7 +60,7 @@ public class DegreeCentralityDemo {
gen.nextEvents();
gen.end();
DegreeCentrality dc = new DegreeCentrality("ui.color", true);
DegreeCentrality dc = new DegreeCentrality("ui.color", NormalizationMode.MAX_1_MIN_0);
dc.init(g);
dc.compute();
......
......@@ -32,6 +32,7 @@
package org.graphstream.algorithm.measure.demo;
import org.graphstream.algorithm.generator.BarabasiAlbertGenerator;
import org.graphstream.algorithm.measure.AbstractCentrality.NormalizationMode;
import org.graphstream.algorithm.measure.EigenvectorCentrality;
import org.graphstream.graph.Graph;
import org.graphstream.graph.implementations.AdjacencyListGraph;
......@@ -55,11 +56,11 @@ public class EigenvectorCentralityDemo {
BarabasiAlbertGenerator gen = new BarabasiAlbertGenerator();
gen.addSink(g);
gen.begin();
for (int i = 0; i < 200; i++)
for (int i = 0; i < 100; i++)
gen.nextEvents();
gen.end();
EigenvectorCentrality dc = new EigenvectorCentrality("ui.color", true);
EigenvectorCentrality dc = new EigenvectorCentrality("ui.color", NormalizationMode.MAX_1_MIN_0);
dc.init(g);
dc.compute();
......
......@@ -41,6 +41,8 @@ import org.graphstream.graph.Node;
*
*/
public class ClosenessCentrality extends AbstractCentrality {
public static final String DEFAULT_ATTRIBUTE_KEY = "closeness";
/**
* Flag indicating if APSP should be computed in this algorithm. If false,
* user needs to compute APSP himself to provide {@link APSPInfo} object in
......@@ -61,7 +63,7 @@ public class ClosenessCentrality extends AbstractCentrality {
* Default construtor. Same as calling `ClosenessCentrality("closeness")`.
*/
public ClosenessCentrality() {
this("closeness");
this(DEFAULT_ATTRIBUTE_KEY);
}
/**
......@@ -72,7 +74,7 @@ public class ClosenessCentrality extends AbstractCentrality {
* attribute where centrality will be stored
*/
public ClosenessCentrality(String attribute) {
this(attribute, false);
this(attribute, NormalizationMode.NONE);
}
/**
......@@ -82,9 +84,9 @@ public class ClosenessCentrality extends AbstractCentrality {
* @param attribute
* attribute where centrality will be stored
* @param normalize
* if true, values will be normalized between 0 and 1
* defines the normalization mode
*/
public ClosenessCentrality(String attribute, boolean normalize) {
public ClosenessCentrality(String attribute, NormalizationMode normalize) {
this(attribute, normalize, true, false);
}
......@@ -94,13 +96,13 @@ public class ClosenessCentrality extends AbstractCentrality {
* @param centralityAttribute
* attribute where centrality will be stored
* @param normalize
* if true, centrality values will be normalized between 0 and 1
* defines the normalization mode
* @param computeAPSP
* if true, apsp will be computed in this algorithm
* @param useDangalchevMethod
* if true, Dangelchev method will be used in this algorithm
*/
public ClosenessCentrality(String centralityAttribute, boolean normalize,
public ClosenessCentrality(String centralityAttribute, NormalizationMode normalize,
boolean computeAPSP, boolean useDangalchevMethod) {
super(centralityAttribute, normalize);
this.computeAPSP = computeAPSP;
......
......@@ -36,12 +36,18 @@ public class DegreeCentrality extends AbstractCentrality {
INOUT, IN, OUT
}
public static final String DEFAULT_ATTRIBUTE_KEY = "degree";
/**
* Defines which degree should be used. It only get a sense with directed
* graph.
*/
protected Mode mode;
public DegreeCentrality() {
this(DEFAULT_ATTRIBUTE_KEY, NormalizationMode.NONE);
}
/**
* Constructor allowing configuration of centrality attribute and
* normalization flag. Mode will be {@link Mode#INOUT}.
......@@ -49,9 +55,9 @@ public class DegreeCentrality extends AbstractCentrality {
* @param attribute
* name of the attribute where centrality values will be stored
* @param normalize
* if true, centrality values will be normalized between 0 and 1
* defines the normalization mode
*/
public DegreeCentrality(String attribute, boolean normalize) {
public DegreeCentrality(String attribute, NormalizationMode normalize) {
this(attribute, normalize, Mode.INOUT);
}
......@@ -62,12 +68,13 @@ public class DegreeCentrality extends AbstractCentrality {
* @param attribute
* name of the attribute where centrality values will be stored
* @param normalize
* if true, centrality values will be normalized between 0 and 1
* defines the normalization mode
* @param mode
* set which degree should be used (in degree, out degree or
* both)
*/
public DegreeCentrality(String attribute, boolean normalize, Mode mode) {
public DegreeCentrality(String attribute, NormalizationMode normalize,
Mode mode) {
super(attribute, normalize);
this.mode = mode;
}
......
......@@ -37,17 +37,22 @@ import org.graphstream.graph.Edge;
import org.graphstream.graph.Node;
public class EigenvectorCentrality extends AbstractCentrality {
public static final String DEFAULT_ATTRIBUTE_KEY = "eigenvector";
public static final int DEFAULT_MAX_ITER = 100;
protected int maxIter;
protected String weightAttribute;
public EigenvectorCentrality(String attribute, boolean normalize) {
public EigenvectorCentrality() {
this("DEFAULT_ATTRIBUTE_KEY", NormalizationMode.NONE);
}
public EigenvectorCentrality(String attribute, NormalizationMode normalize) {
this(attribute, normalize, DEFAULT_MAX_ITER, "weight");
}
public EigenvectorCentrality(String attribute, boolean normalize,
public EigenvectorCentrality(String attribute, NormalizationMode normalize,
int maxIter, String weightAttribute) {
super(attribute, normalize);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment