-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
87bc423
commit a021c5f
Showing
7 changed files
with
78 additions
and
38 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from numpy import argsort | ||
from util.iterable import pick_by | ||
|
||
from lib_satprob.problem import Problem | ||
from lib_satprob.variables import Variables | ||
|
||
|
||
def rho_subset( | ||
problem: Problem, variables: Variables, of_size: int | ||
) -> Variables: | ||
formula = problem.encoding.get_formula() | ||
with problem.solver.get_instance(formula, use_timer=False) as solver: | ||
_indexes = argsort([sum(( | ||
solver.propagate(var.substitute({var: 0})).stats['propagations'], | ||
solver.propagate(var.substitute({var: 1})).stats['propagations'], | ||
)) for var in variables])[::-1][:of_size] | ||
|
||
return Variables(from_vars=pick_by(variables.variables(), _indexes)) |