-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Implementation: Tree CSP Solver #432
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@MrDupin Nice work, but just some suggestions:
With that said, my ideia for the code was something like this: def make_arc_consistent(Xj, Xk, csp):
"""Make arc between parent (Xj) and child (Xk) consistent under the csp's constraints,
by removing the possible values of Xj that cause inconsistencies."""
for val1 in csp.domains[Xj]:
for val2 in csp.domains[Xk]:
if not csp.constraints(Xj, val1, Xk, val2):
csp.prune(Xj, val1)
return csp.curr_domains[Xj] But again, this will require calling the support_prunning method. But this is just an idea.
|
@lucasmoura: Thanks for the feedback.
|
Accidentally deleted branch, will now make new PR. Sorry about that. New PR is #434. |
Completed the implementation of
tree_csp_solver
and added tests. In detail:make_arc_consistent
. For a node n and its parent p, it removes the possible values of p which do not have a consistent assignment with any possible value of n.assign
. It assigns a value to a node consistent to the assignment of the node's parent.node_domains
which convertsUniversalDict
to a built-in dictionary. This way we can play around more with the dictionaries.Note: I had to add two new lines to the algorithm for initialization purposes. If that's an issue, I can work them into the called functions, but it will be ugly.