Start to implement c3a1
parent
bc5e250fd8
commit
026625a7cb
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,17 @@
|
|||
#[derive(Debug)]
|
||||
pub struct Job {
|
||||
pub weight: u32,
|
||||
pub length: u32,
|
||||
}
|
||||
|
||||
pub type Jobs = Vec<Job>;
|
||||
|
||||
|
||||
fn weighted_completion_time(jobs: &Jobs) -> usize {
|
||||
|
||||
jobs.len()
|
||||
}
|
||||
|
||||
pub fn jobs1(jobs: &Jobs) -> usize {
|
||||
weighted_completion_time(&jobs)
|
||||
}
|
11
src/main.rs
11
src/main.rs
|
@ -6,6 +6,8 @@ mod quick_sort;
|
|||
mod ssc;
|
||||
mod util;
|
||||
mod two_sum;
|
||||
mod jobs;
|
||||
mod prims;
|
||||
|
||||
use std::cmp::min;
|
||||
use crate::dijkstra::dijkstra;
|
||||
|
@ -15,6 +17,8 @@ use crate::min_cut::min_cut;
|
|||
use crate::quick_sort::quick_sort;
|
||||
use crate::ssc::ssc;
|
||||
use crate::two_sum::find_two_sums;
|
||||
use crate::jobs::jobs1;
|
||||
use crate::prims::prims;
|
||||
|
||||
|
||||
#[allow(dead_code)]
|
||||
|
@ -87,7 +91,12 @@ fn c2a4() {
|
|||
|
||||
#[allow(dead_code)]
|
||||
fn c3a1() {
|
||||
println!("continue here");
|
||||
let jobs = util::read_jobs("data/c3a1_jobs.txt").unwrap();
|
||||
let r1 = jobs1(&jobs);
|
||||
let r2 = -1;
|
||||
let r3 = prims();
|
||||
|
||||
println!("r1 = {}; r2 = {}; r3 = {} ", r1, r2, r3);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
|
||||
pub fn prims() -> usize {
|
||||
42
|
||||
}
|
22
src/util.rs
22
src/util.rs
|
@ -2,6 +2,7 @@ use std::fs::File;
|
|||
use std::io;
|
||||
use std::io::{BufRead, BufReader, Error, ErrorKind};
|
||||
use std::vec::Vec;
|
||||
use crate::jobs::{Job, Jobs};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Graph {
|
||||
|
@ -138,3 +139,24 @@ pub fn read_to_directed_weighted_graph(path: &str) -> Result<DirectedWeightedGra
|
|||
}
|
||||
Ok(g)
|
||||
}
|
||||
|
||||
pub fn read_jobs(path: &str) -> Result<Jobs, io::Error> {
|
||||
let mut jobs = Vec::new();
|
||||
let file = File::open(path)?;
|
||||
let br = BufReader::new(file);
|
||||
let mut lines = br.lines();
|
||||
lines.next();
|
||||
for line in lines {
|
||||
let line = line?;
|
||||
let mut nodes = line.split_whitespace();
|
||||
let weight: u32 = nodes.next().unwrap().parse().unwrap();
|
||||
let length: u32 = nodes.next().unwrap().parse().unwrap();
|
||||
let job = Job {
|
||||
weight: weight,
|
||||
length: length,
|
||||
};
|
||||
jobs.push(job);
|
||||
}
|
||||
|
||||
Ok(jobs)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue