@@ -78,6 +78,19 @@ impl<OtherBrancher: Brancher> AlternatingBrancher<OtherBrancher> {
78
78
fn toggle_brancher ( & mut self ) {
79
79
self . is_using_default_brancher = !self . is_using_default_brancher
80
80
}
81
+
82
+ /// Returns true if only the default strategy is used from now on and false otherwise.
83
+ ///
84
+ /// This is important if [`AlternatingStrategy::SwitchToDefaultAfterFirstSolution`] is used as
85
+ /// the strategy.
86
+ fn will_always_use_default ( & self ) -> bool {
87
+ match self . strategy {
88
+ AlternatingStrategy :: SwitchToDefaultAfterFirstSolution => {
89
+ self . is_using_default_brancher
90
+ }
91
+ _ => false ,
92
+ }
93
+ }
81
94
}
82
95
83
96
impl < OtherBrancher : Brancher > Brancher for AlternatingBrancher < OtherBrancher > {
@@ -97,13 +110,19 @@ impl<OtherBrancher: Brancher> Brancher for AlternatingBrancher<OtherBrancher> {
97
110
}
98
111
99
112
fn on_appearance_in_conflict_predicate ( & mut self , predicate : Predicate ) {
100
- self . other_brancher
101
- . on_appearance_in_conflict_predicate ( predicate)
113
+ self . default_brancher
114
+ . on_appearance_in_conflict_predicate ( predicate) ;
115
+ if !self . will_always_use_default ( ) {
116
+ self . other_brancher
117
+ . on_appearance_in_conflict_predicate ( predicate)
118
+ }
102
119
}
103
120
104
121
fn on_conflict ( & mut self ) {
105
- self . other_brancher . on_conflict ( ) ;
106
- self . default_brancher . on_conflict ( )
122
+ self . default_brancher . on_conflict ( ) ;
123
+ if !self . will_always_use_default ( ) {
124
+ self . other_brancher . on_conflict ( ) ;
125
+ }
107
126
}
108
127
109
128
fn on_solution ( & mut self , solution : SolutionReference ) {
@@ -120,8 +139,8 @@ impl<OtherBrancher: Brancher> Brancher for AlternatingBrancher<OtherBrancher> {
120
139
}
121
140
}
122
141
AlternatingStrategy :: SwitchToDefaultAfterFirstSolution => {
123
- // Switch only the first time, not that `even_number_of_solutions` is initialised to
124
- // true
142
+ // Switch only the first time, note that `even_number_of_solutions` is initialised
143
+ // to true
125
144
if self . even_number_of_solutions {
126
145
self . even_number_of_solutions = false ;
127
146
self . is_using_default_brancher = true ;
@@ -130,12 +149,17 @@ impl<OtherBrancher: Brancher> Brancher for AlternatingBrancher<OtherBrancher> {
130
149
_ => { }
131
150
}
132
151
133
- self . other_brancher . on_solution ( solution) ;
134
- self . default_brancher . on_solution ( solution)
152
+ self . default_brancher . on_solution ( solution) ;
153
+ if !self . will_always_use_default ( ) {
154
+ self . other_brancher . on_solution ( solution) ;
155
+ }
135
156
}
136
157
137
158
fn on_unassign_integer ( & mut self , variable : DomainId , value : i32 ) {
138
- self . other_brancher . on_unassign_integer ( variable, value)
159
+ self . default_brancher . on_unassign_integer ( variable, value) ;
160
+ if !self . will_always_use_default ( ) {
161
+ self . other_brancher . on_unassign_integer ( variable, value)
162
+ }
139
163
}
140
164
141
165
fn on_restart ( & mut self ) {
@@ -173,12 +197,16 @@ impl<OtherBrancher: Brancher> Brancher for AlternatingBrancher<OtherBrancher> {
173
197
174
198
fn on_backtrack ( & mut self ) {
175
199
self . default_brancher . on_backtrack ( ) ;
176
- self . other_brancher . on_backtrack ( ) ;
200
+ if !self . will_always_use_default ( ) {
201
+ self . other_brancher . on_backtrack ( ) ;
202
+ }
177
203
}
178
204
179
205
fn synchronise ( & mut self , assignments : & Assignments ) {
180
206
self . default_brancher . synchronise ( assignments) ;
181
- self . other_brancher . synchronise ( assignments) ;
207
+ if !self . will_always_use_default ( ) {
208
+ self . other_brancher . synchronise ( assignments) ;
209
+ }
182
210
}
183
211
}
184
212
0 commit comments