forked from kodecocodes/swift-algorithm-club
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add project for SSSP with Bellman-Ford implementation
- Loading branch information
1 parent
495303b
commit dd3ba8d
Showing
15 changed files
with
1,059 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
Single-Source Shortest Paths (Weighted)/SSSP.playground/Contents.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import Graph | ||
import SSSP | ||
|
||
let graph = AdjacencyMatrixGraph<String>() | ||
let s = graph.createVertex("s") | ||
let t = graph.createVertex("t") | ||
let x = graph.createVertex("x") | ||
let y = graph.createVertex("y") | ||
let z = graph.createVertex("z") | ||
|
||
graph.addDirectedEdge(s, to: t, withWeight: 6) | ||
graph.addDirectedEdge(s, to: y, withWeight: 7) | ||
|
||
graph.addDirectedEdge(t, to: x, withWeight: 5) | ||
graph.addDirectedEdge(t, to: y, withWeight: 8) | ||
graph.addDirectedEdge(t, to: z, withWeight: -4) | ||
|
||
graph.addDirectedEdge(x, to: t, withWeight: -2) | ||
|
||
graph.addDirectedEdge(y, to: x, withWeight: -3) | ||
graph.addDirectedEdge(y, to: z, withWeight: 9) | ||
|
||
graph.addDirectedEdge(z, to: s, withWeight: 2) | ||
graph.addDirectedEdge(z, to: x, withWeight: 7) | ||
|
||
let result = BellmanFord<String>.apply(graph, source: s)! | ||
|
||
let path = result.path(z, inGraph: graph) |
4 changes: 4 additions & 0 deletions
4
Single-Source Shortest Paths (Weighted)/SSSP.playground/contents.xcplayground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
<playground version='5.0' target-platform='osx'> | ||
<timeline fileName='timeline.xctimeline'/> | ||
</playground> |
7 changes: 7 additions & 0 deletions
7
...Shortest Paths (Weighted)/SSSP.playground/playground.xcworkspace/contents.xcworkspacedata
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.