2020-11-17 03:12:09 +01:00
|
|
|
mod merge_sort;
|
2020-12-04 01:52:15 +01:00
|
|
|
mod min_cut;
|
2020-11-20 02:37:42 +01:00
|
|
|
mod quick_sort;
|
2020-12-01 22:17:16 +01:00
|
|
|
mod ssc;
|
2020-11-27 18:14:35 +01:00
|
|
|
mod util;
|
2020-11-20 02:37:42 +01:00
|
|
|
|
2020-11-27 21:23:14 +01:00
|
|
|
use crate::util::read_to_graph;
|
2020-12-04 17:43:03 +01:00
|
|
|
use std::cmp::min;
|
2020-12-04 01:52:15 +01:00
|
|
|
|
|
|
|
use crate::merge_sort::merge_sort_inversions;
|
2020-11-28 18:59:14 +01:00
|
|
|
use crate::min_cut::min_cut;
|
2020-11-20 02:37:42 +01:00
|
|
|
use crate::quick_sort::quick_sort;
|
2020-12-01 22:17:16 +01:00
|
|
|
use crate::ssc::ssc;
|
2020-12-04 01:52:15 +01:00
|
|
|
use crate::util::read_to_directed_graph;
|
|
|
|
use crate::util::read_to_vector;
|
2020-11-17 02:24:01 +01:00
|
|
|
|
2020-11-20 02:37:42 +01:00
|
|
|
#[allow(dead_code)]
|
2020-11-17 03:12:09 +01:00
|
|
|
fn c1a2() {
|
2020-11-20 02:37:42 +01:00
|
|
|
let vec = read_to_vector("data/course_1_assignment_2.txt").unwrap();
|
2020-11-17 03:12:09 +01:00
|
|
|
let (_sorted, inversions) = merge_sort_inversions(vec);
|
|
|
|
println!("course 1 assignment 2: {:?}", inversions);
|
2020-11-13 20:48:47 +01:00
|
|
|
}
|
|
|
|
|
2020-11-20 14:19:59 +01:00
|
|
|
#[allow(dead_code)]
|
2020-11-20 02:37:42 +01:00
|
|
|
fn c1a3() {
|
2020-11-20 14:19:59 +01:00
|
|
|
let mut vec = read_to_vector("data/course_1_assignment_3.txt").unwrap();
|
2020-11-20 02:37:42 +01:00
|
|
|
let mut comp_acc: usize = 0;
|
|
|
|
quick_sort(&mut vec, &mut comp_acc);
|
2020-11-20 14:19:59 +01:00
|
|
|
println!("course 1 assignment 3: {:?}", comp_acc);
|
2020-12-04 17:43:03 +01:00
|
|
|
// 1: 162085, 2: 164123, 3: 138382
|
2020-11-20 02:37:42 +01:00
|
|
|
}
|
|
|
|
|
2020-11-28 18:59:14 +01:00
|
|
|
#[allow(dead_code)]
|
2020-11-27 18:14:35 +01:00
|
|
|
fn c1a4() {
|
2020-12-04 01:52:15 +01:00
|
|
|
let g = read_to_graph("data/course_1_assignment_4.txt").unwrap();
|
|
|
|
let mut smalles_min_cut = u32::MAX;
|
|
|
|
let iterations = g.nodes.len().pow(1);
|
|
|
|
for _ in 0..iterations {
|
|
|
|
let new_min_cut = min_cut(g.clone());
|
|
|
|
if new_min_cut < smalles_min_cut {
|
|
|
|
smalles_min_cut = new_min_cut;
|
|
|
|
}
|
|
|
|
}
|
2020-12-04 17:43:03 +01:00
|
|
|
// 17
|
2020-12-04 01:52:15 +01:00
|
|
|
println!("course 1 assignment 4: {:?}", smalles_min_cut);
|
2020-11-27 18:14:35 +01:00
|
|
|
}
|
|
|
|
|
2020-12-01 22:17:16 +01:00
|
|
|
#[allow(dead_code)]
|
|
|
|
fn c2a1() {
|
2020-12-04 17:43:03 +01:00
|
|
|
// I have not checked in the graph file, because it has 70MB. This is a tiny test example.
|
2020-12-04 03:35:58 +01:00
|
|
|
let g = read_to_directed_graph("data/course_2_assignment_1_test.txt").unwrap();
|
2020-12-04 17:40:35 +01:00
|
|
|
let sizes = ssc(g.0, g.1);
|
|
|
|
let max_size = min(sizes.len(), 5);
|
|
|
|
println!("{:?}", &sizes[0..max_size]);
|
2020-12-04 17:43:03 +01:00
|
|
|
// [434821, 968, 459, 313, 211]
|
2020-12-01 22:17:16 +01:00
|
|
|
}
|
|
|
|
|
2020-11-13 20:48:47 +01:00
|
|
|
fn main() {
|
2020-11-27 18:14:35 +01:00
|
|
|
// c1a2();
|
|
|
|
// c1a3();
|
2020-12-01 22:17:16 +01:00
|
|
|
// c1a4();
|
|
|
|
c2a1();
|
2020-11-13 20:48:47 +01:00
|
|
|
}
|