-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to search for literals for stronger explanations
- Loading branch information
Showing
13 changed files
with
393 additions
and
331 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub(crate) mod decision; | ||
pub(crate) mod explanation; | ||
pub(crate) mod initialization; | ||
pub(crate) mod inspection; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
use crate::{ | ||
actions::{inspection::InspectionActions, trailing::TrailingActions}, | ||
solver::{ | ||
engine::int_var::IntVarRef, | ||
view::{BoolViewInner, IntViewInner}, | ||
}, | ||
BoolView, IntView, LitMeaning, | ||
}; | ||
|
||
pub(crate) trait DecisionActions: InspectionActions + TrailingActions { | ||
fn get_int_lit(&mut self, var: IntView, mut meaning: LitMeaning) -> BoolView { | ||
{ | ||
if let IntViewInner::Linear { transformer, .. } | ||
| IntViewInner::Bool { transformer, .. } = var.0 | ||
{ | ||
if let Some(m) = transformer.rev_transform_lit(meaning) { | ||
meaning = m; | ||
} else { | ||
return BoolView(BoolViewInner::Const(false)); | ||
} | ||
} | ||
|
||
match var.0 { | ||
IntViewInner::VarRef(var) | IntViewInner::Linear { var, .. } => { | ||
self.get_intref_lit(var, meaning) | ||
} | ||
IntViewInner::Const(c) => BoolView(BoolViewInner::Const(match meaning { | ||
LitMeaning::Eq(i) => c == i, | ||
LitMeaning::NotEq(i) => c != i, | ||
LitMeaning::GreaterEq(i) => c >= i, | ||
LitMeaning::Less(i) => c < i, | ||
})), | ||
IntViewInner::Bool { lit, .. } => { | ||
let (meaning, negated) = | ||
if matches!(meaning, LitMeaning::NotEq(_) | LitMeaning::Less(_)) { | ||
(!meaning, true) | ||
} else { | ||
(meaning, false) | ||
}; | ||
let bv = BoolView(match meaning { | ||
LitMeaning::Eq(0) => BoolViewInner::Lit(!lit), | ||
LitMeaning::Eq(1) => BoolViewInner::Lit(lit), | ||
LitMeaning::Eq(_) => BoolViewInner::Const(false), | ||
LitMeaning::GreaterEq(1) => BoolViewInner::Lit(lit), | ||
LitMeaning::GreaterEq(i) if i > 1 => BoolViewInner::Const(false), | ||
LitMeaning::GreaterEq(_) => BoolViewInner::Const(true), | ||
_ => unreachable!(), | ||
}); | ||
if negated { | ||
!bv | ||
} else { | ||
bv | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
fn get_intref_lit(&mut self, var: IntVarRef, meaning: LitMeaning) -> BoolView; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,9 @@ | ||
use crate::{ | ||
actions::inspection::InspectionActions, | ||
solver::{ | ||
engine::int_var::IntVarRef, | ||
view::{BoolViewInner, IntViewInner}, | ||
}, | ||
BoolView, IntView, LitMeaning, | ||
}; | ||
use crate::{actions::inspection::InspectionActions, BoolView, IntView, LitMeaning}; | ||
|
||
pub(crate) trait ExplanationActions: InspectionActions { | ||
fn try_int_lit(&self, var: IntView, meaning: LitMeaning) -> Option<BoolView>; | ||
fn get_intref_lit(&mut self, var: IntVarRef, meaning: LitMeaning) -> BoolView; | ||
fn get_int_lit(&mut self, var: IntView, mut meaning: LitMeaning) -> BoolView { | ||
if let IntViewInner::Linear { transformer, .. } | IntViewInner::Bool { transformer, .. } = | ||
var.0 | ||
{ | ||
if let Some(m) = transformer.rev_transform_lit(meaning) { | ||
meaning = m; | ||
} else { | ||
return BoolView(BoolViewInner::Const(false)); | ||
} | ||
} | ||
|
||
match var.0 { | ||
IntViewInner::VarRef(var) | IntViewInner::Linear { var, .. } => { | ||
self.get_intref_lit(var, meaning) | ||
} | ||
IntViewInner::Const(c) => BoolView(BoolViewInner::Const(match meaning { | ||
LitMeaning::Eq(i) => c == i, | ||
LitMeaning::NotEq(i) => c != i, | ||
LitMeaning::GreaterEq(i) => c >= i, | ||
LitMeaning::Less(i) => c < i, | ||
})), | ||
IntViewInner::Bool { lit, .. } => { | ||
let (meaning, negated) = | ||
if matches!(meaning, LitMeaning::NotEq(_) | LitMeaning::Less(_)) { | ||
(!meaning, true) | ||
} else { | ||
(meaning, false) | ||
}; | ||
let bv = BoolView(match meaning { | ||
LitMeaning::Eq(0) => BoolViewInner::Lit(!lit), | ||
LitMeaning::Eq(1) => BoolViewInner::Lit(lit), | ||
LitMeaning::Eq(_) => BoolViewInner::Const(false), | ||
LitMeaning::GreaterEq(1) => BoolViewInner::Lit(lit), | ||
LitMeaning::GreaterEq(i) if i > 1 => BoolViewInner::Const(false), | ||
LitMeaning::GreaterEq(_) => BoolViewInner::Const(true), | ||
_ => unreachable!(), | ||
}); | ||
if negated { | ||
!bv | ||
} else { | ||
bv | ||
} | ||
} | ||
} | ||
} | ||
fn get_int_val_lit(&mut self, var: IntView) -> Option<BoolView> { | ||
self.get_int_val(var) | ||
.map(|v| self.get_int_lit(var, LitMeaning::Eq(v))) | ||
} | ||
fn get_int_lit_or_weaker(&mut self, var: IntView, meaning: LitMeaning) -> BoolView; | ||
fn get_int_val_lit(&mut self, var: IntView) -> Option<BoolView>; | ||
fn get_int_lower_bound_lit(&mut self, var: IntView) -> BoolView; | ||
fn get_int_upper_bound_lit(&mut self, var: IntView) -> BoolView; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.