@@ -267,7 +267,7 @@ impl Engine {
267267 fn analyze_conflict ( & mut self , mut clause : usize ) {
268268 self . seen . fill ( false ) ;
269269 let mut counter: usize = 0 ;
270- let mut p: Option < Lit > = None ;
270+ let mut p: Option < ( Lit , usize ) > = None ;
271271 self . learnt . clear ( ) ;
272272 self . learnt . push ( Lit :: default ( ) ) ; // Placeholder for the asserting literal
273273
@@ -277,7 +277,7 @@ impl Engine {
277277 let v = lit. var ( ) ;
278278
279279 // Skip the variable we are currently resolving away
280- if Some ( v) == p. map ( |l| l. var ( ) ) {
280+ if Some ( v) == p. map ( |l| l. 0 . var ( ) ) {
281281 continue ;
282282 }
283283
@@ -287,18 +287,19 @@ impl Engine {
287287 counter += 1 ;
288288 } else {
289289 // This literal comes from a previous decision level
290- self . learnt . push ( * lit) ;
290+ self . learnt . push ( ! lit) ;
291291 }
292292 }
293293 }
294294
295295 // 2. Find the next variable from the trail assigned at this level
296296 p = loop {
297297 let v = self . propagated_vars [ self . decision_var ] . pop ( ) . expect ( "There should be a variable to resolve away" ) ;
298- let sign = self . value ( v) == & LBool :: True ;
299298 if !self . seen [ v] {
299+ let sign = self . value ( v) == & LBool :: True ;
300+ let reason = self . reason [ v] . expect ( "There should be a reason clause for this variable" ) ;
300301 self . undo ( v) ;
301- break Some ( Lit :: new ( v, sign) ) ;
302+ break Some ( ( Lit :: new ( v, sign) , reason ) ) ;
302303 }
303304 self . undo ( v) ;
304305 } ;
@@ -307,12 +308,12 @@ impl Engine {
307308
308309 // 3. Check for 1-UIP (First Unique Implication Point)
309310 if counter == 0 {
310- self . learnt [ 0 ] = !p. expect ( "There should be a literal to assert" ) ;
311+ self . learnt [ 0 ] = !p. expect ( "There should be a literal to assert" ) . 0 ;
311312 break ;
312313 }
313314
314- // 4. Update clause_id to the REASON why next_to_resolve was assigned
315- clause = self . reason [ p. expect ( "There should be a literal to resolve away" ) . var ( ) ] . expect ( "There should be a reason clause" ) ;
315+ // 4. Update clause to the reason of the variable we just resolved away
316+ clause = p. expect ( "There should be a reason clause for this variable" ) . 1 ;
316317 }
317318
318319 // 5. Final cleanup - undo all assignments made at this level
0 commit comments