rpid 0.3.1

Rust Programmable Interface for Domain-Independent Dynamic Programming (RPID)
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
use num_traits::Zero;
use std::cmp::Ordering;
use std::hash::Hash;
use std::ops::Add;

/// Optimization mode for dynamic programming problems.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum OptimizationMode {
    /// Minimization: the goal is to minimize the cost.
    Minimization,
    /// Maximization: the goal is to maximize the cost.
    Maximization,
}

/// Trait for dynamic programming problems.
///
/// This trait defines the methods that a dynamic programming problem must implement.
/// Data necessary for the problem should be stored in the struct that implements this trait.
///
/// By default, the solution cost is computed by summing the cost weights of the transitions,
/// and minimization is assumed.
/// Override the methods to change this behavior.
///
/// # Examples
///
/// ```
/// use rpid::prelude::*;
/// use fixedbitset::FixedBitSet;
///
/// struct Tsp {
///     c: Vec<Vec<i32>>,
/// }
///
/// struct TspState {
///     unvisited: FixedBitSet,
///     current: usize,
/// }
///
/// impl Dp for Tsp {
///     type State = TspState;
///     type CostType = i32;
///     type Label = usize;
///
///
///     fn get_target(&self) -> Self::State {
///         let mut unvisited = FixedBitSet::with_capacity(self.c.len());
///         unvisited.insert_range(1..);
///
///         TspState {
///             unvisited,
///             current: 0,
///        }
///     }
///
///     fn get_successors(
///         &self,
///         state: &Self::State,
///     ) -> impl IntoIterator<Item = (Self::State, Self::CostType, Self::Label)> {
///         state.unvisited.ones().map(|next| {
///             let mut unvisited = state.unvisited.clone();
///             unvisited.remove(next);
///
///             let successor = TspState {
///                 unvisited,
///                 current: next,
///             };
///             let weight = self.c[state.current][next];
///             
///             (successor, weight, next)
///         })
///     }
///
///     fn get_base_cost(&self, state: &Self::State) -> Option<Self::CostType> {
///         if state.unvisited.is_clear() {
///             Some(self.c[state.current][0])
///         } else {
///             None
///         }
///     }
/// }
///
/// let tsp = Tsp { c: vec![vec![0, 1, 2], vec![1, 0, 3], vec![2, 3, 0]] };
///
/// let target = tsp.get_target();
/// assert_eq!(target.current, 0);
/// let mut unvisited = FixedBitSet::with_capacity(3);
/// unvisited.insert_range(1..);
/// assert_eq!(target.unvisited, unvisited);
///
/// let successors: Vec<_> = tsp.get_successors(&target).into_iter().collect();
/// assert_eq!(successors.len(), 2);
///
/// assert_eq!(successors[0].0.current, 1);
/// let mut unvisited_1 = unvisited.clone();
/// unvisited_1.remove(1);
/// assert_eq!(successors[0].0.unvisited, unvisited_1);
/// assert_eq!(successors[0].1, 1);
/// assert_eq!(successors[0].2, 1);
///
/// assert_eq!(successors[1].0.current, 2);
/// let mut unvisited_2 = unvisited.clone();
/// unvisited_2.remove(2);
/// assert_eq!(successors[1].0.unvisited, unvisited_2);
/// assert_eq!(successors[1].1, 2);
/// assert_eq!(successors[1].2, 2);
///
/// assert_eq!(tsp.get_base_cost(&target), None);
/// ```
pub trait Dp {
    /// Type of the state.
    type State;
    /// Type of the cost. Usually, `i32` or `f64`.
    type CostType: PartialOrd + Add<Output = Self::CostType> + Zero;
    /// Type of the transition label. Usually, an unsigned integer type or `bool` (e.g., the knapsack problem).
    type Label;

    /// Gets the target (initial) state.
    fn get_target(&self) -> Self::State;

    /// Gets the successors of a state.
    ///
    /// The easiest way to implement this method is to return a vector (`Vec<(Self::State, Self::CostType, Self::Label)>`)
    /// or an array ([`(Self::State, Self::CostType, Self::Label); N]`), where the first element of a tuple is the successor state,
    /// the second element is the cost weight of the transition, and the third element is the label of the transition.
    /// However, by returning an iterator, you can avoid allocating memory for the successors.
    fn get_successors(
        &self,
        state: &Self::State,
    ) -> impl IntoIterator<Item = (Self::State, Self::CostType, Self::Label)>;

    /// Checks if a state is a base (goal) state and returns the base cost if it is.
    fn get_base_cost(&self, state: &Self::State) -> Option<Self::CostType>;

