Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Steins algo #29

Open
wants to merge 36 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
cdecccd
init commit, code cleanup
Jan 29, 2023
788f7f3
used newer convention for modules
Jan 30, 2023
63e1233
Update README.md
legalup Jan 30, 2023
eb93296
Update README.md
legalup Feb 3, 2023
c4f2d6e
new graph classes. still, i think tests are incorrect
legalup1729 Feb 4, 2023
28798a9
Merge branch 'master' of github.com:legalup/rust-llama
legalup1729 Feb 4, 2023
eaa2f06
changed data representation of directed graph to something cleaner, s…
Feb 11, 2023
571f68e
udg now works too...as if by miracle
Feb 12, 2023
2576ee8
udg now works too...as if by miracle
Feb 12, 2023
bbb8db5
used internal edge weights for mst. alleviates need to understand dat…
Feb 13, 2023
6ee1d6a
Merge branch 'master' of github.com:legalup/rust-llama-cookbook
Feb 13, 2023
0f23b85
Merge branch 'master' of github.com:legalup/rust-llama-cookbook
Feb 13, 2023
b450889
Update README.md
legalup Feb 13, 2023
2f90101
Update README.md
legalup Feb 13, 2023
918a902
Update README.md
legalup Feb 13, 2023
72b75a1
Update README.md
legalup Feb 13, 2023
0fc219a
Update README.md
legalup Feb 13, 2023
267bdd2
Merge branch 'master' of github.com:legalup/rust-llama-cookbook
Feb 14, 2023
c9f67c0
changed edge of undirected graph to set
Feb 14, 2023
6c45242
changed edge of undirected graph to set
Feb 14, 2023
42c2c0e
cleaned up dijkstra impl
Feb 15, 2023
269f713
Merge branch 'master' of github.com:legalup/rust-llama-cookbook
Feb 15, 2023
f697e79
Merge branch 'master' of github.com:legalup/rust-llama-cookbook
Feb 15, 2023
097dd49
Merge branch 'master' of github.com:legalup/rust-llama-cookbook
Feb 15, 2023
9784cc7
floyd warshall algo
Feb 15, 2023
d306487
Update README.md
legalup Feb 15, 2023
f3cccbb
Update README.md
legalup Feb 15, 2023
6b73af7
Update README.md
legalup Feb 15, 2023
71efc8e
Update LICENSE
legalup Feb 15, 2023
e990191
Create LICENSE.md
legalup Feb 15, 2023
3357eda
Merge pull request #1 from legalup/add-license-1
legalup Feb 15, 2023
3840dd8
did licensing properly
legalup1729 Feb 15, 2023
3cb3131
added test for floyd warshall
legalup1729 Feb 16, 2023
fbce395
added levenshtein distance
legalup1729 Feb 17, 2023
8292e95
flakes
Apr 25, 2024
a44a043
adding steins algo for fast gcd computation
Dec 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions src/graph/connectivity.rs
Original file line number Diff line number Diff line change
@@ -195,7 +195,7 @@ impl<'a> ConnectivityUndirectedGraph<'a> {
}
self.is_articulation_point[u] = true;
}
} else if data.visited[v] < data.visited[u] && e != parent{
} else if data.visited[v] < data.visited[u] && e != parent {
data.lower(u, data.visited[v]);
data.e_stack.push(e);
} else if v == u {
@@ -297,13 +297,11 @@ mod test {
.filter(|&u| cg.is_cut_vertex(u))
.collect::<Vec<_>>();

for idx in 0..graph.num_e(){

if cg.is_cut_edge(idx){
println!(" edge {} is a cut edge",idx)
}
else{
println!(" edge {} is not a cut edge",idx)
for idx in 0..graph.num_e() {
if cg.is_cut_edge(idx) {
println!(" edge {} is a cut edge", idx)
} else {
println!(" edge {} is not a cut edge", idx)
}
}
assert_eq!(bridges, vec![0]);
@@ -323,7 +321,7 @@ mod test {
graph.add_edge(1, 6);

let cg = ConnectivityUndirectedGraph::new(&graph);

let articulation_points = (0..graph.num_v())
.filter(|&u| cg.is_cut_vertex(u))
.collect::<Vec<_>>();
7 changes: 6 additions & 1 deletion src/graph/flow.rs
Original file line number Diff line number Diff line change
@@ -177,7 +177,12 @@ impl FlowGraph {
}

// Pushes flow along an augmenting path of minimum cost.
fn min_cost_flow_augment(&self, t: usize, par: &[Option<usize>], flow: &mut [i64]) -> (i64, i64) {
fn min_cost_flow_augment(
&self,
t: usize,
par: &[Option<usize>],
flow: &mut [i64],
) -> (i64, i64) {
let (mut dc, mut df) = (0, Self::INF);
let mut u = t;
while let Some(e) = par[u] {
2 changes: 1 addition & 1 deletion src/graph/graph.rs
Original file line number Diff line number Diff line change
@@ -107,7 +107,7 @@ impl UndirectedGraph {

/// Adds a weighted edge from u to v.
pub fn add_weighted_edge(&mut self, u: usize, v: usize, w: i64) {
let undirected_edge = HashSet::from([u,v]);
let undirected_edge = HashSet::from([u, v]);
self.edges.push(undirected_edge);
self.edge_weights.push(w);
self.adj_lists[u].push((self.edges.len() - 1, v));
3 changes: 1 addition & 2 deletions src/graph/util.rs
Original file line number Diff line number Diff line change
@@ -27,7 +27,6 @@ impl DirectedGraph {

// Single-source shortest paths on a directed graph with non-negative weights
pub fn dijkstra(&self, u: usize) -> Vec<u64> {

let mut dist = vec![u64::max_value(); self.edge_weights.len()];
let mut heap = std::collections::BinaryHeap::new();

@@ -73,7 +72,7 @@ impl UndirectedGraph {
.into_iter()
.filter(|&e| {
let edge_vec = Vec::from_iter(&self.edges[e]);
components.merge(*edge_vec[0],*edge_vec[1])
components.merge(*edge_vec[0], *edge_vec[1])
})
.collect()
}