@@ -243,55 +243,51 @@ impl Clause {
243
243
condition_candidates : impl IntoIterator < Item = VariableId > ,
244
244
) -> ( Self , Option < [ Literal ; 2 ] > , bool ) {
245
245
assert_ne ! ( decision_tracker. assigned_value( parent_id) , Some ( false ) ) ;
246
-
247
- let mut condition_candidates = condition_candidates. into_iter ( ) . peekable ( ) ;
248
- let condition_first_candidate = condition_candidates
249
- . peek ( )
250
- . copied ( )
251
- . expect ( "no condition candidates" ) ;
252
- let mut requirement_candidates = requirement_candidates. into_iter ( ) . peekable ( ) ;
253
-
254
- match condition_candidates
255
- . find ( |& condition_id| decision_tracker. assigned_value ( condition_id) == Some ( true ) )
256
- {
257
- Some ( _) => {
258
- // Condition is true, find first requirement candidate not set to false
259
- if let Some ( req_candidate) = requirement_candidates
260
- . find ( |& req_id| decision_tracker. assigned_value ( req_id) != Some ( false ) )
261
- {
262
- (
263
- Clause :: Conditional ( parent_id, condition, requirement) ,
264
- Some ( [ parent_id. negative ( ) , req_candidate. positive ( ) ] ) ,
265
- false ,
266
- )
267
- } else {
268
- // No valid requirement candidate, use first condition candidate and mark conflict
269
- (
270
- Clause :: Conditional ( parent_id, condition, requirement) ,
271
- Some ( [ parent_id. negative ( ) , condition_first_candidate. negative ( ) ] ) ,
272
- true ,
273
- )
274
- }
275
- }
276
- None => {
277
- // No true condition, look for unset condition
278
- if let Some ( unset_condition) = condition_candidates. find ( |& condition_id| {
279
- decision_tracker. assigned_value ( condition_id) != Some ( false )
280
- } ) {
281
- (
282
- Clause :: Conditional ( parent_id, condition, requirement) ,
283
- Some ( [ parent_id. negative ( ) , unset_condition. negative ( ) ] ) ,
284
- false ,
285
- )
286
- } else {
287
- // All conditions false
288
- (
289
- Clause :: Conditional ( parent_id, condition, requirement) ,
290
- None ,
291
- false ,
292
- )
293
- }
294
- }
246
+ let mut condition_candidates = condition_candidates. into_iter ( ) ;
247
+ let mut requirement_candidates = requirement_candidates. into_iter ( ) ;
248
+
249
+ // Check if we have any condition candidates
250
+ let Some ( first_condition) = condition_candidates. next ( ) else {
251
+ // No conditions means this is just an assertion
252
+ return (
253
+ Clause :: Conditional ( parent_id, condition, requirement) ,
254
+ None ,
255
+ false ,
256
+ ) ;
257
+ } ;
258
+
259
+ // Try to find a condition candidate that is undecided or true
260
+ let condition_literal = std:: iter:: once ( first_condition)
261
+ . chain ( condition_candidates)
262
+ . find ( |& id| {
263
+ let value = decision_tracker. assigned_value ( id) ;
264
+ value. is_none ( ) || value == Some ( true )
265
+ } ) ;
266
+
267
+ // Try to find a requirement candidate that is undecided or true
268
+ let requirement_literal = requirement_candidates. find ( |& id| {
269
+ let value = decision_tracker. assigned_value ( id) ;
270
+ value. is_none ( ) || value == Some ( true )
271
+ } ) ;
272
+
273
+ match ( condition_literal, requirement_literal) {
274
+ // Found valid literals - use them
275
+ ( Some ( cond) , _) => (
276
+ Clause :: Conditional ( parent_id, condition, requirement) ,
277
+ Some ( [ parent_id. negative ( ) , cond. negative ( ) ] ) ,
278
+ false ,
279
+ ) ,
280
+ ( None , Some ( req) ) => (
281
+ Clause :: Conditional ( parent_id, condition, requirement) ,
282
+ Some ( [ parent_id. negative ( ) , req. positive ( ) ] ) ,
283
+ false ,
284
+ ) ,
285
+ // No valid literals found - conflict case
286
+ ( None , None ) => (
287
+ Clause :: Conditional ( parent_id, condition, requirement) ,
288
+ Some ( [ parent_id. negative ( ) , first_condition. negative ( ) ] ) ,
289
+ true ,
290
+ ) ,
295
291
}
296
292
}
297
293
0 commit comments