aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com.example.portfolio3/com/example/portfolio3/EdgeGraph.java
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2025-04-26 19:32:53 +0200
committerJonas Smedegaard <dr@jones.dk>2025-04-26 19:32:53 +0200
commite4a0762c7a2ac3afb8e33bf24fd7495553b5819f (patch)
tree83d738e242670a4171cd20727f697744d05eaec8 /src/main/java/com.example.portfolio3/com/example/portfolio3/EdgeGraph.java
parent7f93e18b6424b292d4f54fb746aeb6e10b62e76d (diff)
use Maven idiomatic root path src/main/java
Diffstat (limited to 'src/main/java/com.example.portfolio3/com/example/portfolio3/EdgeGraph.java')
-rw-r--r--src/main/java/com.example.portfolio3/com/example/portfolio3/EdgeGraph.java37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/main/java/com.example.portfolio3/com/example/portfolio3/EdgeGraph.java b/src/main/java/com.example.portfolio3/com/example/portfolio3/EdgeGraph.java
new file mode 100644
index 0000000..ae9cbe9
--- /dev/null
+++ b/src/main/java/com.example.portfolio3/com/example/portfolio3/EdgeGraph.java
@@ -0,0 +1,37 @@
+package com.example.portfolio3;
+
+// origin: <https://moodle.ruc.dk/course/section.php?id=211877>
+
+/// EdgeGraph - One big set of all edges in the graph
+class EdgeGraph extends AbstractGraph {
+
+ /// foo
+ EdgeGraph() {}
+
+ /// foo
+ Set<Edge> edges=new HashSet<>();
+
+ /// foo
+ public void insertEdge(Vertex v1,Vertex v2,int w){
+ edges.add(new Edge(v1,v2,w));
+ }
+
+ /// foo
+ public Collection<Edge> edges(){return edges;}
+
+ /// foo
+ public Collection<Edge> outEdge(Vertex v){
+ ArrayList<Edge> outEdge=new ArrayList<>();
+ for(Edge e:edges)if(e.from()==v)outEdge.add(e);
+ return outEdge;
+ }
+
+ /// foo
+ public Integer getWeight(Vertex v1,Vertex v2){
+ // linear in number of edges in the graph
+ for(Edge e:edges){
+ if(e.from()==v1 && e.to()==v2)return e.weight();
+ }
+ return null;
+ }
+}