Skip to content

Commit 608bf8f

Browse files
committed
Merge pull request #40 from agouge/edge_ids
Add edge ids This will be important especially in irstv/gdms-topology when calculating edge betweenness. [I should add unit tests later.]
2 parents 573484f + 94f50ac commit 608bf8f

File tree

18 files changed

+125
-40
lines changed

18 files changed

+125
-40
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,4 @@ src/test/java/com/graphhopper/sna/centrality/examples/NantesAnalyzerTest.java
1717
.project
1818
.settings/
1919
java-network-analyzer.iml
20-
src/main/java/org/javanetworkanalyzer/alg/Alg.ucls
21-
20+
*.ucls

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>org.javanetworkanalyzer</groupId>
66
<artifactId>java-network-analyzer</artifactId>
7-
<version>0.1.2-SNAPSHOT</version>
7+
<version>0.1.2</version>
88
<packaging>bundle</packaging>
99

1010
<name>Java-Network-Analyzer</name>

src/main/java/org/javanetworkanalyzer/graphcreators/GraphCreator.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,8 @@
2525
package org.javanetworkanalyzer.graphcreators;
2626

2727
import org.javanetworkanalyzer.data.VId;
28-
import org.javanetworkanalyzer.model.DirectedPseudoG;
29-
import org.javanetworkanalyzer.model.Edge;
30-
import org.javanetworkanalyzer.model.KeyedGraph;
31-
import org.javanetworkanalyzer.model.PseudoG;
28+
import org.javanetworkanalyzer.model.*;
29+
3230
import java.io.BufferedReader;
3331
import java.io.File;
3432
import java.io.FileNotFoundException;
@@ -45,7 +43,7 @@
4543
*
4644
* @author Adam Gouge
4745
*/
48-
public class GraphCreator<V extends VId, E extends Edge> {
46+
public class GraphCreator<V extends VId, E extends EdgeID> {
4947

5048
/**
5149
* Start node column name.
@@ -107,7 +105,6 @@ public class GraphCreator<V extends VId, E extends Edge> {
107105
* Initializes a new {@link GraphCreator}.
108106
*
109107
* @param csvFile CSV file containing the edge information.
110-
* @param weightField The weight column name.
111108
* @param orientation The desired graph orientation.
112109
* @param vertexClass The vertex class
113110
* @param edgeClass The edge class

src/main/java/org/javanetworkanalyzer/graphcreators/WeightedGraphCreator.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,9 @@
2626

2727
import org.javanetworkanalyzer.data.VId;
2828
import static org.javanetworkanalyzer.graphcreators.GraphCreator.UNDIRECTED;
29-
import org.javanetworkanalyzer.model.DirectedWeightedPseudoG;
30-
import org.javanetworkanalyzer.model.Edge;
31-
import org.javanetworkanalyzer.model.KeyedGraph;
32-
import org.javanetworkanalyzer.model.WeightedKeyedGraph;
33-
import org.javanetworkanalyzer.model.WeightedPseudoG;
29+
30+
import org.javanetworkanalyzer.model.*;
31+
3432
import java.io.FileNotFoundException;
3533
import java.util.Scanner;
3634

src/main/java/org/javanetworkanalyzer/model/AsUndirectedG.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
*
3434
* @author Adam Gouge
3535
*/
36-
public class AsUndirectedG<V extends VId, E>
36+
public class AsUndirectedG<V extends VId, E extends EdgeID>
3737
// extends GraphDelegator<V, E>
3838
// implements Serializable,
3939
// UndirectedGraph<V, E>
@@ -54,7 +54,7 @@ public AsUndirectedG(DirectedG<V, E> g)
5454
@Override
5555
public boolean addVertex(int id) {
5656
throw new UnsupportedOperationException("Adding vertices to "
57-
+ " an as-undirected graph is not currently supported.");
57+
+ " an as-undirected graph is not supported.");
5858
}
5959

6060
@Override
@@ -65,6 +65,12 @@ public V getVertex(int id) {
6565
@Override
6666
public E addEdge(int source, int target) {
6767
throw new UnsupportedOperationException("Adding edges to "
68-
+ " an as-undirected graph is not currently supported.");
68+
+ " an as-undirected graph is not supported.");
69+
}
70+
71+
@Override
72+
public E addEdge(int source, int target, int edgeID) {
73+
throw new UnsupportedOperationException("Adding edges to "
74+
+ " an as-undirected graph is not supported.");
6975
}
7076
}

src/main/java/org/javanetworkanalyzer/model/AsUnweightedDirectedG.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
*
3232
* @author Adam Gouge
3333
*/
34-
public class AsUnweightedDirectedG<V extends VId, E>
34+
public class AsUnweightedDirectedG<V extends VId, E extends EdgeID>
3535
// extends GraphDelegator<V, E>
3636
// implements Serializable, DirectedGraph<V, E>
3737
extends AsUnweightedDirectedGraph<V, E>
@@ -52,7 +52,7 @@ public AsUnweightedDirectedG(DirectedG<V, E> g)
5252
public boolean addVertex(int id) {
5353
throw new UnsupportedOperationException(
5454
"Adding vertices to an as-unweighted-undirected graph is not "
55-
+ "currently supported.");
55+
+ "supported.");
5656
}
5757

