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
// Copyright 2020 Xavier Gillard
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
// the Software, and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//! This module defines the traits used to encapsulate solver heuristics.
//!
//! Namely, it defines :
//!
//! - the `WidthHeuristic` which is used to control the maximum width of an MDD
//! - the `StateRanking` heuristic which is used to guess the nodes promising-ness
//! - the `Cutoff` heuristic which is used to impose a stopping criterion on the
//! solver resolution.
use Ordering;
use crateSubProblem;
/// This trait encapsulates the behavior of the heuristic that determines
/// the maximum permitted width of a decision diagram.
///
/// # Technical Note:
/// Just like `Problem`, `Relaxation` and `StateRanking`, the `WidthHeuristic`
/// trait is generic over `State`s. However, rather than using the same
/// 'associated-type' mechanism that was used for the former three types,
/// `WidthHeuristic` uses a parameter type for this purpose (the type parameter
/// approach might feel more familiar to Java or C++ programmers than the
/// associated-type).
///
/// This choice was motivated by two factors:
/// 1. The `Problem`, `Relaxation` and `StateRanking` are intrinsically tied
/// to *one type* of state. And thus, the `State` is really a part of the
/// problem/relaxation itself. Therefore, it would not make sense to define
/// a generic problem implementation which would be applicable to all kind
/// of states. Instead, an implementation of the `Problem` trait is the
/// concrete implementation of a DP model (same argument holds for the other
/// traits).
///
/// 2. On the other hand, it does make sense to define a `WidthHeuristic`
/// implementation which is applicable regardless of the state of the problem
/// which is currently being solved. For instance, the ddo framework offers
/// the `Fixed` and `NbUnassigned` width heuristics which are independent of
/// the problem. The `Fixed` width heuristic imposes that the maximum layer
/// width be constant across all compiled DDs whereas `NbUnassigned` lets
/// the maximum width vary depending on the number of problem variables
/// which have already been decided upon.
/// A state ranking is an heuristic that imposes a partial order on states.
/// This order is used by the framework as a means to discriminate the most
/// promising nodes from the least promising ones when restricting or relaxing
/// a layer from some given DD.
///
/// According to this ordering, greater means better and hence more likely to
/// means a node with a given state is more likely to be kept after restriction
/// or relaxation.
/// A subproblem ranking is an heuristic that imposes a partial order on
/// sub-problems on the solver fringe. This order is used by the framework
/// as a means to impose a given ordering on the nodes that are popped from
/// the solver fringe.
/// This trait encapsulates a criterion (external to the solver) which imposes
/// to stop searching for a better solution. Typically, this is done to grant
/// a given time budget to the search.