    /// Combines two cost weights.
    ///
    /// This method is used to combine the cost weights of two transitions.
    /// Addition is used by default, but you can override this method to use a different operation.
    /// However, the operation must be associative and isotone, e.g.,
    /// (a + b) + c = a + (b + c) and a ≤ b → a + c ≤ b + c.
    fn combine_cost_weights(&self, a: Self::CostType, b: Self::CostType) -> Self::CostType {
        a + b
    }

    /// Gets the identity weight.
    ///
    /// This method returns the identity element of the `combine_cost_weights` operation, e.g.,
    /// a + 0 = 0 + a = a.
    /// The default implementation returns `Self::CostType::zero()`.
    fn get_identity_weight(&self) -> Self::CostType {
        Self::CostType::zero()
    }

    /// Returns the optimization mode of the problem.
    ///
    /// The default implementation returns `OptimizationMode::Minimization`.
    fn get_optimization_mode(&self) -> OptimizationMode {
        OptimizationMode::Minimization
    }

    /// Returns whether the cost is better than the old cost.
    ///
    /// By default, this method follows the maximization flag.
    fn is_better_cost(&self, new_cost: Self::CostType, old_cost: Self::CostType) -> bool {
        match self.get_optimization_mode() {
            OptimizationMode::Minimization => new_cost < old_cost,
            OptimizationMode::Maximization => new_cost > old_cost,
        }
    }
}

/// Trait for dominance relations.
///
/// # Examples
///
/// ```
/// use rpid::prelude::*;
/// use fixedbitset::FixedBitSet;
///
/// struct Tsp {
///     c: Vec<Vec<i32>>,
/// }
///
/// struct TspState {
///     unvisited: FixedBitSet,
///     current: usize,
/// }
///
/// impl Dominance for Tsp {
///     type State = TspState;
///     type Key = (FixedBitSet, usize);
///
///     fn get_key(&self, state: &Self::State) -> Self::Key {
///         (state.unvisited.clone(), state.current)
///     }
/// }
///
/// let tsp = Tsp { c: vec![vec![0, 1, 2], vec![1, 0, 3], vec![2, 3, 0]] };
///
/// let unvisited = FixedBitSet::with_capacity(3);
/// let current = 0;
/// let key = (unvisited.clone(), current);
/// let state = TspState { unvisited, current };
/// assert_eq!(tsp.get_key(&state), key);
/// ```
pub trait Dominance {
    /// Type of the state.
    type State;
    /// Type of the key.
    type Key: Hash + Eq;

    /// Gets the key of a state.
    ///
    /// A state possibly dominates or is dominated by another state if their keys are equal.
    /// If only this method is implemented, the states are the same if their keys are equal.
    fn get_key(&self, state: &Self::State) -> Self::Key;

    /// Compares two states with the same key.
    ///
    /// Returns `Some(Ordering::Greater)` if the first state dominates the second state,
    /// `Some(Ordering::Less)` if the second state dominates the first state,
    /// `Some(Ordering::Equal)` if they are the same, and `None` if they are incomparable.
    /// By default, this method returns `Some(Ordering::Equal)`, which means that
    /// the states are the same if their keys are equal.
    fn compare(&self, _a: &Self::State, _b: &Self::State) -> Option<Ordering> {
        Some(Ordering::Equal)
    }

    /// Updates the key of a state.
    ///
    /// This method is not necessarily implemented.
    /// It is useful to reduce memory usage when the key of a state is stored as a shared pointer.
    fn update_key(&self, _state: &mut Self::State, _key: &Self::Key) {}
}

/// Trait for computing dual bounds depending on a state.
///
/// A dual bound is a lower/upper bound on the cost of the optimal solution
/// in a minimization/maximization problem.
///
/// ```
/// use rpid::prelude::*;
/// use rpid::algorithms;
/// use fixedbitset::FixedBitSet;
///
/// struct Tsp {
///     c: Vec<Vec<i32>>,
/// }
///
/// struct TspState {
///     unvisited: FixedBitSet,
///     current: usize,
/// }
///
/// impl Bound for Tsp {
///     type State = TspState;
///     type CostType = i32;
///
///     fn get_dual_bound(&self, _: &Self::State) -> Option<Self::CostType> {
///         Some(0)
///     }
/// }
///
/// let tsp = Tsp { c: vec![vec![0, 1, 2], vec![1, 0, 3], vec![2, 3, 0]] };
///
/// let unvisited = FixedBitSet::with_capacity(3);
/// let current = 0;
/// let state = TspState { unvisited, current };
/// assert_eq!(tsp.get_dual_bound(&state), Some(0));
/// ```
pub trait Bound {
    /// Type of the state.
    type State;
    /// Type of the cost.
    type CostType;

