<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE article  PUBLIC "-//NLM//DTD Journal Publishing DTD v3.0 20080202//EN" "http://dtd.nlm.nih.gov/publishing/3.0/journalpublishing3.dtd"><article xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:xlink="http://www.w3.org/1999/xlink" dtd-version="3.0" xml:lang="en" article-type="research article"><front><journal-meta><journal-id journal-id-type="publisher-id">AJOR</journal-id><journal-title-group><journal-title>American Journal of Operations Research</journal-title></journal-title-group><issn pub-type="epub">2160-8830</issn><publisher><publisher-name>Scientific Research Publishing</publisher-name></publisher></journal-meta><article-meta><article-id pub-id-type="doi">10.4236/ajor.2016.63022</article-id><article-id pub-id-type="publisher-id">AJOR-66317</article-id><article-categories><subj-group subj-group-type="heading"><subject>Articles</subject></subj-group><subj-group subj-group-type="Discipline-v2"><subject>Physics&amp;Mathematics</subject></subj-group></article-categories><title-group><article-title>
 
 
  An Integer Programming Model for the KenKen Problem
 
</article-title></title-group><contrib-group><contrib contrib-type="author" xlink:type="simple"><name name-style="western"><surname>ardges</surname><given-names>Melkonian</given-names></name><xref ref-type="aff" rid="aff1"><sub>1</sub></xref><xref ref-type="corresp" rid="cor1"><sup>*</sup></xref></contrib></contrib-group><aff id="aff1"><label>1</label><addr-line>Department of Mathematics, Ohio University, Athens, Ohio, USA</addr-line></aff><author-notes><corresp id="cor1">* E-mail:<email>melkonia@ohio.edu</email></corresp></author-notes><pub-date pub-type="epub"><day>10</day><month>05</month><year>2016</year></pub-date><volume>06</volume><issue>03</issue><fpage>213</fpage><lpage>225</lpage><history><date date-type="received"><day>21</day>	<month>March</month>	<year>2016</year></date><date date-type="rev-recd"><day>accepted</day>	<month>7</month>	<year>May</year>	</date><date date-type="accepted"><day>10</day>	<month>May</month>	<year>2016</year></date></history><permissions><copyright-statement>&#169; Copyright  2014 by authors and Scientific Research Publishing Inc. </copyright-statement><copyright-year>2014</copyright-year><license><license-p>This work is licensed under the Creative Commons Attribution International License (CC BY). http://creativecommons.org/licenses/by/4.0/</license-p></license></permissions><abstract><p>
 
 
  In this paper we consider modeling techniques for the mathematical puzzle KenKen. It is an interesting puzzle from modeling point of view since it has different kind of mathematical restrictions that are not trivial to express as linear constraints. We give an integer program for solving KenKen and and its implementation on modeling language AMPL. Our integer program uses an innovative way for converting product restrictions into linear constraints. It can be also used for teaching various integer programming techniques in an Operations Research course.
 
