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