Start to implement K-clustering
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -17,3 +17,6 @@ algos.sublime-workspace
|
|||||||
# Data for the exercises. Some files are big so don't check them in.
|
# Data for the exercises. Some files are big so don't check them in.
|
||||||
data/c2a4.txt
|
data/c2a4.txt
|
||||||
data/c2a4.back.txt
|
data/c2a4.back.txt
|
||||||
|
data/c3a2_clustering.txt
|
||||||
|
data/c3a2_clustering_big.txt
|
||||||
|
|
||||||
|
|||||||
BIN
misc/krustal_01.png
Normal file
BIN
misc/krustal_01.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 226 KiB |
BIN
misc/krustal_02.png
Normal file
BIN
misc/krustal_02.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 123 KiB |
BIN
misc/krustal_03.png
Normal file
BIN
misc/krustal_03.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 162 KiB |
10
src/k_clustering.rs
Normal file
10
src/k_clustering.rs
Normal 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()
|
||||||
|
}
|
||||||
|
|
||||||
@@ -8,6 +8,7 @@ mod quick_sort;
|
|||||||
mod ssc;
|
mod ssc;
|
||||||
mod two_sum;
|
mod two_sum;
|
||||||
mod util;
|
mod util;
|
||||||
|
mod k_clustering;
|
||||||
|
|
||||||
use crate::dijkstra::dijkstra;
|
use crate::dijkstra::dijkstra;
|
||||||
use crate::heap::heap;
|
use crate::heap::heap;
|
||||||
@@ -18,6 +19,7 @@ use crate::prims::prims;
|
|||||||
use crate::quick_sort::quick_sort;
|
use crate::quick_sort::quick_sort;
|
||||||
use crate::ssc::ssc;
|
use crate::ssc::ssc;
|
||||||
use crate::two_sum::find_two_sums;
|
use crate::two_sum::find_two_sums;
|
||||||
|
use crate::k_clustering::k_clustering;
|
||||||
use std::cmp::min;
|
use std::cmp::min;
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
@@ -103,7 +105,9 @@ fn c3a1() {
|
|||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
fn c3a2() {
|
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() {
|
fn main() {
|
||||||
|
|||||||
Reference in New Issue
Block a user