    /// Gets the dual bound of a state.
    ///
    /// Returns `None` if the state is not feasible.
    fn get_dual_bound(&self, state: &Self::State) -> Option<Self::CostType>;

    /// Gets the global primal bound.
    ///
    /// The default implementation returns `None`, which means that the global primal bound is not used.
    /// The global primal bound is an upper/lower bound on the cost of the optimal solution in a minimization/maximization problem.
    fn get_global_primal_bound(&self) -> Option<Self::CostType> {
        None
    }

    /// Gets the global dual bound.
    ///
    /// The default implementation returns `None`, which means that the global dual bound is not used.
    /// The global dual bound is an lower/upper bound on the cost of the optimal solution in a minimization/maximization problem.
    fn get_global_dual_bound(&self) -> Option<Self::CostType> {
        None
    }
}

/// Trait for dynamic programming problems.
///
/// This trait defines the methods that a dynamic programming problem must implement.
/// Data necessary for the problem should be stored in the struct that implements this trait.
///
/// By default, the solution cost is computed by summing the cost weights of the transitions,
/// and minimization is assumed.
/// Override the methods to change this behavior.
///
/// This trait is similar to the `Dp` trait, but it allows mutable access to the problem struct
/// when generating successors and get the base cost.
/// This is useful when the problem struct contains data that needs to be updated during the search.
/// For example, some caching on the user side may be used to speed up the computation of successors.
///
/// If you are unsure what this trait is for, you probably want to implement the `Dp` trait instead.
///
/// When a struct implements the [Dp] trait, [DpMut] is automatically implemented for it.
/// A solving algorithm should be generic over [DpMut] to accept both [Dp] and [DpMut].
pub trait DpMut {
    /// Type of the state.
    type State;
    /// Type of the cost. Usually, `i32` or `f64`.
    type CostType: PartialOrd + Add<Output = Self::CostType> + Zero;
    /// Type of the transition label. Usually, an unsigned integer type or `bool` (e.g., the knapsack problem).
    type Label;

    /// Gets the target (initial) state.
    fn get_target(&self) -> Self::State;

    /// Gets the successors of a state.
    ///
    /// The easiest way to implement this method is to return a vector (`Vec<(Self::State, Self::CostType, Self::Label)>`)
    /// or an array ([`(Self::State, Self::CostType, Self::Label); N]`), where the first element of a tuple is the successor state,
    /// the second element is the cost weight of the transition, and the third element is the label of the transition.
    /// However, by returning an iterator, you can avoid allocating memory for the successors.
    fn get_successors(
        &mut self,
        state: &Self::State,
        successors: &mut Vec<(Self::State, Self::CostType, Self::Label)>,
    );

    /// Checks if a state is a base (goal) state and returns the base cost if it is.
    fn get_base_cost(&mut self, state: &Self::State) -> Option<Self::CostType>;

    /// Combines two cost weights.
    ///
    /// This method is used to combine the cost weights of two transitions.
    /// Addition is used by default, but you can override this method to use a different operation.
    /// However, the operation must be associative and isotone, e.g.,
    /// (a + b) + c = a + (b + c) and a ≤ b → a + c ≤ b + c.
    fn combine_cost_weights(&self, a: Self::CostType, b: Self::CostType) -> Self::CostType {
        a + b
    }

    /// Gets the identity weight.
    ///
    /// This method returns the identity element of the `combine_cost_weights` operation, e.g.,
    /// a + 0 = 0 + a = a.
    /// The default implementation returns `Self::CostType::zero()`.
    fn get_identity_weight(&self) -> Self::CostType {
        Self::CostType::zero()
    }

    /// Returns the optimization mode of the problem.
    ///
    /// The default implementation returns `OptimizationMode::Minimization`.
    fn get_optimization_mode(&self) -> OptimizationMode {
        OptimizationMode::Minimization
    }

    /// Returns whether the cost is better than the old cost.
    ///
    /// By default, this method follows the maximization flag.
    fn is_better_cost(&self, new_cost: Self::CostType, old_cost: Self::CostType) -> bool {
        match self.get_optimization_mode() {
            OptimizationMode::Minimization => new_cost < old_cost,
            OptimizationMode::Maximization => new_cost > old_cost,
        }
    }

    /// Notifies information of a new primal bound.
    ///
    /// By default, this method does nothing.
    ///
    /// An expected use case is to update some internal data structures that tracks the primal bound for pruning.
    /// For example, a user may want to evaluate a dual bound function when `get_successors` is called.
    /// Since `Bound::get_dual_bound` may be called when the state is generated,
    /// the user may want to use a more expensive dual bound function only when it is expanded.
    /// In this case, the user needs to store the primal bound in the struct and update it in this method.
    fn notify_primal_bound(&mut self, _primal_bound: Self::CostType) {}
}

