Skip to content

Commit

Permalink
Detect properly initial state
Browse files Browse the repository at this point in the history
  • Loading branch information
reinterpretcat committed Aug 7, 2023
1 parent ba6fb7f commit bcf5505
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions rosomaxa/src/hyper/dynamic_selective.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,13 @@ where
let reward_multiplier = estimate_reward_multiplier(&context, duration, is_new_best);
let reward = base_reward * reward_multiplier;

let transition = (context.from, convert_to_state(context.heuristic_ctx, &new_solution));
let to = if matches!(compare_to_best(context.heuristic_ctx, &new_solution), Ordering::Less) {
SearchState::BestKnown
} else {
SearchState::Diverse
};

let transition = (context.from, to);

let sample = SearchSample { name: self.operator_name.clone(), duration, reward, transition };

Expand Down Expand Up @@ -226,7 +232,11 @@ where

/// Picks relevant search operator based on learnings and runs the search.
pub fn search(&self, heuristic_ctx: &C, solution: &S) -> SearchFeedback<S> {
let from = convert_to_state(heuristic_ctx, solution);
let from = if matches!(compare_to_best(heuristic_ctx, solution), Ordering::Equal) {
SearchState::BestKnown
} else {
SearchState::Diverse
};

let (slot_idx, slot_machine) = self
.slot_machines
Expand Down Expand Up @@ -319,19 +329,6 @@ where
.unwrap_or(Ordering::Less)
}

fn convert_to_state<C, O, S>(heuristic_ctx: &C, solution: &S) -> SearchState
where
C: HeuristicContext<Objective = O, Solution = S>,
O: HeuristicObjective<Solution = S>,
S: HeuristicSolution,
{
if matches!(compare_to_best(heuristic_ctx, solution), Ordering::Less) {
SearchState::BestKnown
} else {
SearchState::Diverse
}
}

/// Estimates new solution discovery reward based on distance metric.
/// Returns a reward estimation in `[0, 6]` range. This range consists of:
/// - a initial distance improvement gives `[0, 2]`
Expand Down

0 comments on commit bcf5505

Please sign in to comment.