Start to implement K-clustering

master
Felix Martin 2021-02-04 21:39:38 -05:00
parent a13fae6ceb
commit 12f8f2cf43
6 changed files with 18 additions and 1 deletions

3
.gitignore vendored
View File

@ -17,3 +17,6 @@ algos.sublime-workspace
# Data for the exercises. Some files are big so don't check them in.
data/c2a4.txt
data/c2a4.back.txt
data/c3a2_clustering.txt
data/c3a2_clustering_big.txt

BIN
misc/krustal_01.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 226 KiB

BIN
misc/krustal_02.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 123 KiB

BIN
misc/krustal_03.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 162 KiB

10
src/k_clustering.rs Normal file
View File

@ -0,0 +1,10 @@
use crate::prims::WeightedGraph;
use std::convert::TryInto;
pub fn k_clustering(graph: &WeightedGraph) -> i32 {
for vertex in graph {
println!("{:?}", vertex.edges.len());
}
graph.len().try_into().unwrap()
}

View File

@ -8,6 +8,7 @@ mod quick_sort;
mod ssc;
mod two_sum;
mod util;
mod k_clustering;
use crate::dijkstra::dijkstra;
use crate::heap::heap;
@ -18,6 +19,7 @@ use crate::prims::prims;
use crate::quick_sort::quick_sort;
use crate::ssc::ssc;
use crate::two_sum::find_two_sums;
use crate::k_clustering::k_clustering;
use std::cmp::min;
#[allow(dead_code)]
@ -103,7 +105,9 @@ fn c3a1() {
#[allow(dead_code)]
fn c3a2() {
println!("let's go");
let graph = util::read_weighted_graph("data/c3a2_clustering.txt").unwrap();
let r1 = k_clustering(&graph);
println!("r1 = {:?}", r1);
}
fn main() {