impl<T: Dp> DpMut for T {
    type State = T::State;
    type CostType = T::CostType;
    type Label = T::Label;

    fn get_target(&self) -> Self::State {
        Dp::get_target(self)
    }

    fn get_successors(
        &mut self,
        state: &Self::State,
        successors: &mut Vec<(Self::State, Self::CostType, Self::Label)>,
    ) {
        successors.extend(Dp::get_successors(self, state));
    }

    fn get_base_cost(&mut self, state: &Self::State) -> Option<Self::CostType> {
        Dp::get_base_cost(self, state)
    }

    fn combine_cost_weights(&self, a: Self::CostType, b: Self::CostType) -> Self::CostType {
        Dp::combine_cost_weights(self, a, b)
    }

    fn get_identity_weight(&self) -> Self::CostType {
        Dp::get_identity_weight(self)
    }

    fn get_optimization_mode(&self) -> OptimizationMode {
        Dp::get_optimization_mode(self)
    }

    fn is_better_cost(&self, new_cost: Self::CostType, old_cost: Self::CostType) -> bool {
        Dp::is_better_cost(self, new_cost, old_cost)
    }
}

/// Trait for computing dual bounds depending on a state.
///
/// A dual bound is a lower/upper bound on the cost of the optimal solution
/// in a minimization/maximization problem.
///
/// This trait is similar to the `Bound` trait, but it allows mutable access to the problem struct
/// when evaluating the dual bound function.
/// This is useful when the problem struct contains data that needs to be updated during the search, e.g.,
/// some caching.
///
/// If you are unsure what this trait is for, you probably want to implement the `Bound` trait instead.
///
/// When a struct implements the `Bound` trait, [BoundMut] is automatically implemented for it.
/// A solving algorithm should be generic over [BoundMut] to accept both [Bound] and [BoundMut].
pub trait BoundMut {
    /// Type of the state.
    type State;
    /// Type of the cost.
    type CostType;

    /// Gets the dual bound of a state.
    ///
    /// Returns `None` if the state is not feasible.
    fn get_dual_bound(&mut self, state: &Self::State) -> Option<Self::CostType>;

    /// Gets the global primal bound.
    ///
    /// The default implementation returns `None`, which means that the global primal bound is not used.
    /// The global primal bound is an upper/lower bound on the cost of the optimal solution in a minimization/maximization problem.
    fn get_global_primal_bound(&self) -> Option<Self::CostType> {
        None
    }

    /// Gets the global dual bound.
    ///
    /// The default implementation returns `None`, which means that the global dual bound is not used.
    /// The global dual bound is an lower/upper bound on the cost of the optimal solution in a minimization/maximization problem.
    fn get_global_dual_bound(&self) -> Option<Self::CostType> {
        None
    }
}

impl<T: Bound> BoundMut for T {
    type State = T::State;
    type CostType = T::CostType;

    fn get_dual_bound(&mut self, state: &Self::State) -> Option<Self::CostType> {
        Bound::get_dual_bound(self, state)
    }

    fn get_global_primal_bound(&self) -> Option<Self::CostType> {
        Bound::get_global_primal_bound(self)
    }

