Commit Graph

72 Commits

Author SHA1 Message Date
358175fd33 Fix & fmt & ci
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
2022-03-09 12:42:09 +04:00
656890c1be Refactored variable constructors 2021-12-10 13:20:36 +04:00
dc20c9aa76 Removed Candidates::None variant 2021-12-09 23:41:30 +04:00
d8323a144f Move LinExpr into linexpr module 2021-12-09 22:48:36 +04:00
25a6634069 on_assing -> propagate 2021-12-09 22:36:40 +04:00
e363a552f0 Split out Ranges struct 2021-12-09 22:26:07 +04:00
ba86c49bfb Ranges 2021-12-08 18:50:21 +04:00
631d25cc3c fix warnings 2021-12-08 11:17:32 +04:00
da22e1dfbb fmt 2021-12-07 20:56:04 +04:00
74ea9c497f Edition 2021 2021-12-07 20:49:40 +04:00
David Wang
ee6bf20aba Version bump: 0.4.1. 2017-04-16 08:32:52 +10:00
David Wang
bbf75b6579 Update README. 2017-04-16 08:27:47 +10:00
David Wang
2f20aa4086 Add test: Takuzu (A.K.A. Binairo).
takuzu_grid1: 12 guesses.
takuzu_grid2: 0 guesses.
takuzu_grid3: 0 guesses.
takuzu_grid4: 20724 guesses (all solutions).
2017-03-21 08:44:26 +11:00
David Wang
b22c6466ca Add test: Nonogram (A.K.A. Hanjie, Picross).
nonogram_wikipedia: 10 guesses.
2017-03-20 08:31:09 +11:00
David Wang
c7c0bfa128 Version bump: 0.4.0. 2017-03-19 08:11:07 +11:00
David Wang
533c382605 Update README. 2017-03-19 08:08:00 +11:00
David Wang
f22b271000 Clean up.
- Use cloned instead of map.
- Use Val instead of i32.
- Import module instead of trait.
2017-03-18 09:22:52 +11:00
David Wang
630f09fc80 Add test: xkcd knapsack problem.
xkcd_knapsack: 60 guesses.
2017-03-17 08:45:57 +11:00
David Wang
3afb599568 Delete mini integer-division module.
We no longer need this since we've added rationals.
2017-03-16 08:03:29 +11:00
David Wang
ab6267b46c Add support for rational coefficients in linear expressions.
Coef has been redefined to Rational32.
2017-03-15 08:13:30 +11:00
David Wang
20e5242624 Replace Coef with i32 in arithmetic overloads.
We want to redefine Coef to be Rational32.  However, we want to be
able to build linear expressions as easily as before.  We will do this
by retaining the overloads with i32, and introduce new overloads for
operations with Rational32s.
2017-03-14 07:52:39 +11:00
David Wang
bf656fcb0d Add dependency: num-rational. 2017-03-13 08:30:11 +11:00
David Wang
80b84f4f90 Version bump: 0.3.0. 2017-03-12 08:17:54 +11:00
David Wang
889d12bf75 Update README. 2017-03-12 08:14:42 +11:00
David Wang
65222f24d1 Update test: Samurai Sudoku.
samuraisudoku_easy: 2 -> no guesswork!
2017-03-12 08:07:31 +11:00
David Wang
93cf70c0ca Add convenience functions for unify. 2017-03-11 10:38:15 +11:00
David Wang
f265a165dd Add unification constraint.
This constraint unifies two variables.  This is done by substituting
one variable for another in all of the current constraints, resulting
a new set of constraints.

We would like to make the equality constraint perform the more general
substitution: "coef1 var1 -> coef2 var2 + constant".  While this
constraint is less general, it can be used when the variables are not
integer quantities.
2017-03-11 10:06:53 +11:00
David Wang
4a331fdc1a Separate constraints from puzzle.
Separate the list of puzzle constraints from the puzzle structure.
This allows different stages of the puzzle solution search to have
different constraints.
2017-03-11 09:51:04 +11:00
David Wang
035a8fc8a4 Clean up: candidate manipulation returns a Result.
Functions to manipulate candidates during the solution search now
always return a Result instead of sometimes returning a bool, and
other times returning an Option.

We opted to use Result over Option mainly to (ab)use the try! macro.
In addition, it also makes it emit a warning when we forget to handle
the result.  (We tend to assume people don't just ignore the result
and continue as normal, instead of putting the puzzle in a special
contradiction detected state.)
2017-03-11 09:40:20 +11:00
David Wang
5bb52b03f2 Add simple variable substitution for constraints.
Constraints must now implement the substitution of "from" with "to".
The implementations can be sanity checked when we come to build the
list of constraints that each variable wakes up.

