Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion pumpkin-crates/branching/src/branching/autonomous_search.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//! Defines [`AutonomousSearch`], a [`Brancher`] that selects predicates with VSIDS and their truth
//! values with solution-based phase saving.

use pumpkin_core::Solver;
use pumpkin_core::branching::Brancher;
use pumpkin_core::branching::BrancherEvent;
Expand Down Expand Up @@ -323,7 +326,9 @@ impl<BackupBrancher: Brancher> Brancher for AutonomousSearch<BackupBrancher> {
}

fn on_solution(&mut self, solution: SolutionReference) {
// We store the best known solution
// The previous best known solution is dropped before the new one is copied, so that only
// one copy is alive at a time.
self.best_known_solution = None;
self.best_known_solution = Some(solution.into());
self.backup_brancher.on_solution(solution);
}
Expand Down
7 changes: 4 additions & 3 deletions pumpkin-crates/core/src/basic_types/solution.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//! Defines [`Solution`] and [`SolutionReference`], an owned and a borrowed assignment of values to
//! the variables, which both implement [`ProblemSolution`].

use crate::engine::Assignments;
use crate::engine::variables::DomainGeneratorIterator;
use crate::engine::variables::DomainId;
Expand Down Expand Up @@ -84,9 +87,7 @@ impl From<Assignments> for Solution {

impl From<SolutionReference<'_>> for Solution {
fn from(value: SolutionReference) -> Self {
Self {
assignments: value.assignments.clone(),
}
value.assignments.clone().into()
}
}

Expand Down
3 changes: 3 additions & 0 deletions pumpkin-crates/core/src/branching/selection_context.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//! Defines [`SelectionContext`], the view of the solver state that a [`Brancher`] uses to select
//! its next decision.

use std::fmt::Debug;

use crate::basic_types::Random;
Expand Down
3 changes: 3 additions & 0 deletions pumpkin-crates/core/src/engine/cp/assignments.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//! Defines [`Assignments`], the current domains of all integer variables together with the trail
//! of every change made to them, so that earlier domains can be queried and restored.

use crate::basic_types::Trail;
use crate::containers::HashMap;
use crate::containers::KeyedVec;
Expand Down
51 changes: 22 additions & 29 deletions pumpkin-crates/core/src/optimisation/linear_sat_unsat.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//! Defines [`LinearSatUnsat`], the optimisation procedure that repeatedly searches for a solution
//! with a strictly better objective value than the best one found so far.

use std::ops::ControlFlow;

use super::OptimisationProcedure;
Expand Down Expand Up @@ -65,37 +68,27 @@ impl<Var, Callback> LinearSatUnsat<Var, Callback> {

let best_objective_value = best_solution.get_integer_value(objective.clone());

let conclusion = {
let solve_result = solver.satisfy_under_assumptions(
brancher,
termination,
resolver,
&[predicate![objective < best_objective_value]],
);

match solve_result {
SatisfactionResultUnderAssumptions::Satisfiable(satisfiable) => {
best_solution = satisfiable.solution().into();
None
}
SatisfactionResultUnderAssumptions::UnsatisfiableUnderAssumptions(_) => {
Some(OptimisationResult::Optimal(best_solution.clone()))
}
SatisfactionResultUnderAssumptions::Unsatisfiable(_) => unreachable!(
"If the problem is unsatisfiable here, it would have been unsatisifable in the initial solve."
),
SatisfactionResultUnderAssumptions::Unknown(_) => {
Some(OptimisationResult::Satisfiable(best_solution.clone()))
}
match solver.satisfy_under_assumptions(
brancher,
termination,
resolver,
&[predicate![objective < best_objective_value]],
) {
SatisfactionResultUnderAssumptions::Satisfiable(satisfiable) => {
// The previous best solution is dropped before the new one is copied, so that
// only one copy is alive at a time.
drop(best_solution);
best_solution = satisfiable.solution().into();
}
};

match conclusion {
Some(OptimisationResult::Optimal(solution)) => {
return OptimisationResult::Optimal(solution);
SatisfactionResultUnderAssumptions::UnsatisfiableUnderAssumptions(_) => {
return OptimisationResult::Optimal(best_solution);
}
SatisfactionResultUnderAssumptions::Unsatisfiable(_) => unreachable!(
"If the problem is unsatisfiable here, it would have been unsatisfiable in the initial solve."
),
SatisfactionResultUnderAssumptions::Unknown(_) => {
return OptimisationResult::Satisfiable(best_solution);
}
Some(result) => return result,
None => {}
}
}
}
Expand Down
Loading