    fn get_global_dual_bound(&self) -> Option<Self::CostType> {
        Bound::get_global_dual_bound(self)
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    struct MockDp;

    impl Dp for MockDp {
        type State = i32;
        type CostType = i32;
        type Label = usize;

        fn get_target(&self) -> Self::State {
            0
        }

        fn get_successors(
            &self,
            _: &Self::State,
        ) -> impl IntoIterator<Item = (Self::State, Self::CostType, Self::Label)> {
            vec![]
        }

        fn get_base_cost(&self, _state: &Self::State) -> Option<Self::CostType> {
            None
        }
    }

    impl Dominance for MockDp {
        type State = i32;
        type Key = i32;

        fn get_key(&self, state: &Self::State) -> Self::Key {
            *state
        }
    }

    impl Bound for MockDp {
        type State = i32;
        type CostType = i32;

        fn get_dual_bound(&self, _: &Self::State) -> Option<Self::CostType> {
            Some(0)
        }
    }

    #[test]
    fn test_get_target_mut() {
        let dp = MockDp;
        assert_eq!(DpMut::get_target(&dp), 0);
    }

    #[test]
    fn test_get_successors_mut() {
        let mut dp = MockDp;
        let mut successors = Vec::new();
        DpMut::get_successors(&mut dp, &0, &mut successors);
        assert!(successors.is_empty());
    }

    #[test]
    fn get_base_cost_mut() {
        let mut dp = MockDp;
        assert_eq!(DpMut::get_base_cost(&mut dp, &0), None);
    }

    #[test]
    fn test_combine_cost_weights_default() {
        let dp = MockDp;
        assert_eq!(Dp::combine_cost_weights(&dp, 1, 2), 3);
    }

    #[test]
    fn test_combine_cost_weights_mut() {
        let dp = MockDp;
        assert_eq!(DpMut::combine_cost_weights(&dp, 1, 2), 3);
    }

    #[test]
    fn test_get_identity_weight_default() {
        let dp = MockDp;
        assert_eq!(Dp::get_identity_weight(&dp), 0);
    }

    #[test]
    fn test_get_identity_weight_mut() {
        let dp = MockDp;
        assert_eq!(DpMut::get_identity_weight(&dp), 0);
    }

    #[test]
    fn test_get_optimization_mode_default() {
        let dp = MockDp;
        assert_eq!(
            Dp::get_optimization_mode(&dp),
            OptimizationMode::Minimization
        );
    }

    #[test]
    fn test_get_optimization_mode_mut() {
        let dp = MockDp;
        assert_eq!(
            DpMut::get_optimization_mode(&dp),
            OptimizationMode::Minimization
        );
    }

    #[test]
    fn test_is_better_cost_default() {
        let dp = MockDp;
        assert!(Dp::is_better_cost(&dp, 1, 2));
    }

    #[test]
    fn test_is_better_cost_mut() {
        let dp = MockDp;
        assert!(DpMut::is_better_cost(&dp, 1, 2));
    }

    #[test]
    fn test_compare_default() {
        let dp = MockDp;
        assert_eq!(dp.compare(&0, &0), Some(Ordering::Equal));
    }

    #[test]
    fn test_get_global_primal_bound_default() {
        let dp = MockDp;
        assert_eq!(Bound::get_global_primal_bound(&dp), None);
    }

    #[test]
    fn test_get_global_primal_bound_mut() {
        let dp = MockDp;
        assert_eq!(Bound::get_global_primal_bound(&dp), None);
    }

    #[test]
    fn test_get_dual_bound_mut() {
        let mut dp = MockDp;
        assert_eq!(BoundMut::get_dual_bound(&mut dp, &0), Some(0));
    }

    #[test]
    fn test_get_global_dual_bound_default() {
        let dp = MockDp;
        assert_eq!(Bound::get_global_dual_bound(&dp), None);
    }

    #[test]
    fn test_get_global_dual_bound_mut() {
        let dp = MockDp;
        assert_eq!(BoundMut::get_global_dual_bound(&dp), None);
    }

    struct MockDpMut;

    impl DpMut for MockDpMut {
        type State = i32;
        type CostType = i32;
        type Label = usize;

        fn get_target(&self) -> Self::State {
            0
        }

        fn get_successors(
            &mut self,
            _: &Self::State,
            _: &mut Vec<(Self::State, Self::CostType, Self::Label)>,
        ) {
        }

        fn get_base_cost(&mut self, _state: &Self::State) -> Option<Self::CostType> {
            None
        }
    }

    impl BoundMut for MockDpMut {
        type State = i32;
        type CostType = i32;

        fn get_dual_bound(&mut self, _: &Self::State) -> Option<Self::CostType> {
            Some(0)
        }
    }

    #[test]
    fn test_combine_cost_weights_mut_default() {
        let dp = MockDpMut;
        assert_eq!(dp.combine_cost_weights(1, 2), 3);
    }

    #[test]
    fn test_get_identity_weight_mut_default() {
        let dp = MockDpMut;
        assert_eq!(dp.get_identity_weight(), 0);
    }

    #[test]
    fn test_get_optimization_mode_mut_default() {
        let dp = MockDpMut;
        assert_eq!(dp.get_optimization_mode(), OptimizationMode::Minimization);
    }

    #[test]
    fn test_is_better_cost_mut_default() {
        let dp = MockDpMut;
        assert!(dp.is_better_cost(1, 2));
    }

    #[test]
    fn test_get_global_primal_bound_mut_default() {
        let dp = MockDpMut;
        assert_eq!(dp.get_global_primal_bound(), None);
    }

    #[test]
    fn test_get_global_dual_bound_mut_default() {
        let dp = MockDpMut;
        assert_eq!(dp.get_global_dual_bound(), None);
    }

    #[test]
    fn test_notify_primal_bound_mut_default() {
        let mut dp = MockDpMut;
        dp.notify_primal_bound(42);
    }
}