Skip to content

Commit

Permalink
Apply some refactorings
Browse files Browse the repository at this point in the history
  • Loading branch information
reinterpretcat committed Aug 28, 2024
1 parent 3af7954 commit ef7dbee
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 16 deletions.
9 changes: 8 additions & 1 deletion vrp-scientific/src/common/initial_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
mod init_solution_reader_test;

use crate::common::read_line;
use std::collections::HashMap;
use std::collections::{HashMap, HashSet};
use std::io::{BufReader, Read};
use std::sync::Arc;
use vrp_core::construction::heuristics::UnassignmentInfo;
use vrp_core::models::common::*;
use vrp_core::models::problem::*;
use vrp_core::models::solution::{Activity, Registry, Route, Tour};
Expand All @@ -28,6 +29,8 @@ pub fn read_init_solution<R: Read>(
telemetry: None,
};

let mut not_used_jobs = problem.jobs.all().collect::<HashSet<_>>();

loop {
match read_line(&mut reader, &mut buffer) {
Ok(read) if read > 0 => {
Expand Down Expand Up @@ -60,6 +63,8 @@ pub fn read_init_solution<R: Read>(
job: Some(single.clone()),
commute: None,
});

not_used_jobs.remove(&Job::Single(single.clone()));
});

solution.registry.use_actor(&actor);
Expand All @@ -76,5 +81,7 @@ pub fn read_init_solution<R: Read>(
}
}

solution.unassigned = not_used_jobs.into_iter().map(|job| (job, UnassignmentInfo::Unknown)).collect();

Ok(solution)
}
14 changes: 0 additions & 14 deletions vrp-scientific/tests/integration/known_problems_test.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,13 @@
use crate::helpers::*;
use std::sync::Arc;
use vrp_core::construction::heuristics::InsertionContext;
use vrp_core::construction::heuristics::*;
use vrp_core::models::problem::JobIdDimension;
use vrp_core::models::Problem;
use vrp_core::rosomaxa::evolution::TelemetryMode;
use vrp_core::solver::create_elitism_population;
use vrp_core::solver::search::{Recreate, RecreateWithCheapest};
use vrp_core::solver::RefinementContext;
use vrp_core::utils::Environment;

#[derive(Default)]
struct StableJobSelector {}

impl JobSelector for StableJobSelector {
fn prepare(&self, insertion_ctx: &mut InsertionContext) {
insertion_ctx
.solution
.required
.sort_by(|a, b| a.dimens().get_job_id().unwrap().cmp(b.dimens().get_job_id().unwrap()));
}
}

parameterized_test! {can_solve_problem_with_cheapest_insertion_heuristic, (problem, expected, cost), {
can_solve_problem_with_cheapest_insertion_heuristic_impl(Arc::new(problem), expected, cost);
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ pub fn can_read_init_solution() {
let file = get_test_resource("../../examples/data/scientific/solomon/C101.100.best.txt").unwrap();

let solution = read_init_solution(BufReader::new(file), problem.clone(), environment.random.clone())
.expect("Cannot read initial solution");
.expect("cannot read initial solution");
assert_eq!(solution.routes.len(), 10);
assert!(solution.unassigned.is_empty());

let insertion_ctx = InsertionContext::new_from_solution(problem, (solution, None), environment);
assert_eq!(insertion_ctx.get_total_cost().unwrap_or_default().round(), 828.936f64.round());
Expand Down

0 comments on commit ef7dbee

Please sign in to comment.