pub struct ConstraintWeightOverrides<Sc: Score> { /* private fields */ }Expand description
Holds runtime overrides for constraint weights.
Use this to adjust constraint weights without recompiling. Weights can be changed between solver runs or even during solving (if you rebuild constraints).
§Example
use solverforge_scoring::ConstraintWeightOverrides;
use solverforge_core::score::HardSoftScore;
let mut overrides = ConstraintWeightOverrides::<HardSoftScore>::new();
// Override specific constraint weights
overrides.put("room_conflict", HardSoftScore::of_hard(2));
overrides.put("preferred_room", HardSoftScore::of_soft(5));
// Get weight with fallback to default
let weight = overrides.get_or_default(
"room_conflict",
HardSoftScore::of_hard(1), // default if not overridden
);
assert_eq!(weight, HardSoftScore::of_hard(2));
// Non-overridden constraint uses default
let other = overrides.get_or_default(
"other_constraint",
HardSoftScore::of_soft(10),
);
assert_eq!(other, HardSoftScore::of_soft(10));Implementations§
Source§impl<Sc: Score> ConstraintWeightOverrides<Sc>
impl<Sc: Score> ConstraintWeightOverrides<Sc>
Sourcepub fn from_pairs<I, N>(iter: I) -> Self
pub fn from_pairs<I, N>(iter: I) -> Self
Creates overrides from an iterator of (name, weight) pairs.
§Example
use solverforge_scoring::ConstraintWeightOverrides;
use solverforge_core::score::HardSoftScore;
let overrides = ConstraintWeightOverrides::from_pairs([
("hard_constraint", HardSoftScore::of_hard(1)),
("soft_constraint", HardSoftScore::of_soft(10)),
]);
assert_eq!(overrides.len(), 2);Sourcepub fn get_or_default(&self, name: &str, default: Sc) -> Sc
pub fn get_or_default(&self, name: &str, default: Sc) -> Sc
Gets the overridden weight, or returns the default if not overridden.
Trait Implementations§
Source§impl<Sc: Clone + Score> Clone for ConstraintWeightOverrides<Sc>
impl<Sc: Clone + Score> Clone for ConstraintWeightOverrides<Sc>
Source§fn clone(&self) -> ConstraintWeightOverrides<Sc>
fn clone(&self) -> ConstraintWeightOverrides<Sc>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<Sc: Score> Debug for ConstraintWeightOverrides<Sc>
impl<Sc: Score> Debug for ConstraintWeightOverrides<Sc>
Source§impl<Sc: Score> Default for ConstraintWeightOverrides<Sc>
impl<Sc: Score> Default for ConstraintWeightOverrides<Sc>
Source§impl<Sc: Score> WeightProvider<Sc> for ConstraintWeightOverrides<Sc>
impl<Sc: Score> WeightProvider<Sc> for ConstraintWeightOverrides<Sc>
Auto Trait Implementations§
impl<Sc> Freeze for ConstraintWeightOverrides<Sc>
impl<Sc> RefUnwindSafe for ConstraintWeightOverrides<Sc>where
Sc: RefUnwindSafe,
impl<Sc> Send for ConstraintWeightOverrides<Sc>
impl<Sc> Sync for ConstraintWeightOverrides<Sc>
impl<Sc> Unpin for ConstraintWeightOverrides<Sc>where
Sc: Unpin,
impl<Sc> UnwindSafe for ConstraintWeightOverrides<Sc>where
Sc: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more