<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://classes.engineering.wustl.edu/cse231/core/index.php?action=history&amp;feed=atom&amp;title=Sudoku_Constraint_Propagation</id>
	<title>Sudoku Constraint Propagation - Revision history</title>
	<link rel="self" type="application/atom+xml" href="http://classes.engineering.wustl.edu/cse231/core/index.php?action=history&amp;feed=atom&amp;title=Sudoku_Constraint_Propagation"/>
	<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse231/core/index.php?title=Sudoku_Constraint_Propagation&amp;action=history"/>
	<updated>2026-12-01T22:02:55Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.34.4</generator>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse231/core/index.php?title=Sudoku_Constraint_Propagation&amp;diff=3129&amp;oldid=prev</id>
		<title>Cosgroved at 21:50, 24 September 2021</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse231/core/index.php?title=Sudoku_Constraint_Propagation&amp;diff=3129&amp;oldid=prev"/>
		<updated>2021-09-24T21:50:49Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;Revision as of 21:50, 24 September 2021&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l80&quot; &gt;Line 80:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 80:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;====eliminate(resultOptionSets,square,value)====&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;====eliminate(resultOptionSets,square,value)====&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;{{Sequential|private void eliminate(Map&amp;lt;Square, SortedSet&amp;lt;Integer&amp;gt;&amp;gt; resultOptionSets, Square square, int value)}}&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;{{Sequential|private void eliminate(Map&amp;lt;Square, SortedSet&amp;lt;Integer&amp;gt;&amp;gt; resultOptionSets, Square square, int value)}}&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;===(Optional) Advanced Constraint Propagation===&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;====Unit Constraint Propagation====&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;The second rule in [http://norvig.com/sudoku.html Peter Norvig's Essay] is Unit Constraint Propagation: &amp;quot;If a unit has only one possible place for a value, then put the value there&amp;quot;. This propagation rule is it bit more challenging to put into code, but doing so can make even the hardest of Sudoku puzzles fall nice and quickly. To complete this bonus part of the lab, simply update your &amp;lt;code&amp;gt;assign&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;eliminate&amp;lt;/code&amp;gt; methods to do unit constraint propagation (don't remove the old propagation rule!). After assigning a square, you'll have to look at the new options set to see if any unit (a single row, column, or box) has only one unassigned square that is a possibility for any value. We encourage you to think of a solution on your own! Below is a example of unit constraint propagation.&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;{| class=&amp;quot;wikitable&amp;quot;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;		|-&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;		! Board !! Info&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;		|-&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;		| [[File:UnitConstraint1.PNG|200px]]  || We can see that the red square (E1) has only one available option. At this point, let's say we call assign on the red square E1 for the value 6.&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;		|-&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;		| [[File:UnitConstraint2.PNG|200px]]  || Due to the assignment of red square E1, the value of 6 is eliminated from its peer, yellow square A1. &lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;                |-&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;                | [[File:UnitConstraint3.PNG|200px]]  || Our Peer Elimination constraint propagation will treat yellow square A1 as if it has been assigned. Unfortunately, eliminating the value 9 from the peers doesn't open up any new opportunities for solving squares. This is where unit constraint propagation kicks in. Of the three unassigned squares in the top left box unit, 6 is only a valid option in the green square, C3. Even though green square C3 has multiple possible options remaining, we know that it '''must''' be 6, and should assign it as such&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;                |-&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;                | [[File:UnitConstraint4.PNG|200px]]  || Once green square C3 has been assigned (all other options are removed), we should make sure that all of C3's peers have 6 removed from their options. And keep an eye out for any new squares that we now know due to the two propagation rules! With both peer elimination and unit constraint propagation, we can solve a large quantity of Sudoku puzzles without needing any backtracking recursion&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;		|}&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;====Naked Twins====&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;In what is dubbed a [http://www.sudokudragon.com/sudokustrategy.htm more sophisticated strategy] in [http://norvig.com/sudoku.html Peter Norvig's Essay] is Naked Twins strategy which ''&amp;quot;looks for two squares in the same unit that both have the same two possible digits. Given {'A5': '26', 'A6':'26', ...}, we can conclude that 2 and 6 must be in A5 and A6 (although we don't know which is where), and we can therefore eliminate 2 and 6 from every other square in the A row unit. We could code that strategy in a few lines by adding an elif len(values[s]) == 2 test to eliminate.&amp;quot;''&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;====Tips====&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;*Make sure your solver uses the generic SquareSearchAlgorithm so that it works with both versions of the search ordering.&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;*Just like n-queens, your &amp;lt;code&amp;gt;solveKernel&amp;lt;/code&amp;gt; is the recursive method that will be called in the solve method. Again, watch where you put your &amp;lt;code&amp;gt;finish&amp;lt;/code&amp;gt;.&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;*In your &amp;lt;code&amp;gt;solveKernel&amp;lt;/code&amp;gt; method, you should use the given search algorithm (row major or fewest options first) to select which square you will fill. After selecting a square, you should recursively call the kernel to check every viable option in the context of the puzzle. If there are no more unfilled squares, you should set the value of the solution to the finished puzzle and exit out of the recursion.&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Cosgroved</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse231/core/index.php?title=Sudoku_Constraint_Propagation&amp;diff=3118&amp;oldid=prev</id>
		<title>Cosgroved: Created page with &quot;===Constraint Propagator===  {{CodeToImplement|DefaultConstraintPropagator|createCandidateSetsFromGivens&lt;br&gt;createNextCandidateSets&lt;br&gt;assign&lt;br&gt;eliminate|sudoku.lab}}  You wi...&quot;</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse231/core/index.php?title=Sudoku_Constraint_Propagation&amp;diff=3118&amp;oldid=prev"/>
		<updated>2021-09-23T20:26:44Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;===Constraint Propagator===  {{CodeToImplement|DefaultConstraintPropagator|createCandidateSetsFromGivens&amp;lt;br&amp;gt;createNextCandidateSets&amp;lt;br&amp;gt;assign&amp;lt;br&amp;gt;eliminate|sudoku.lab}}  You wi...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;===Constraint Propagator===&lt;br /&gt;
&lt;br /&gt;
{{CodeToImplement|DefaultConstraintPropagator|createCandidateSetsFromGivens&amp;lt;br&amp;gt;createNextCandidateSets&amp;lt;br&amp;gt;assign&amp;lt;br&amp;gt;eliminate|sudoku.lab}}&lt;br /&gt;
&lt;br /&gt;
You will need to implement two public methods to satisfy the ConstraintPropagator interface: &amp;lt;code&amp;gt;createCandidateSetsFromGivens&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;createNextCandidateSets&amp;lt;/code&amp;gt;.  Each of these two methods will be invoked from a different constructor in the [[#DefaultImmutableSudokuPuzzle]] class.  It should be relatively obvious which one goes with which based on the parameters.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
{{Warning| Resist the temptation to perform the constraint propagation in these public methods.  Get things set up and then get your private method(s) to work for you.}}&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Warning| &amp;lt;br/&amp;gt;Resist the temptation to cut corners or lock in the given values too soon.&amp;lt;br/&amp;gt;Load up the entire board with each square associated with all 9 candidates.&amp;lt;br/&amp;gt;  Then in a separate phase assign the givens. }}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====createCandidateSetsFromGivens====&lt;br /&gt;
{{Sequential|public Map&amp;lt;Square, SortedSet&amp;lt;Integer&amp;gt;&amp;gt; createCandidateSetsFromGivens(String givens)}}&lt;br /&gt;
&lt;br /&gt;
This method will be invoked when you have loaded a new puzzle.  Whether it is from the newspaper, or your airline magazine, or Dr. Arto Inkala there is a set of givens the puzzle creator has provided. That string of givens is parsed into a Map from Square to Optional&amp;lt;Integer&amp;gt;.  If a square is given (that is it has a specified starting value) the Optional will be present and its value will be set.  If a specific spot of the board wasn't given in the input, it will be empty.  &lt;br /&gt;
&lt;br /&gt;
{{Tip| A good choice for Maps which have enums as their keys is EnumMap.  Use &amp;lt;code&amp;gt;new EnumMap&amp;lt;&amp;gt;(Square.class)&amp;lt;/code&amp;gt; for an EnumMap of Squares.}}&lt;br /&gt;
&lt;br /&gt;
A good approach here is to start of by initializing all of the squares to all the options (1 through 9) whether or not the square has a given value.  &lt;br /&gt;
&lt;br /&gt;
{{Tip| &amp;lt;code&amp;gt;Square.values()&amp;lt;/code&amp;gt; is useful here for iterating over all of the Square enum constants. }}&lt;br /&gt;
&lt;br /&gt;
{{Tip| [&amp;lt;code&amp;gt;CandidateSet.createAllCandidates()&amp;lt;/code&amp;gt; is useful here when looking to start a square's candidates off at [1,2,3,4,5,6,7,8,9]. }}&lt;br /&gt;
&lt;br /&gt;
Once that is complete go through the givens and get your private method(s) to work for you.&lt;br /&gt;
&lt;br /&gt;
====createNextCandidateSets====&lt;br /&gt;
{{Sequential|public Map&amp;lt;Square, SortedSet&amp;lt;Integer&amp;gt;&amp;gt; createNextCandidateSets(Map&amp;lt;Square, SortedSet&amp;lt;Integer&amp;gt;&amp;gt; otherCandidateSets, Square square, int value)}}&lt;br /&gt;
&lt;br /&gt;
This method should be invoked when you are searching for the solution in your solver.  Much like when you need to create a new copy of the board every time you make a decision in the n-queens search so too will you need to create a new copy of your sudoku board every time you make a decision in your backtracking search.&lt;br /&gt;
&lt;br /&gt;
Make sure to use the &amp;lt;code&amp;gt;[https://www.cse.wustl.edu/~cosgroved/courses/cse231/current/apidocs/sudoku/core/SudokuUtils.html#deepCopyOf(java.util.Map) SudokuUtils.deepCopyOf]&amp;lt;/code&amp;gt; method and refrain from mutating the incoming parameter &amp;lt;code&amp;gt;otherCandidateSets&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
As warned above, do not actually do any of the constraint propagation in this method. Simply get the copy of the options set, then leverage your private &amp;lt;code&amp;gt;assign&amp;lt;/code&amp;gt; method (which in turn may leverage &amp;lt;code&amp;gt;eliminate&amp;lt;/code&amp;gt;) to update the copy to be correct before returning it.&lt;br /&gt;
&lt;br /&gt;
{{Tip |If you have two Lists, &amp;lt;code&amp;gt;a&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;b&amp;lt;/code&amp;gt;, and you set &amp;lt;code&amp;gt;a &amp;lt;nowiki&amp;gt;=&amp;lt;/nowiki&amp;gt; b&amp;lt;/code&amp;gt;, then any changes you make to &amp;lt;code&amp;gt;a&amp;lt;/code&amp;gt; will also be made to &amp;lt;code&amp;gt;b&amp;lt;/code&amp;gt;. Both variables reference the same objects; they are not copies.}}&lt;br /&gt;
&lt;br /&gt;
====Assign and Eliminate====&lt;br /&gt;
&lt;br /&gt;
=====Background=====&lt;br /&gt;
&lt;br /&gt;
[http://norvig.com/sudoku.html Peter Norvig's Essay] is very helpful here.  We have adopted his terms, but challenge yourself to complete this section without simply translating his pseudocode.&lt;br /&gt;
&lt;br /&gt;
To simplify things a bit, we have elected to not short circuit when a 0 option square is found (relying on the search ordering to take care of that for us).&lt;br /&gt;
&lt;br /&gt;
It is up to you how to utilize these two methods. The goal is to update the map that is passed in to reflect the &amp;quot;solving&amp;quot; of a square. For example, if assign is called on square A1 for the value 1, the map that is returned should link the square A1 to a list containing just the value 1 ([1]). Furthermore, any square that is a peer of A1 (ex. B1), should not have the value 1 in its set in the map. &lt;br /&gt;
&lt;br /&gt;
But in solving Sudoku, there are some strategies that we can rely on to more efficiently complete the puzzle. The first one, and required in order to finish this lab, is ''Peer Elimination Constraint Propagation'' (rule 1 in the Norvig essay). The rule is as follows: &amp;quot;If a square has only one possible value, then eliminate that value from the square's peers.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Let's very slowly walk through a example of this propagation in detail to make it more clear what we are looking for. Start by looking at this nearly finished board:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
		|-&lt;br /&gt;
		! Board !! Info&lt;br /&gt;
		|-&lt;br /&gt;
		| [[File:PeerConstraint1.PNG|200px]]  || We can see that the red square (D1) has only one available option. At this point, let's say we call assign on the red square D1 for the value 1.&lt;br /&gt;
		|-&lt;br /&gt;
		| [[File:PeerConstraint3.PNG|200px]]  || As part of the assignment process, all the peers of red square D1 have the value 1 removed from their possibilities. In this example, yellow square, A1, is directly affected! After eliminating the alternative option, there is only one possible value yellow square A1 could be. This is where our constraint propagator needs to take the next step and treat yellow square A1 as assigned.&lt;br /&gt;
                |-&lt;br /&gt;
                | [[File:PeerConstraint4.PNG|200px]]  || This step right here (going from a small 7 to a big 7) is not actually something our program will do. In our implementation, '''having only one option in a square's set is equivalent to that square being &amp;quot;assigned&amp;quot; to that value'''. Because of this, you actually do not need to call assign again for yellow square A1.&lt;br /&gt;
                |-&lt;br /&gt;
                | [[File:PeerConstraint5.PNG|200px]]  || Now that yellow square A1 is known, the final step is to go through all of A1's peers (including green square C3) and remove the value 7. Note that now there is only one possible option left for green square C3. Your code should keep going, looking at all the peers of C3 and eliminating the value 1, and so on. Some puzzles can be completely solved using only Peer Elimination constraint propagation!&lt;br /&gt;
		|}&lt;br /&gt;
&lt;br /&gt;
===== Two Paths =====&lt;br /&gt;
====== All Assign All The Time ======&lt;br /&gt;
In this implementation, you will perform all of your work in the assign method.  eliminate will never be invoked.&lt;br /&gt;
====== Mutual Recursion ======&lt;br /&gt;
In this implementation, assign and eliminate will take on their own roles, at times calling each other.  This implementation leads nicely into the extra credit portion.&lt;br /&gt;
&lt;br /&gt;
=====assign(resultOptionSets,square,value)=====&lt;br /&gt;
{{Sequential|private void assign(Map&amp;lt;Square, SortedSet&amp;lt;Integer&amp;gt;&amp;gt; resultOptionSets, Square square, int value)}}&lt;br /&gt;
&lt;br /&gt;
{{Tip|If you are hitting a ConcurrentModificationException here, make sure you are using CandidateSet. }}&lt;br /&gt;
&lt;br /&gt;
{{Tip|If you are hitting a ConcurrentModificationException here and you are using CandidateSet, think about how a chain reaction might be causing what you ensured to no longer be true. }}&lt;br /&gt;
&lt;br /&gt;
====eliminate(resultOptionSets,square,value)====&lt;br /&gt;
{{Sequential|private void eliminate(Map&amp;lt;Square, SortedSet&amp;lt;Integer&amp;gt;&amp;gt; resultOptionSets, Square square, int value)}}&lt;/div&gt;</summary>
		<author><name>Cosgroved</name></author>
		
	</entry>
</feed>