In the future, we would like to make the more general substitution:
from -> scale * to + constant.
2017-03-09 07:52:08 +11:00
David Wang
bae1138501 Store constraints in Rc instead of Box.
We will implement unification by substituting one variable for
another, creating a new set of constraints.  Only the affected
constraints need to perform the substitution, the others can simply be
cloned.  As such, we will store constraints using reference counting.
2017-03-08 08:02:37 +11:00
David Wang
ddf425efe0 Automatically box constraints.
Puzzle.add_constraint() now takes a generic (unboxed) constraint,
making it more pleasant to use when adding custom constraints.
2017-03-08 07:57:19 +11:00
David Wang
b1b727b38e Implement Debug for intermediate puzzle search state. 2017-03-07 07:44:42 +11:00
David Wang
6689b0106f Add test: Samurai Sudoku.
samuraisudoku_easy: 2 guesses.
2017-03-06 07:53:10 +11:00
David Wang
9f9549ee56 Version bump: 0.2.0. 2017-03-05 08:58:06 +11:00
David Wang
bfb85a9f1d Update README. 2017-03-05 08:49:26 +11:00
David Wang
23ae2331bf Add test: Killer Sudoku.
killersudoku_wikipedia: 7 guesses.
2017-03-04 09:07:04 +11:00
David Wang
c93b9430c1 Add test: Kakuro.
kakuro_wikipedia: 9 guesses.
2017-03-04 08:57:52 +11:00
David Wang
dfda5961ef Add test: Sujiko.
sujiko_simetric: 4 guesses.

Note that the puzzle on Wikipedia does not specify the initial board
configuration and is not unique.
2017-03-04 08:16:33 +11:00
David Wang
d9f92e2baa Add test: Hidato.
hidato_wikipedia: 4 guesses.
2017-03-04 08:03:00 +11:00
David Wang
abb4cebce3 Equality: bound variable range by using min/max of other variables.
magicsquare_3x3: 873 -> 63 guesses.
magicsquare_4x4: 13475456 -> 539910 guesses (all solutions).
sendmoremoney_carry: 154 -> 6 guesses.
sendmoremoney_naive: 633681 -> 4 guesses.
zebra: 453 -> no guesswork!
2017-03-03 08:06:48 +11:00
David Wang
8e62c85bf5 Add test: Zebra puzzle (A.K.A. Einstein's riddle).
zebra: 453 guesses.
2017-03-02 08:42:46 +11:00
David Wang
57df25eb37 Add test: Magic Square.
magicsquare_3x3: 873 guesses.
magicsquare_4x4: 13475456 guesses (all solutions).
2017-03-02 08:25:29 +11:00
David Wang
67b7cb5dc6 Add test: Send More Money.
sendmoremoney_carry: 154 guesses.
sendmoremoney_naive: 633681 guesses.
2017-03-02 08:15:55 +11:00
David Wang
58a2b0b41f Add convenience functions for equality.
This function takes a LHS and RHS only to give the illusion of an
equality.  It simply subtracts one from the other because our
equations are all in the form: coef_i var_i + constant == 0.
2017-03-01 08:04:27 +11:00
David Wang
7e908457a2 Add equality constraint.
This is a very simple equality constraint.  It only assigns a variable
when all other variables in the equation have been assigned.  Possible
improvements:

- We can find the min and max range by considering the coefficients
  and the max and min values of the other variables in the equation.

- When there are only 2 variables remaining, we can eliminate the
  incompatible candidates and then substitute one variable for the
  other in other constraints.
2017-03-01 08:04:09 +11:00
David Wang
bddb31dd5b Add integer division with rounding up/down.
While these functions can be found in rational number libraries,
support for rational numbers is an extra complexity that we do not
wish to tackle at this stage.  We'll use these to keep things simple.
2017-02-28 07:58:38 +11:00
David Wang
407a3e7555 Overload arithmetic operators to build linear expressions.
This allows one to easily build linear constraint equations by writing
equations with the tokens.

Note that variables will always take integer values, but coefficients
may be generalised to support rationals.
2017-02-27 08:14:56 +11:00
David Wang
8b90319555 Add crates.io metadata. 2017-02-26 07:54:03 +11:00
David Wang
afc08ad697 Add README. 2017-02-26 07:54:02 +11:00