Implementation: Tree CSP Solver#432
Implementation: Tree CSP Solver#432antmarakis wants to merge 3 commits intoaimacode:masteraimacode/aima-python:masterfrom antmarakis:tcs_patchCopy head branch name to clipboard
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_solverand 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_domainswhich convertsUniversalDictto 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.