</p></abstract><kwd-group><kwd>Integer Programming</kwd><kwd>Mathematical Games</kwd><kwd>Education Operations Research</kwd><kwd>Discrete Optimization</kwd></kwd-group></article-meta></front><body><sec id="s1"><title>1. Introduction</title><p>A KenKen puzzle is a grid of n by n cells (see <xref ref-type="fig" rid="fig1">Figure 1</xref>). The goal is to fill the whole grid with numbers 1 to n, making sure no number is repeated in any row and column. An additional feature of KenKen (compared to a similar puzzle Sudoku) is that the grid is partitioned into “cages”. Each cage consists of several adjacent cells. The top left corner of each cage has a target number and an arithmetic operation (sum, difference, product, ratio). The numbers entered into a cage must combine (in any order) to produce the target number using the arithmetic operation. An 8 by 8 example of KenKen is given in <xref ref-type="fig" rid="fig1">Figure 1</xref>. This is a real example from KenKen website [<xref ref-type="bibr" rid="scirp.66317-ref1">1</xref>] .</p><p>Among similar puzzles, KenKen is particularly interesting for mathematicians. Thanks to its mathematical constraints, it creates a different level of interest and challenge for the solver. It is also a more challenging task to create a mathematical model that can solve the puzzle.</p><p>While Sudoku has been studied extensively, not much research has been done on KenKen. [<xref ref-type="bibr" rid="scirp.66317-ref2">2</xref>] shows how ideas from number theory can be used to solve KenKen. [<xref ref-type="bibr" rid="scirp.66317-ref3">3</xref>] discusses how KenKen can be used to develop rea-</p><fig id="fig1"  position="float"><label><xref ref-type="fig" rid="fig1">Figure 1</xref></label><caption><title> An example of 8 &#215; 8 KenKen</title></caption><graphic mimetype="image"   position="float"  xlink:type="simple"  xlink:href="http://html.scirp.org/file/1-1040464x6.png"/></fig><p>soning skills for different levels of students. In this paper we give an integer programming model for solving KenKen. The Latin square constraints were given before for Sudoku [<xref ref-type="bibr" rid="scirp.66317-ref4">4</xref>] [<xref ref-type="bibr" rid="scirp.66317-ref5">5</xref>] . Our contribution is giving linear constraints for sum, difference, product, and ratio restrictions. The product restrictions are the hardest ones for expressing by linear constraints. We give a non-standard way of using prime number factorizations for product constraints. The other parts of the model use different integer programming techniques, such as Either-Or constraints, converting absolute values to linear constraints, using auxiliary binary variables. Thus, the model could be an example for teaching different integer programming techniques.</p><p>We implemented the model on optimization modeling language AMPL [<xref ref-type="bibr" rid="scirp.66317-ref6">6</xref>] and tested on examples. The implementation requires different data structures needed for the model, such as prime number factorization of a number. The AMPL techniques also can be a good teaching tool on how to implement an integer programming model with an optimization software.</p><p>The paper is organized as follows. Section 2 gives the set of constraints that make the solution a Latin square. Sections 3, 4, 5, 6 cover sum, difference, ratio, product constraints correspondingly. Section 7 gives the AMPL model and an analysis of the solution. An Appendix section gives more details on a secondary method for converting product restrictions to linear constraints.</p></sec><sec id="s2"><title>2. Latin Square Constraints</title><p>First we need to give constraints to provide that the numbers filling the grid form a Latin square, that is, each number occurs exactly once in each row and exactly once in each column. This type of constraints was given before for Sudoku puzzles (reference). The following binary variables are essential for giving those constraints.</p><disp-formula id="scirp.66317-formula1"><graphic  xlink:href="http://html.scirp.org/file/1-1040464x7.png"  xlink:type="simple"/></disp-formula><p>The following set of constraints provide that each cell (i, j) gets exactly one value k from<inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x8.png" xlink:type="simple"/></inline-formula>.</p><p><inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x9.png" xlink:type="simple"/></inline-formula>for each cell (i, j) (2.1)</p><p>The following set of constraints provides that there is exactly one number k in each row i:</p><p><inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x10.png" xlink:type="simple"/></inline-formula>for each row i and each number k from <inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x11.png" xlink:type="simple"/></inline-formula> (2.2)</p><p>The following set of constraints provides that there is exactly one number k in each column j:</p><p><inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x12.png" xlink:type="simple"/></inline-formula>for each column j and each number k from <inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x13.png" xlink:type="simple"/></inline-formula> (2.3)</p></sec><sec id="s3"><title>3. Addition Constraints</title><p>While the binary variables defined are useful for giving the Latin square constraints, there is not a good way of using them to express the arithmetic restrictions by linear constraints. As we will see below, it is more helpful to define the following general integer variables for those constraints.</p><p>Let y<sub>ij</sub> be the numerical value assigned to cell (i, j). The possible values to be assigned to y<sub>ij</sub> are numbers 1 to n. This new set of variables can be easily used to express the summation restrictions by linear constraints. For a cage C having a target number t and arithmetic operation “+”, the constraint is</p><disp-formula id="scirp.66317-formula2"><label>(3.1)</label><graphic position="anchor" xlink:href="http://html.scirp.org/file/1-1040464x14.png"  xlink:type="simple"/></disp-formula><p>For example, the cage consisting of cells (3, 1), (3, 2) and (3, 3) in <xref ref-type="fig" rid="fig1">Figure 1</xref> needs the following constraint:<inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x15.png" xlink:type="simple"/></inline-formula>.</p><p>The new integer variables should be connected to the original binary variables. For each cell (i, j), the connection is given by the following constraint.</p><disp-formula id="scirp.66317-formula3"><label>(3.2)</label><graphic position="anchor" xlink:href="http://html.scirp.org/file/1-1040464x16.png"  xlink:type="simple"/></disp-formula><p>The constraints (3.1) and (3.2) together provide that y<sub>ij</sub> takes the value k for which the corresponding variable x<sub>ijk</sub> is equal to 1.</p><p>Note that constraint (3.2) is an example of an integer programming technique to provide that a variable takes one of the given values, 1 to n in this case.</p><p>Constraint (3.2) provides that y<sub>ij</sub> is a sum of products of integers, and thus it can take only integer values. Therefore, there is no need to require variables y<sub>ij</sub> to be integers since (3.2) will guarantee it. This observation reduces the number of integer variables in the model, thus making the solution process more efficient.</p></sec><sec id="s4"><title>4. Difference Constraints</title><p>A difference restriction is given for two adjacent cells with a target number d. For example, if the cells are (i, j) and (i, j + 1) then the restriction is that either <inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x17.png" xlink:type="simple"/></inline-formula> or<inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x18.png" xlink:type="simple"/></inline-formula>. This is an example of Either-Or constraints (reference). While each of the two equalities is a linear constraint, their Either-Or combination is not. It should be replaced by an equivalent set of constraints where all of them must hold. It is normally done by introducing a new binary variable and using the big M method [<xref ref-type="bibr" rid="scirp.66317-ref7">7</xref>] . However, that method works when each of the Either-Or constraints is an inequality. In the case of equalities, first each of them should be switched to a pair of equivalent inequalities and only then applying the standard technique. But in this case there is a simpler way of switching to linear constraints as explained below.</p><p>Note that requiring to have one of <inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x19.png" xlink:type="simple"/></inline-formula> or <inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x20.png" xlink:type="simple"/></inline-formula> hold is equivalent of requiring that</p><p><inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x21.png" xlink:type="simple"/></inline-formula>.</p><p>The absolute value makes the constraint nonlinear. But it has the following equivalent linear constraint</p><disp-formula id="scirp.66317-formula4"><label>, (4.1)</label><graphic position="anchor" xlink:href="http://html.scirp.org/file/1-1040464x22.png"  xlink:type="simple"/></disp-formula><p>where u is an auxiliary binary variable.</p><p>When u = 0, (4.1) becomes<inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x23.png" xlink:type="simple"/></inline-formula>; while when u = 1, (4.1) becomes<inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x23.png" xlink:type="simple"/></inline-formula><inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x24.png" xlink:type="simple"/></inline-formula>.</p><p>For example, the cage consisting of cells (1, 3) and (1, 4) in <xref ref-type="fig" rid="fig1">Figure 1</xref> needs the following constraint:<inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x25.png" xlink:type="simple"/></inline-formula>.</p></sec><sec id="s5"><title>5. Division Constraints</title><p>A division restriction is given for two adjacent cells with a target number r. For example, if the cells are (i, j) and (i, j + 1) then the restriction is that either <inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x26.png" xlink:type="simple"/></inline-formula> or<inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x26.png" xlink:type="simple"/></inline-formula><inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x27.png" xlink:type="simple"/></inline-formula>. This is another example of Either-Or constraints. But unlike the difference constraints, there is no simple way of switching it to equivalent linear constraints. Below is given the sequence of steps for achieving linearity.</p><p>1) <inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x28.png" xlink:type="simple"/></inline-formula>or<inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x28.png" xlink:type="simple"/></inline-formula><inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x29.png" xlink:type="simple"/></inline-formula>.</p><p>2) <inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x30.png" xlink:type="simple"/></inline-formula>or <inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x30.png" xlink:type="simple"/></inline-formula><inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x31.png" xlink:type="simple"/></inline-formula> (by simple algebra).</p><p>3) (<inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x32.png" xlink:type="simple"/></inline-formula>and<inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x32.png" xlink:type="simple"/></inline-formula><inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x33.png" xlink:type="simple"/></inline-formula>) or (<inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x32.png" xlink:type="simple"/></inline-formula><inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x33.png" xlink:type="simple"/></inline-formula><inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x34.png" xlink:type="simple"/></inline-formula>and<inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x32.png" xlink:type="simple"/></inline-formula><inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x33.png" xlink:type="simple"/></inline-formula><inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x34.png" xlink:type="simple"/></inline-formula><inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x35.png" xlink:type="simple"/></inline-formula>)</p><p>(by switching to equivalent pairs of inequalities).</p><p>4) <inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x36.png" xlink:type="simple"/></inline-formula> (5.1)</p><disp-formula id="scirp.66317-formula5"><label>(5.2)</label><graphic position="anchor" xlink:href="http://html.scirp.org/file/1-1040464x37.png"  xlink:type="simple"/></disp-formula><disp-formula id="scirp.66317-formula6"><label>(5.3)</label><graphic position="anchor" xlink:href="http://html.scirp.org/file/1-1040464x38.png"  xlink:type="simple"/></disp-formula><disp-formula id="scirp.66317-formula7"><label>, (5.4)</label><graphic position="anchor" xlink:href="http://html.scirp.org/file/1-1040464x39.png"  xlink:type="simple"/></disp-formula><p>where u is an auxiliary binary variable and M is a large positive number (its choice is explained below).</p><p>When u = 0, (5.1) and (5.2) together imply <inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x40.png" xlink:type="simple"/></inline-formula> and hence<inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x40.png" xlink:type="simple"/></inline-formula><inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x41.png" xlink:type="simple"/></inline-formula>; while (5.3) and (5.4) do not force any restrictions on the variables.</p><p>When u = 1, (5.3) and (5.4) together imply <inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x42.png" xlink:type="simple"/></inline-formula> and hence<inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x42.png" xlink:type="simple"/></inline-formula><inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x43.png" xlink:type="simple"/></inline-formula>; while (5.1) and (5.2) do not force any restrictions on the variables.</p><p>Thus, constraints (5.1)-(5.4) should be included in the model for every ratio cage.</p><p>Proper choice of big M.</p><p>To solve the integer program efficiently, M should be assigned the smallest possible value. For a puzzle of size n &#215; n, the smallest value for M to make constraints (5.1)-(5.4) work is<inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x44.png" xlink:type="simple"/></inline-formula>. Consider the following example to illustrate that choice. Suppose the target number of a ratio cage is 3 in a puzzle of size 8 &#215; 8. Then the highest cell values satisfying the ratio restriction are 2 and 6. Here 6 is the highest multiple of 3 under 8, and it can be written as 8 ? (8 mod 3); while 2 is 6 div 3 = 8 div 3. Suppose u = 1, y<sub>i</sub><sub>,j+1</sub> = 6, and y<sub>ij</sub> = 2, thus making<inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x44.png" xlink:type="simple"/></inline-formula><inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x45.png" xlink:type="simple"/></inline-formula>. Then the left-hand side of (5.1) is <inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x44.png" xlink:type="simple"/></inline-formula><inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x45.png" xlink:type="simple"/></inline-formula><inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x46.png" xlink:type="simple"/></inline-formula>. Thus, 16 should be the smallest value assigned to M to make constraint (5.1) satisfied.</p><p>In the AMPL model of Section 7, the (5.1)-(5.4) are given in the segment named “ratio constraints”, while big M is defined in the segment named “sets and parameters used in ratio constraints”.</p><p>Example.</p><p>The cage consisting of cells (5, 2) and (5, 3) in <xref ref-type="fig" rid="fig1">Figure 1</xref> needs the following set of constraints:</p><disp-formula id="scirp.66317-formula8"><graphic  xlink:href="http://html.scirp.org/file/1-1040464x47.png"  xlink:type="simple"/></disp-formula><disp-formula id="scirp.66317-formula9"><graphic  xlink:href="http://html.scirp.org/file/1-1040464x48.png"  xlink:type="simple"/></disp-formula><disp-formula id="scirp.66317-formula10"><graphic  xlink:href="http://html.scirp.org/file/1-1040464x49.png"  xlink:type="simple"/></disp-formula><disp-formula id="scirp.66317-formula11"><graphic  xlink:href="http://html.scirp.org/file/1-1040464x50.png"  xlink:type="simple"/></disp-formula></sec><sec id="s6"><title>6. Product Constraints</title><p>Product restrictions are the hardest ones for converting to linear constraints. Simply requiring that the product of y-variables is equal to the target number makes it a nonlinear constraint. We suggest two different ways of giving linear constraints for product restrictions.</p><p>Our main method gives a non-standard way of covering all product restrictions by using prime number factorizations of target numbers. That method is covered in Subsection 6.1 and is the basis of the AMPL model given in Section 7.</p><p>The second method is more intuitive and can be used to practice standard integer programming techniques. The disadvantages of this method are: (i) auxiliary binary variables are needed to write the constraints which makes the solution of the integer program less efficient; (ii) more importantly, while the method covers the most common situations it is not clear how to extend it to the general case. But this method is even more intuitive and simple than method 1 for the most common product restrictions when a cage consists of two cells (3 out of 5 product cages in the example of <xref ref-type="fig" rid="fig1">Figure 1</xref> consist of two cells). Thus, one can use a combination of methods 1 and 2 when building the model. An idea how method 2 works is given in Subsection 6.2 for a special case; the rest of the discussion is in Appendix A.</p><sec id="s6_1"><title>6.1. Method 1 for Product Restrictions</title><p>The method first finds the prime number factorization of the target number. The puzzles in [<xref ref-type="bibr" rid="scirp.66317-ref1">1</xref>] are of size at most 9 &#215; 9. For that kind of puzzles, the prime numbers in the factorizations are 2, 3, 5, 7. In this section we will give constraints for each of those prime numbers for a puzzle of size 9 &#215; 9. But the constraints can be easily generalized to any problem size and any prime number.</p><p>- Product constraint for 5: Suppose the power of 5 in the prime number factorization is d (could also be 0). Then the following constraint should be added.</p><disp-formula id="scirp.66317-formula12"><label>(6.1.1)</label><graphic position="anchor" xlink:href="http://html.scirp.org/file/1-1040464x51.png"  xlink:type="simple"/></disp-formula><p>The constraint provides that the number of cells in cage C getting 5 is d.</p><p>- Product constraint for 7: The constraint for 5 can be easily extended to 7. Suppose the power of 7 in the prime number factorization is d (could also be 0). Then the following constraint should be added.</p><disp-formula id="scirp.66317-formula13"><label>(6.1.2)</label><graphic position="anchor" xlink:href="http://html.scirp.org/file/1-1040464x52.png"  xlink:type="simple"/></disp-formula><p>The constraint provides that the number of cells in cage C getting 7 is d.</p><p>- Product constraint for 3: Suppose the power of 3 in the prime number factorization is d (could also be 0). Then the following constraint should be added.</p><disp-formula id="scirp.66317-formula14"><label>(6.1.3)</label><graphic position="anchor" xlink:href="http://html.scirp.org/file/1-1040464x53.png"  xlink:type="simple"/></disp-formula><p>It is similar to the previous case except that each entry 9 in the cage contributes 2 to the total power of 3, thus the coefficient of x<sub>ij</sub><sub>9</sub> is 2.</p><p>- Product constraint for 2: Suppose the power of 2 in the prime number factorization is d (could also be 0). Then the following constraint should be added.</p><disp-formula id="scirp.66317-formula15"><label>(6.1.4)</label><graphic position="anchor" xlink:href="http://html.scirp.org/file/1-1040464x54.png"  xlink:type="simple"/></disp-formula><p>Here each entry 4 contributes 2 and each entry 8 contributes 3 to the total power of 2. Thus the coefficient of x<sub>ij</sub><sub>4</sub> is 2, and the coefficient of x<sub>ij</sub><sub>8</sub> is 3.</p><p>- A complete example: Suppose the target number is 2520. Its prime number factorization is 2<sup>3</sup> &#215; 3<sup>2</sup> &#215; 5<sup>1</sup> &#215; 7<sup>1</sup>. Then the following set of constraints is needed.</p><disp-formula id="scirp.66317-formula16"><graphic  xlink:href="http://html.scirp.org/file/1-1040464x55.png"  xlink:type="simple"/></disp-formula><disp-formula id="scirp.66317-formula17"><graphic  xlink:href="http://html.scirp.org/file/1-1040464x56.png"  xlink:type="simple"/></disp-formula><disp-formula id="scirp.66317-formula18"><graphic  xlink:href="http://html.scirp.org/file/1-1040464x57.png"  xlink:type="simple"/></disp-formula><disp-formula id="scirp.66317-formula19"><graphic  xlink:href="http://html.scirp.org/file/1-1040464x58.png"  xlink:type="simple"/></disp-formula><p>Note that there is no easy way to extend Method 2 (described in Subsection 6.2 and Appendix A) to this example.</p><p>General product constraint: Let P be the set of prime numbers used in a puzzle of size n &#215; n. For a prime number p &#206; P we define the following three sets.</p><p>M[p] represents the integers from 1 to n that are multiples of p but are not multiples of its square:</p><p><inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x59.png" xlink:type="simple"/></inline-formula>;</p><p>S[p] represents the integers from 1 to n that are multiples of p<sup>2</sup> but are not multiples of p<sup>3</sup>:</p><p><inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x60.png" xlink:type="simple"/></inline-formula>;</p><p>C[p] represents the integers from 1 to n that are multiples of p<sup>3</sup>:</p><p><inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x61.png" xlink:type="simple"/></inline-formula>;</p><p>Note that there are no higher powers of p in actual Kenken puzzles; but the technique can be easily generalized to higher powers too.</p><p>Let power[t, p] be the power of p &#206; P in prime number factorization of target number t. The parameter power[t, p] is recursively computed in the parameters section of the AMPL code. Then we have the following general product constraint for p.</p><disp-formula id="scirp.66317-formula20"><label>(6.1.5)</label><graphic position="anchor" xlink:href="http://html.scirp.org/file/1-1040464x62.png"  xlink:type="simple"/></disp-formula><p>This general constraint represents the product constraints in our AMPL code.</p></sec><sec id="s6_2"><title>6.2. Method 2 for the Case When the Cage Consists of Two Cells and There Is a Single Factorization for the Target Number</title><p>Most product restrictions in KenKen are given for two adjacent cells, and there is a single factorization for the target number. It happens when</p><p>(i) the target number is a prime number, namely, 2, 3, 5, 7;</p><p>(ii) the target number is composite but the size of the puzzle implies a single factorization; for example, when the target number is 4, 9, 10, 14, 15, 16, 20, 21 in puzzles of size at most 9 &#215; 9.</p><p>Case (i). Suppose the cage consists of two adjacent cells (i, j) and (i, j + 1), and the target number is a prime number p. Then the restriction is the following:</p><disp-formula id="scirp.66317-formula21"><label>(6.2.1)</label><graphic position="anchor" xlink:href="http://html.scirp.org/file/1-1040464x63.png"  xlink:type="simple"/></disp-formula><p>There are two ways to convert the restriction to linear constraints.</p><p>Technique 1: Restriction (6.2.1) is equivalent to requiring that</p><disp-formula id="scirp.66317-formula22"><graphic  xlink:href="http://html.scirp.org/file/1-1040464x64.png"  xlink:type="simple"/></disp-formula><p>The Either-Or constraint is equivalent to the following pair of linear constraints:</p><disp-formula id="scirp.66317-formula23"><label>, (6.2.2)</label><graphic position="anchor" xlink:href="http://html.scirp.org/file/1-1040464x65.png"  xlink:type="simple"/></disp-formula><disp-formula id="scirp.66317-formula24"><label>, (6.2.3)</label><graphic position="anchor" xlink:href="http://html.scirp.org/file/1-1040464x66.png"  xlink:type="simple"/></disp-formula><p>where u is an auxiliary binary variable.</p><p>When u = 1, (6.2.2) and (6.2.3) together imply x<sub>ijp</sub> = 1 , x<sub>i</sub><sub>,j+1,1</sub> = 1 , x<sub>ij</sub><sub>1</sub> = 0 , x<sub>i</sub><sub>,j+1,p</sub> = 0; thus cell (i, j) gets value p, and cell (i, j + 1) gets value 1.</p><p>When u = 0, (6.2.2) and (6.2.3) together imply x<sub>ijp</sub> = 0 , x<sub>i</sub><sub>,j+1,1</sub> = 0, x<sub>ij</sub><sub>1</sub> = 1 , x<sub>i</sub><sub>,j+1,p</sub> = 1; thus cell (i, j) gets value 1, and cell (i, j + 1) gets value p.</p><p>Technique 2: The second way is less intuitive but simpler since it is given by just one constraint without using any auxiliary variables.</p><disp-formula id="scirp.66317-formula25"><label>(6.2.4)</label><graphic position="anchor" xlink:href="http://html.scirp.org/file/1-1040464x67.png"  xlink:type="simple"/></disp-formula><p>Another advantage of this second way is that it does not need any new auxiliary binary variables.</p><p>Constraint (6.2.4) does not work by itself but rather with the combination of other constraints we introduced before. Recall that constraint (2.1) provides that each cell gets exactly one value k from<inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x68.png" xlink:type="simple"/></inline-formula>; that constraint for cells (i, j) and (i, j + 1) are given below:</p><disp-formula id="scirp.66317-formula26"><label>(2.1a)</label><graphic position="anchor" xlink:href="http://html.scirp.org/file/1-1040464x69.png"  xlink:type="simple"/></disp-formula><p>Also, constraint (2.2) provides that there is exactly one number k assigned to each row i; that constraint for row i and numbers 1 and p are given below:</p><disp-formula id="scirp.66317-formula27"><label>(2.2a)</label><graphic position="anchor" xlink:href="http://html.scirp.org/file/1-1040464x70.png"  xlink:type="simple"/></disp-formula><p>There are only two combinations of variable values that can satisfy constraints (2.1), (2.1a), (2.2a) at the same time:</p><p>- x<sub>ijp</sub> = 1 , x<sub>i</sub><sub>,j+1,1</sub> = 1, x<sub>ij</sub><sub>1</sub> = 0 , x<sub>i</sub><sub>,j+1,p</sub> = 0; thus cell (i, j) gets value p, and cell (i, j + 1) gets value 1.</p><p>- x<sub>ijp</sub> = 0 , x<sub>i</sub><sub>,j+1,1</sub> = 0, x<sub>ij</sub><sub>1</sub> = 1 , x<sub>i</sub><sub>,j+1,p</sub> = 1; thus cell (i, j) gets value 1, and cell (i, j + 1) gets value p.</p><p>Case (ii). Suppose the target number is composite but the size of the puzzle implies a single factorization. For example, if the target number is 30 for a puzzle of size 9 &#215; 9 then the only factorization is 30 = 5 &#215; 6. The solution for this case is identical to case (i) by taking 5 and 6 instead of 1 and p.</p><p>Example.</p><p>The cage consisting of cells (2, 3) and (2, 4) in <xref ref-type="fig" rid="fig1">Figure 1</xref> needs the following constraint:</p><disp-formula id="scirp.66317-formula28"><graphic  xlink:href="http://html.scirp.org/file/1-1040464x71.png"  xlink:type="simple"/></disp-formula></sec></sec><sec id="s7"><title>7. The AMPL Model and Its Solution</title><p>In this section we give the full AMPL model for the integer program developed in previous sections. The model has comments for most of the parameters, sets, variables, constraints; more detailed explanations about how they work are given in Sections 2-6. We also give a data set for the example of <xref ref-type="fig" rid="fig1">Figure 1</xref> and its solution.</p><p>The model is given in Section 7.1. The data set is in Section 7.2. A brief analysis of the solution process and efficiency follows in Section 7.3.</p></sec><sec id="s8"><title>7.1. The AMPL Model</title><p>######### INPUT DATA: PARAMETERS AND SETS ########</p><p>param n;</p><p># size of the problem</p><p>set rows := 1..n;</p><p>set columns := 1..n;</p><p>set cells := {rows, columns};</p><p>### Cage information ###</p><p>param t; # number of cages</p><p>set cage{1..t} within cells;</p><p># each cage is a collection of cells</p><p>check: forall {(i,j) in cells} card({c in 1..t: (i,j) in cage[c]}) = 1;</p><p># checking that each cell is in exactly one cage</p><p>param target_number{1..t};</p><p>param operation{1..t} symbolic;</p><p># target number and operation for each cage</p><p>### The following parameters are used for giving difference and ratio constraints ###</p><p>### by distinguishing the two cells in difference and ratio cages ###</p><p>param min_cell_number{c in 1..t}:=min{(i,j) in cage[c]}(i+j);</p><p>param max_cell_number{c in 1..t}:=max{(i,j) in cage[c]}(i+j);</p><p>### Sets and parameters used in ratio constraints ###</p><p>set possible_ratio_numbers:=2..n;</p><p># possible ratio numbers in a puzzle of size n</p><p>param bigM{r in possible_ratio_numbers: r&lt;=n}:= r * (n - (n mod r)) - (n div r);</p><p>### Sets and parameters used in product constraints ###</p><p>set prime_numbers;</p><p># prime numbers for puzzles of size up to 9</p><p>set prime_number_multiples {p in prime_numbers}:= {i in 1..n: i mod p = 0 and i mod (p^2) != 0};</p><p>set prime_number_squares {p in prime_numbers}:= {i in 1..n: i mod (p^2) = 0 and i mod (p^3) != 0};</p><p>set prime_number_cubes {p in prime_numbers}:= {i in 1..n: i mod (p^3) = 0};</p><p>param max_multipl_target_numbers := max{c in 1..t: operation[c]='product'} target_number[c];</p><p># maximum product target number in the puzzle</p><p>param prime_number_power {m in 1..max_multipl_target_numbers, p in prime_numbers}</p><p>:= if (m mod p != 0) then 0 else prime_number_power[m div p, p] + 1;</p><p># this parameter gives the power of prime number p in prime number factorization of m</p><p>############################### VARIABLES #################################</p><p>var x{i in rows, j in columns, k in 1..n} binary;</p><p># is equal 1 if value k is assigned to cell (i,j)</p><p>var y{i in rows, j in columns} &gt;=1, &lt;=n;</p><p># the value assigned to cell (i,j)</p><p>var u{c in 1..t: operation[c]='difference' or operation[c]='ratio'} binary;</p><p># auxiliary binary variable for a difference or ratio cage c</p><p>########################### OBJECTIVE FUNCTION ###########################</p><p>maximize something: 1;</p><p>##### no need for an objective function #####</p><p>############################### CONSTRAINTS ###############################</p><p>##### Latin Square Constraints #####</p><p># Constraint (2.1): each cell is assigned exactly one value</p><p>subject to one_value_for_each_cell {i in rows, j in columns}:</p><p>sum{k in 1..n} x[i,j,k]=1;</p><p># Constraint (2.2): each row has exactly one number k</p><p>subject to one_of_each_number_for_each_row{i in rows, k in 1..n}:</p><p>sum{j in columns} x[i,j,k]=1;</p><p># Constraint (2.3): each column has exactly one number k</p><p>subject to one_of_each_number_for_each_column{j in columns, k in 1..n}:</p><p>sum{i in rows} x[i,j,k]=1;</p><p># Constraint (3.2): connection between x and y variables</p><p>subject to value_of_each_square {i in rows, j in columns}:</p><p>y[i,j]=sum{k in 1..n} k*x[i,j,k];</p><p>##### Constraint (3.1): Sum Constraints #####</p><p>s.t. Cage_sum_restriction{c in 1..t: operation[c] == 'sum'}:</p><p>sum{(i,j) in cage[c]} y[i,j] = target_number[c];</p><p>##### Constraint (4.1): Difference Constraints #####</p><p>s.t. Cage_difference_restriction{c in 1..t: operation[c] == 'difference'}:</p><p>sum{(i,j) in cage[c]: i+j == max_cell_number[c]} y[i,j] -</p><p>sum{(i,j) in cage[c]: i+j == min_cell_number[c]} y[i,j] =</p><p>target_number[c] - 2 * target_number[c] * u[c];</p><p>##### Ratio Constraints (5.1)-(5.4) #####</p><p>s.t. Cage_ratio_restriction1{c in 1..t: operation[c] == 'ratio'}:</p><p>sum{(i,j) in cage[c]: i+j = max_cell_number[c]} y[i,j] -</p><p>target_number[c] * sum{(i,j) in cage[c]: i+j = min_cell_number[c]} y[i,j] &gt;=</p><p>- bigM[target_number[c]] * u[c];</p><p>s.t. Cage_ratio_restriction2{c in 1..t: operation[c] == 'ratio'}:</p><p>sum{(i,j) in cage[c]: i+j = max_cell_number[c]} y[i,j] -</p><p>target_number[c] * sum{(i,j) in cage[c]: i+j = min_cell_number[c]} y[i,j] &lt;=</p><p>bigM[target_number[c]] * u[c];</p><p>s.t. Cage_ratio_restriction3{c in 1..t: operation[c] == 'ratio'}:</p><p>sum{(i,j) in cage[c]: i+j = min_cell_number[c]} y[i,j] -</p><p>target_number[c] * sum{(i,j) in cage[c]: i+j = max_cell_number[c]} y[i,j] &gt;=</p><p>- bigM[target_number[c]] * (1 - u[c]);</p><p>s.t. Cage_ratio_restriction4{c in 1..t: operation[c] == 'ratio'}:</p><p>sum{(i,j) in cage[c]: i+j = min_cell_number[c]} y[i,j] -</p><p>target_number[c] * sum{(i,j) in cage[c]: i+j = max_cell_number[c]} y[i,j] &lt;=</p><p>bigM[target_number[c]] * (1 - u[c]);</p><p>##### Product Constraints (6.1.5) #####</p><p>s.t. Cage_product_restriction{c in 1..t, p in prime_numbers: operation[c] == 'product' and p&lt;=n}:</p><p>sum{(i,j) in cage[c], k in prime_number_multiples[p]} x[i,j,k] +</p><p>sum{(i,j) in cage[c], k in prime_number_squares[p]} 2*x[i,j,k] +</p><p>sum{(i,j) in cage[c], k in prime_number_cubes[p]} 3*x[i,j,k] = prime_number_power[target_number[c],p];</p><sec id="s8_1"><title>7.2. The Data Set for <xref ref-type="fig" rid="fig1">Figure 1</xref></title><p>param n:=5;</p><p>param t:=10;</p><p>set cage[<xref ref-type="bibr" rid="scirp.66317-ref1">1</xref>]: = (1, 1) (1, 2) (2,1);</p><p>set cage[<xref ref-type="bibr" rid="scirp.66317-ref2">2</xref>]: = (1, 3) (1, 4);</p><p>set cage[<xref ref-type="bibr" rid="scirp.66317-ref3">3</xref>]: = (1, 5) (2, 5);</p><p>set cage[<xref ref-type="bibr" rid="scirp.66317-ref4">4</xref>]: = (2, 2) (2, 3) (2,4) (3,2) (4,2);</p><p>set cage[<xref ref-type="bibr" rid="scirp.66317-ref5">5</xref>]: = (3, 1) (4, 1);</p><p>set cage[<xref ref-type="bibr" rid="scirp.66317-ref6">6</xref>]: = (3, 3) (3, 4);</p><p>set cage[<xref ref-type="bibr" rid="scirp.66317-ref7">7</xref>]: = (3, 5) (4, 5) (5,5);</p><p>set cage[<xref ref-type="bibr" rid="scirp.66317-ref8">8</xref>]: = (4, 3) (5, 3) (5,4);</p><p>set cage[<xref ref-type="bibr" rid="scirp.66317-ref9">9</xref>]: = (4, 4);</p><p>set cage[<xref ref-type="bibr" rid="scirp.66317-ref10">10</xref>]: = (5, 1) (5,2);</p><p>param: target_number operation:=</p><p>1 9 &quot;product&quot;</p><p>2 1 &quot;difference&quot;</p><p>3 2 &quot;ratio&quot;</p><p>4 13 &quot;sum&quot;</p><p>5 1 &quot;difference&quot;</p><p>6 2 &quot;ratio&quot;</p><p>7 15 &quot;product&quot;</p><p>8 24 &quot;product&quot;</p><p>9 3 &quot;sum&quot;</p><p>10 3 &quot;difference&quot;;</p><p>set prime_numbers:= 2 3 5 7;</p></sec><sec id="s8_2"><title>7.3. The Solution, Efficiency of the Model and Future Directions</title><p>We ran the AMPL model on the NEOS server using the solver Gurobi [<xref ref-type="bibr" rid="scirp.66317-ref8">8</xref>] and received the following correct solution for the puzzle.</p><p>y [*,*]</p><p>: 1 2 3 4 5 6 7 8 :=</p><p>1 3 5 8 1 2 4 7 6</p><p>2 2 3 5 6 8 1 4 7</p><p>3 8 6 7 5 1 3 2 4</p><p>4 4 7 2 8 5 6 3 1</p><p>5 7 1 4 3 6 2 8 5</p><p>6 6 4 3 2 7 5 1 8</p><p>7 1 2 6 7 4 8 5 3</p><p>8 5 8 1 4 3 7 6 2</p><p>;</p><p>It took under 1 second to return the solution. Thus, the model is very efficient for puzzles of size 9 or less. But it is still an interesting question how to make the model more efficient for any size. Below we describe related open questions.</p><p>It would be more efficient to solve the LP-relaxation of our integer program. But our computations show that the LP-relaxation does not always return an integer solution. It is an interesting open question if there are any techniques to achieve integrality. A possible technique could be the following.</p><p>The integer program does not need an objective function. Thus, one has a flexibility of adding an appropriate objective function. It is an interesting open question if there is an objective function that would make the optimal solution of the LP-relaxation integral.</p><p>The existence of appropriate cutting planes that would make the solution process more efficient and perhaps make the optimal solution of the LP-relaxation integral is another open question.</p></sec></sec><sec id="s9"><title>Cite this paper</title><p>Vardges Melkonian, (2016) An Integer Programming Model for the KenKen Problem. American Journal of Operations Research,06,213-225. doi: 10.4236/ajor.2016.63022</p></sec><sec id="s10"><title>Appendix. Method 2 for Product Restrictions</title><p>In this appendix, we give a further discussion on Method 2 for product restrictions.</p>A1. The Subcase When the Cage Consists of Two Cells and There Are More Than One Factorization for the Target Number<p>In puzzles of size at most 9 &#215; 9, if a product cage consists of two cells and the target number is composite then at most 2 different factorizations are possible. It is easy to verify it for all possible composite target numbers. Namely, numbers 4, 9, 10, 14, 15, 16, 20, 21, 27, 28, 30, 32, 35, 36, 40, 42, 45, 48, 54, 56, 63, 72 can have only one factorization; while numbers 6, 8, 12, 18, 24 can have two different factorizations. In this subsection we will show how to write linear constraints in the case of two different factorizations. For the sake of simplicity and better demonstration, we will show it on an example of a specific number; the technique is identical for other numbers.</p><p>Suppose the cage consists of two adjacent cells (i, j) and (i, j + 1), and the target number is 12. Then the restriction is the following:</p><disp-formula id="scirp.66317-formula29"><label>(A.1)</label><graphic position="anchor" xlink:href="http://html.scirp.org/file/1-1040464x72.png"  xlink:type="simple"/></disp-formula><p>As in Subsection 6.1, there are two ways to convert the restriction to linear constraints. And again one of the methods is less intuitive but more efficient since it requires fewer constraints and auxiliary binary variables. But for the sake of comparison and completeness, we will give both methods, starting from the more intuitive one.</p><p>Method 1: The restriction (A.1) is equivalent to requiring that</p><disp-formula id="scirp.66317-formula30"><graphic  xlink:href="http://html.scirp.org/file/1-1040464x73.png"  xlink:type="simple"/></disp-formula><p>The “1-out-of-4 must hold” constraint is equivalent to the following set of linear constraints:</p><disp-formula id="scirp.66317-formula31"><label>, (A.2)</label><graphic position="anchor" xlink:href="http://html.scirp.org/file/1-1040464x74.png"  xlink:type="simple"/></disp-formula><disp-formula id="scirp.66317-formula32"><label>, (A.3)</label><graphic position="anchor" xlink:href="http://html.scirp.org/file/1-1040464x75.png"  xlink:type="simple"/></disp-formula><disp-formula id="scirp.66317-formula33"><label>, (A.4)</label><graphic position="anchor" xlink:href="http://html.scirp.org/file/1-1040464x76.png"  xlink:type="simple"/></disp-formula><disp-formula id="scirp.66317-formula34"><label>, (A.5)</label><graphic position="anchor" xlink:href="http://html.scirp.org/file/1-1040464x77.png"  xlink:type="simple"/></disp-formula><disp-formula id="scirp.66317-formula35"><label>(A.6)</label><graphic position="anchor" xlink:href="http://html.scirp.org/file/1-1040464x78.png"  xlink:type="simple"/></disp-formula><p>where u<sub>34 </sub>, u<sub>43 </sub>, u<sub>26 </sub>, u<sub>62</sub> are auxiliary binary variables.</p><p>Constraint (A.6) implies that exactly one of the u<sub>pq</sub> variables takes value 1 while others are zero. When u<sub>pq</sub> = 1, the corresponding x<sub>ijp</sub> and x<sub>i</sub><sub>,j+1,q </sub>variables also take value 1 while other x-variables in (A.2)-(A.5) are forced to be zero; thus cell (i, j) gets value p, and cell (i, j + 1) gets value q.</p><p>Method 2: The first step of this method is the same as in method 1. The restriction (A.1) is equivalent to requiring that</p><disp-formula id="scirp.66317-formula36"><graphic  xlink:href="http://html.scirp.org/file/1-1040464x79.png"  xlink:type="simple"/></disp-formula><p>But from here we proceed as it was done in method 2 of Subsection 6.1. The Either-Or restriction (<inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x80.png" xlink:type="simple"/></inline-formula>) or (<inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x80.png" xlink:type="simple"/></inline-formula><inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x81.png" xlink:type="simple"/></inline-formula>) is equivalent to constraint <inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x80.png" xlink:type="simple"/></inline-formula><inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x81.png" xlink:type="simple"/></inline-formula><inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x82.png" xlink:type="simple"/></inline-formula> since x-variables satisfy (2.1) and (2.2). Based on the same reason, the Either-Or restriction (<inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x80.png" xlink:type="simple"/></inline-formula><inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x81.png" xlink:type="simple"/></inline-formula><inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x82.png" xlink:type="simple"/></inline-formula><inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x83.png" xlink:type="simple"/></inline-formula>) or (<inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x80.png" xlink:type="simple"/></inline-formula><inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x81.png" xlink:type="simple"/></inline-formula><inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x82.png" xlink:type="simple"/></inline-formula><inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x83.png" xlink:type="simple"/></inline-formula><inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x84.png" xlink:type="simple"/></inline-formula>) is equivalent to<inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x80.png" xlink:type="simple"/></inline-formula><inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x81.png" xlink:type="simple"/></inline-formula><inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x82.png" xlink:type="simple"/></inline-formula><inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x83.png" xlink:type="simple"/></inline-formula><inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x84.png" xlink:type="simple"/></inline-formula><inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x85.png" xlink:type="simple"/></inline-formula>.</p><p>Thus, the restriction (A.1) is equivalent to</p><disp-formula id="scirp.66317-formula37"><graphic  xlink:href="http://html.scirp.org/file/1-1040464x86.png"  xlink:type="simple"/></disp-formula><p>This Either-Or restriction is converted to an equivalent pair of linear constraints in a standard way.</p><disp-formula id="scirp.66317-formula38"><label>, (A.7)</label><graphic position="anchor" xlink:href="http://html.scirp.org/file/1-1040464x87.png"  xlink:type="simple"/></disp-formula><disp-formula id="scirp.66317-formula39"><label>, (A.8)</label><graphic position="anchor" xlink:href="http://html.scirp.org/file/1-1040464x88.png"  xlink:type="simple"/></disp-formula><p>where u is an auxiliary binary variable.</p>A2. The Subcase When the Cage Consists of K Cells in the Same Row (Column) and There Is a Single Factorization for the Target Number<p>The technique discussed in this section is the extension of the technique for 2-cell cages discussed in subsection 6.1.</p><p>Suppose the cells in the cage are<inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x89.png" xlink:type="simple"/></inline-formula>, the target value is m, and there is a single factorization of<inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x89.png" xlink:type="simple"/></inline-formula><inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x90.png" xlink:type="simple"/></inline-formula>. Then there are k! permutations of assigning numbers <inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x89.png" xlink:type="simple"/></inline-formula><inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x90.png" xlink:type="simple"/></inline-formula><inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x91.png" xlink:type="simple"/></inline-formula><sub> </sub>to the cells<inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x89.png" xlink:type="simple"/></inline-formula><inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x90.png" xlink:type="simple"/></inline-formula><inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x91.png" xlink:type="simple"/></inline-formula><inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x92.png" xlink:type="simple"/></inline-formula>. The following linear constraint together with Latin square constraints (2.1) and (2.2) forces that exactly one of those permutations is chosen.</p><disp-formula id="scirp.66317-formula40"><label>(A.9)</label><graphic position="anchor" xlink:href="http://html.scirp.org/file/1-1040464x93.png"  xlink:type="simple"/></disp-formula><p>The reason that this combination of constraints works is the same that we had for two-cell cages with a single factorization as discussed in Subsection 6.1.</p><p>Here is a specific example to illustrate how constraint (A.9) works. Suppose the cells in the cage are (1, 1), (1, 2), (1, 3); the target number is 18, and thus the single factorization is 18 = 1 &#215; 3 &#215; 6. The constraint (A.9) in this case is</p><disp-formula id="scirp.66317-formula41"><graphic  xlink:href="http://html.scirp.org/file/1-1040464x94.png"  xlink:type="simple"/></disp-formula><p>This constraint together with Latin square constraints (2.1) and (2.2) provides that exactly one of the following 3! = 6 combinations of assignments:</p><p>- cell (1,1) gets 1; cell (1,2) gets 3; cell (1,3) gets 6;</p><p>- cell (1,1) gets 1; cell (1,2) gets 6; cell (1,3) gets 3;</p><p>- cell (1,1) gets 3; cell (1,2) gets 1; cell (1,3) gets 6;</p><p>- cell (1,1) gets 3; cell (1,2) gets 6; cell (1,3) gets 1;</p><p>- cell (1,1) gets 6; cell (1,2) gets 1; cell (1,3) gets 3;</p><p>- cell (1,1) gets 6; cell (1,2) gets 3; cell (1,3) gets 1.</p>A3. The Subcase When the Cage Consists of K Cells in the Same Row (Column) and There Are More Than One Factorization for the Target Number<p>The technique discussed in this section is the extension of the technique for 2-cell cages discussed in subsection A1.</p><p>Suppose the cells in the cage are<inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x95.png" xlink:type="simple"/></inline-formula>, the target value is m, and there are more than one factorizations. Denote the set of all factorizations<inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x95.png" xlink:type="simple"/></inline-formula><inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x96.png" xlink:type="simple"/></inline-formula>. Let the factorization for F<sub>t</sub> be <inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x95.png" xlink:type="simple"/></inline-formula><inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x96.png" xlink:type="simple"/></inline-formula><inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x97.png" xlink:type="simple"/></inline-formula><sub> </sub>. As in subsection A1, the constraint for factorization F<sub>t</sub> would be</p><disp-formula id="scirp.66317-formula42"><label>(A.10)</label><graphic position="anchor" xlink:href="http://html.scirp.org/file/1-1040464x98.png"  xlink:type="simple"/></disp-formula><p>But we want constraint (A.10) to be satisfied by only one of the factorizations. Note that for the other factorizations the left-hand side of (A.10) is not necessarily 0 since the same factor m could be in more than one factorization. The following set of constraints takes the above considerations into account.</p><p><inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x99.png" xlink:type="simple"/></inline-formula>, for each <inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x99.png" xlink:type="simple"/></inline-formula><inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x100.png" xlink:type="simple"/></inline-formula> (A.11)</p><disp-formula id="scirp.66317-formula43"><label>(A.12)</label><graphic position="anchor" xlink:href="http://html.scirp.org/file/1-1040464x101.png"  xlink:type="simple"/></disp-formula><p>Note that the left-hand side of (A.11) cannot be more than k because of constraints (2.1) and (2.2). Thus, (A.12) will force that the left-hand side of (A.11) is equal to k for exactly one factorization; for other factorizations, the left-hand side of (A.11) is ≥0, hence not forcing anything on its x-variables.</p><p>Here is a specific example to illustrate how constraints (A.11)-(A.12) work. Suppose the cells in the cage are (1, 1), (1, 2), (1, 3); the target number is 48, and thus the following three factorizations are possible:</p><p><inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x102.png" xlink:type="simple"/></inline-formula>;</p><p><inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x103.png" xlink:type="simple"/></inline-formula>;</p><p><inline-formula><inline-graphic xlink:href="http://html.scirp.org/file/1-1040464x104.png" xlink:type="simple"/></inline-formula>.</p><p>The constraints (A.11)-(A.12) in this case are</p><disp-formula id="scirp.66317-formula44"><label>(A.13)</label><graphic position="anchor" xlink:href="http://html.scirp.org/file/1-1040464x105.png"  xlink:type="simple"/></disp-formula><disp-formula id="scirp.66317-formula45"><label>(A.14)</label><graphic position="anchor" xlink:href="http://html.scirp.org/file/1-1040464x106.png"  xlink:type="simple"/></disp-formula><disp-formula id="scirp.66317-formula46"><label>(A.15)</label><graphic position="anchor" xlink:href="http://html.scirp.org/file/1-1040464x107.png"  xlink:type="simple"/></disp-formula><disp-formula id="scirp.66317-formula47"><label>(A.16)</label><graphic position="anchor" xlink:href="http://html.scirp.org/file/1-1040464x108.png"  xlink:type="simple"/></disp-formula>A4. General Case (Cage Occupies Multiple Rows and Columns)<p>A problem in this case could be the following. Even in the case of a single factorization, e.g., the cage is in cells (1, 1), (1, 2), (2, 1), and the target number is 35 = 1 &#215; 5 &#215; 7, constraint of type (A.9) would not work:</p><disp-formula id="scirp.66317-formula48"><graphic  xlink:href="http://html.scirp.org/file/1-1040464x109.png"  xlink:type="simple"/></disp-formula><p>A solution satisfying this constraint could be x<sub>111</sub> = 1, x<sub>125 </sub>= 1, x<sub>215</sub> = 1, that is, cells (1, 2) and (2, 1) getting value 5 while cell (1, 1) getting value 1, hence the cell restriction is not satisfied. Note that constraints (2.1) and (2.2) are not violated by this solution.</p><p>A solution for the general case is given by the method described in Subsection 6.1.</p></sec></body><back><ref-list><title>References</title><ref id="scirp.66317-ref1"><label>1</label><mixed-citation publication-type="other" xlink:type="simple">The KenKen Website. http://www.kenkenpuzzle.com/</mixed-citation></ref><ref id="scirp.66317-ref2"><label>2</label><mixed-citation publication-type="other" xlink:type="simple">Watkins, J. (2012) Triangular Numbers, Gaussian Integers, and KenKen. The College Mathematics Journal, 43, 37-42.http://dx.doi.org/10.4169/college.math.j.43.1.037</mixed-citation></ref><ref id="scirp.66317-ref3"><label>3</label><mixed-citation publication-type="other" xlink:type="simple">Reiter, H., Thornton, J. and Vennebush, G.P. (2013) Using KenKen to Build Reasoning Skills. Mathematics Teacher, 107, 341-347.</mixed-citation></ref><ref id="scirp.66317-ref4"><label>4</label><mixed-citation publication-type="other" xlink:type="simple">Chlond, M. (2005) Classroom Exercises in IP Modeling: Sudoku and the Log Pile. INFORMS Transactions on Education, 5, 77-79. http://dx.doi.org/10.1287/ited.5.2.77</mixed-citation></ref><ref id="scirp.66317-ref5"><label>5</label><mixed-citation publication-type="other" xlink:type="simple">Bartlett, A.C., Chartier, T.P., Langville, A.N. and Rankin, T.D. (2008) An Integer Programming Model for the Sudoku Problem. The Journal of Online Mathematics and Its Applications, 8, Article ID: 1798.http://www.maa.org/external_archive/joma/Volume8/Bartlett/index.html</mixed-citation></ref><ref id="scirp.66317-ref6"><label>6</label><mixed-citation publication-type="other" xlink:type="simple">The AMPL Website. http://www.ampl.com/</mixed-citation></ref><ref id="scirp.66317-ref7"><label>7</label><mixed-citation publication-type="other" xlink:type="simple">Hillier, F. and Lieberman, G. (2014) Introduction to Operations Research. 10th Edition, McGraw-Hill, New York.</mixed-citation></ref><ref id="scirp.66317-ref8"><label>8</label><mixed-citation publication-type="other" xlink:type="simple">The Gurobi Website. https://neos-server.org/neos/solvers/lp:Gurobi/AMPL.html</mixed-citation></ref></ref-list></back></article>