5858
@Override
@@ -64,6 +64,13 @@ public V getVertex(int id) {
6464
public E addEdge(int source, int target) {
6565
throw new UnsupportedOperationException(
6666
"Adding edges to an as-unweighted-undirected graph is not "
67-
+ "currently supported.");
67+
+ "supported.");
68+
}
69+
70+
@Override
71+
public E addEdge(int source, int target, int edgeID) {
72+
throw new UnsupportedOperationException(
73+
"Adding edges to an as-unweighted-undirected graph is not "
74+
+ "supported.");
6875
}
6976
}

src/main/java/org/javanetworkanalyzer/model/AsUnweightedG.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
*
3434
* @author Adam Gouge
3535
*/
36-
public class AsUnweightedG<V extends VId, E>
36+
public class AsUnweightedG<V extends VId, E extends EdgeID>
3737
// extends GraphDelegator<V, E>
3838
// implements Serializable
3939
extends AsUnweightedGraph<V, E>
@@ -54,7 +54,7 @@ public AsUnweightedG(KeyedGraph<V, E> g)
5454
public boolean addVertex(int id) {
5555
throw new UnsupportedOperationException(
5656
"Adding vertices to an as-unweighted graph is not "
57-
+ "currently supported.");
57+
+ "supported.");
5858
}
5959

6060
@Override
@@ -66,6 +66,13 @@ public V getVertex(int id) {
6666
public E addEdge(int source, int target) {
6767
throw new UnsupportedOperationException(
6868
"Adding edges to an as-unweighted graph is not "
69-
+ "currently supported.");
69+
+ "supported.");
70+
}
71+
72+
@Override
73+
public E addEdge(int source, int target, int edgeID) {
74+
throw new UnsupportedOperationException(
75+
"Adding edges to an as-unweighted graph is not "
76+
+ "supported.");
7077
}
7178
}

src/main/java/org/javanetworkanalyzer/model/DirectedG.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@
3131
*
3232
* @author Adam Gouge
3333
*/
34-
public interface DirectedG<V, E> extends DirectedGraph<V, E>, KeyedGraph<V, E> {
34+
public interface DirectedG<V, E extends EdgeID> extends DirectedGraph<V, E>, KeyedGraph<V, E> {
3535
}

src/main/java/org/javanetworkanalyzer/model/DirectedPseudoG.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
*
4040
* @author Adam Gouge
4141
*/
42-
public class DirectedPseudoG<V extends VId, E>
42+
public class DirectedPseudoG<V extends VId, E extends EdgeID>
4343
extends DirectedPseudograph<V, E>
4444
implements DirectedG<V, E> {
4545

@@ -107,13 +107,20 @@ public V getVertex(int id) {
107107
}
108108

109109
@Override
110-
public E addEdge(int source, int target) {
110+
public E addEdge(int source, int target, int edgeID) {
111111
if (!containsVertex(getVertex(source))) {
112112
addVertex(source);
113113
}
114114
if (!containsVertex(getVertex(target))) {
115115
addVertex(target);
116116
}
117-
return addEdge(getVertex(source), getVertex(target));
117+
final E e = addEdge(getVertex(source), getVertex(target));
118+
e.setID(edgeID);
119+
return e;
120+
}
121+
122+
@Override
123+
public E addEdge(int source, int target) {
124+
return addEdge(source, target, -1);
118125
}
119126
}

src/main/java/org/javanetworkanalyzer/model/Edge.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,13 @@
3232
*
3333
* @author Adam Gouge
3434
*/
35-
public class Edge<E extends Edge<E>> extends DefaultWeightedEdge
36-
implements EdgeSPT<E> {
35+
public class Edge<E extends Edge> extends DefaultWeightedEdge
36+
implements EdgeSPT<E>, EdgeID {
3737

3838
private double weight = WeightedGraph.DEFAULT_EDGE_WEIGHT;
3939
private E baseGraphEdge;
40+
private int id;
41+
private boolean setID = false;
4042

4143
/**
4244
* Sets the weight of this edge.
@@ -60,4 +62,19 @@ public E getBaseGraphEdge() {
6062
public void setBaseGraphEdge(E edgeCent) {
6163
baseGraphEdge = edgeCent;
6264
}
65+
66+
@Override
67+
public int getID() {
68+
return id;
69+
}
70+
71+
@Override
72+
public void setID(int id) {
73+
if (!setID) {
74+
this.id = id;
75+
setID = true;
76+
} else {
77+
throw new IllegalStateException("Cannot set the edge id more than once.");
78+
}
79+
}
6380
}

0 commit comments

Comments
 (0)