Skip to content

Commit

Permalink
Added Essence/Tailor and Essence/Savile Row.
Browse files Browse the repository at this point in the history
  • Loading branch information
hakank committed Aug 7, 2013
1 parent 6acfcd3 commit 114bb3a
Show file tree
Hide file tree
Showing 143 changed files with 5,316 additions and 0 deletions.
131 changes: 131 additions & 0 deletions essence_savile_row/a_puzzle.eprime
@@ -0,0 +1,131 @@
$
$ "A puzzle" in Essence'.
$
$ From "God plays dice"
$ "A puzzle"
$ http://gottwurfelt.wordpress.com/2012/02/22/a-puzzle/
$ And the sequel "Answer to a puzzle"
$ http://gottwurfelt.wordpress.com/2012/02/24/an-answer-to-a-puzzle/
$
$ This problem instance was taken from the latter blog post.
$
$ """
$ 8809 = 6
$ 7111 = 0
$ 2172 = 0
$ 6666 = 4
$ 1111 = 0
$ 3213 = 0
$ 7662 = 2
$ 9312 = 1
$ 0000 = 4
$ 2222 = 0
$ 3333 = 0
$ 5555 = 0
$ 8193 = 3
$ 8096 = 5
$ 7777 = 0
$ 9999 = 4
$ 7756 = 1
$ 6855 = 3
$ 9881 = 5
$ 5531 = 0
$
$ 2581 = ?
$ """
$
$ Note:
$ This model yields 10 solutions, since x4 is not
$ restricted in the constraints.
$ All solutions has x assigned to the correct result.
$


$ The problem stated in "A puzzle"
$ http://gottwurfelt.wordpress.com/2012/02/22/a-puzzle/
$ is
$ """
$ 8809 = 6
$ 7662 = 2
$ 9312 = 1
$ 8193 = 3
$ 8096 = 5
$ 7756 = 1
$ 6855 = 3
$ 9881 = 5
$
$ 2581 = ?
$ """
$ This problem instance - using the same principle - yields
$ two different solutions of x, one is the same (correct) as
$ for the above problem instance, and one is not.
$ This is because here both x4 and x1 are underdefined.
$
$
$ Model created by Hakan Kjellerstrand, hakank@bonetmail.com
$ See also my Essence'/Tailor page: http://www.hakank.org/minion_tailor
language ESSENCE' 1.0

letting R be domain int(0..9)

find x0: R
find x1: R
find x2: R
find x3: R
find x4: R
find x5: R
find x6: R
find x7: R
find x8: R
find x9: R

find all: matrix indexed by [int(1..10)] of R
find x: R

such that

all[1] = x0, all[2] = x1, all[3] = x2, all[4] = x3, all[5] = x4,
all[6] = x5, all[7] = x6, all[8] = x7, all[9] = x8, all[10] = x9,

$$ This yields 10 solutions, all with the same
$$ values for x
x8+x8+x0+x9 = 6,
x7+x1+x1+x1 = 0,
x2+x1+x7+x2 = 0,
x6+x6+x6+x6 = 4,
x1+x1+x1+x1 = 0,
x3+x2+x1+x3 = 0,
x7+x6+x6+x2 = 2,
x9+x3+x1+x2 = 1,
x0+x0+x0+x0 = 4,
x2+x2+x2+x2 = 0,
x3+x3+x3+x3 = 0,
x5+x5+x5+x5 = 0,
x8+x1+x9+x3 = 3,
x8+x0+x9+x6 = 5,
x7+x7+x7+x7 = 0,
x9+x9+x9+x9 = 4,
x7+x7+x5+x6 = 1,
x6+x8+x5+x5 = 3,
x9+x8+x8+x1 = 5,
x5+x5+x3+x1 = 0,

$ the unknown
x2+x5+x8+x1 = x



$$ This yields two different values for x
$ x8+x8+x0+x9 = 6,
$ x7+x6+x6+x2 = 2,
$ x9+x3+x1+x2 = 1,
$ x8+x1+x9+x3 = 3,
$ x8+x0+x9+x6 = 5,
$ x7+x7+x5+x6 = 1,
$ x6+x8+x5+x5 = 3,
$ x9+x8+x8+x1 = 5,
$
$$ the unknown
$ x2+x5+x8+x1 = x


109 changes: 109 additions & 0 deletions essence_savile_row/a_round_of_golf.eprime
@@ -0,0 +1,109 @@
$
$ A Round of Golf puzzle (Dell Logic Puzzles) in Essence'.
$
$ From http://brownbuffalo.sourceforge.net/RoundOfGolfClues.html
$ """
$ Title: A Round of Golf
$ Author: Ellen K. Rodehorst
$ Publication: Dell Favorite Logic Problems
$ Issue: Summer, 2000
$ Puzzle #: 9
$ Stars: 1
$
$ When the Sunny Hills Country Club golf course isn't in use by club members,
$ of course, it's open to the club's employees. Recently, Jack and three other
$ workers at the golf course got together on their day off to play a round of
$ eighteen holes of golf.
$ Afterward, all four, including Mr. Green, went to the clubhouse to total
$ their scorecards. Each man works at a different job (one is a short-order
$ cook), and each shot a different score in the game. No one scored below
$ 70 or above 85 strokes. From the clues below, can you discover each man's
$ full name, job and golf score?
$
$ 1. Bill, who is not the maintenance man, plays golf often and had the lowest
$ score of the foursome.
$ 2. Mr. Clubb, who isn't Paul, hit several balls into the woods and scored ten
$ strokes more than the pro-shop clerk.
$ 3. In some order, Frank and the caddy scored four and seven more strokes than
$ Mr. Sands.
$ 4. Mr. Carter thought his score of 78 was one of his better games, even
$ though Frank's score was lower.
$ 5. None of the four scored exactly 81 strokes.
$
$ Determine: First Name - Last Name - Job - Score
$ """
$
$ Model created by Hakan Kjellerstrand, hakank@bonetmail.com
$ See also my Essence'/Tailor page: http://www.hakank.org/minion_tailor
$
language ESSENCE' 1.0

letting n be 4

letting Jack be 1
letting Bill be 2
letting Paul be 3
letting Frank be 4

letting R be domain int(1..n)

find Green: R
find Clubb: R
find Sands: R
find Carter: R
find last_name: matrix indexed by [int(1..n)] of R

find cook: R
find maintenance_man: R
find clerk: R
find caddy: R
find job: matrix indexed by [int(1..n)] of R

find score: matrix indexed by [int(1..n)] of int(70..85)


such that

last_name[1] = Green, last_name[2] = Clubb, last_name[3] = Sands, last_name[4] = Carter,
job[1] = cook, job[2] = maintenance_man, job[3] = clerk, job[4] = caddy,

allDiff(last_name),
allDiff(job),
allDiff(score),

$ 1. Bill, who is not the maintenance man, plays golf often and had
$ the lowest score of the foursome.
Bill != maintenance_man,
score[Bill] < score[Jack],
score[Bill] < score[Paul],
score[Bill] < score[Frank],

$ 2. Mr. Clubb, who isn't Paul, hit several balls into the woods and
$ scored ten strokes more than the pro-shop clerk.
Clubb != Paul,
score[Clubb] = score[clerk] + 10,


$ 3. In some order, Frank and the caddy scored four and seven more
$ strokes than Mr. Sands.
Frank != caddy,
Frank != Sands,
caddy != Sands,
(
(score[Frank] = score[Sands] + 4 /\
score[caddy] = score[Sands] + 7 )
\/
(score[Frank] = score[Sands] + 7 /\
score[caddy] = score[Sands] + 4 )
),

$ 4. Mr. Carter thought his score of 78 was one of his better games, even
$ though Frank's score was lower.
Frank != Carter,
score[Carter] = 78,
score[Frank] < score[Carter],

$ 5. None of the four scored exactly 81 strokes.
forall i : R .
score[i] != 81

44 changes: 44 additions & 0 deletions essence_savile_row/all_interval.eprime
@@ -0,0 +1,44 @@
$
$ All interval problem in Essence'.
$
$
$ CSPLib problem number 7
$ http://www.cs.st-andrews.ac.uk/~ianm/CSPLib/prob/prob007/index.html
$ """
$ Given the twelve standard pitch-classes (c, c$, d, ...), represented by
$ numbers 0,1,...,11, find a series in which each pitch-class occurs exactly
$ once and in which the musical intervals between neighbouring notes cover
$ the full set of intervals from the minor second (1 semitone) to the major
$ seventh (11 semitones). That is, for each of the intervals, there is a
$ pair of neigbhouring pitch-classes in the series, between which this
$ interval appears. The problem of finding such a series can be easily
$ formulated as an instance of a more general arithmetic problem on Z_n,
$ the set of integer residues modulo n. Given n in N, find a vector
$ s = (s_1, ..., s_n), such that (i) s is a permutation of
$ Z_n = {0,1,...,n-1}; and (ii) the interval vector
$ v = (|s_2-s_1|, |s_3-s_2|, ... |s_n-s_{n-1}|) is a permutation of
$ Z_n-{0} = {1,2,...,n-1}. A vector v satisfying these conditions is
$ called an all-interval series of size n; the problem of finding such
$ a series is the all-interval series problem of size n. We may also be
$ interested in finding all possible series of a given size.
$ """
$
$ Model created by Hakan Kjellerstrand, hakank@bonetmail.com
$ See also my Essence'/Tailor page: http://www.hakank.org/minion_tailor
$
language ESSENCE' 1.0

letting n be 12

find x: matrix indexed by [int(1..n)] of int(1..n)
find diffs: matrix indexed by [int(1..n-1)] of int(1..n-1)

such that

allDiff(diffs),
allDiff(x),
forall k : int(1..n-1) . (
diffs[k] = |x[k+1]-x[k]|
),
x[1] < x[n-1],
diffs[1] < diffs[2]
56 changes: 56 additions & 0 deletions essence_savile_row/alldifferent_except_0.eprime
@@ -0,0 +1,56 @@
$ Alldifferent except 0 in Essence'.
$
$ Decomposition of the global constraint alldifferent except 0.
$
$ From Global constraint catalogue:
$ http://www.emn.fr/x-info/sdemasse/gccat/sec4.6.html
$ """
$ Enforce all variables of the collection VARIABLES to take distinct values, except those
$ variables that are assigned to 0.
$
$ Example
$ (<5, 0, 1, 9, 0, 3>)
$
$ The alldifferent_except_0 constraint holds since all the values (that are different from 0)
$ 5, 1, 9 and 3 are distinct.
$ """
$
$ Note: Essence' don't have predicates.
$
$ Compare with the following models:
$ * Comet: http://www.hakank.org/comet/alldifferent_except_0.co
$ * ECLiPSE: http://www.hakank.org/eclipse/alldifferent_except_0.ecl
$ * Gecode: http://www.hakank.org/gecode/alldifferent_except_0.cpp
$ * Gecode/R: http://www.hakank.org/gecode_r/all_different_except_0.rb
$ * MiniZinc: http://www.hakank.org/minizinc/alldifferent_except_0.mzn
$ * Choco: http://www.hakank.org/choco/AllDifferentExcept0_test.java
$ * JaCoP: http://www.hakank.org/JaCoP/AllDifferentExcept0_test.java
$
$
$ Model created by Hakan Kjellerstrand, hakank@bonetmail.com
$ See also my Essence'/Tailor page: http://www.hakank.org/minion_tailor
language ESSENCE' 1.0

letting n be 6
$ given n : int

find x : matrix indexed by [int(1..n)] of int(0..9)
find z : int(0..10000) $ number of zeros in x

such that
z = (sum i : int(1..n) . x[i] = 0),

z = 2, $ number of 0's in x

$ all different except 0
forall i,j : int(1..n) . (
(i != j) =>
(((x[i] != 0) /\ (x[j] != 0)) => (x[i] != x[j]))
),

$ symmetry breaking sorted
forall i,j : int(2..n) .
x[i-1] <= x[i]



47 changes: 47 additions & 0 deletions essence_savile_row/alldifferent_except_0b.eprime
@@ -0,0 +1,47 @@
$ Alldifferent except 0 in Essence'.
$
$ Decomposition of the global constraint alldifferent except 0.
$
$ From Global constraint catalogue:
$ http://www.emn.fr/x-info/sdemasse/gccat/sec4.6.html
$ """
$ Enforce all variables of the collection VARIABLES to take distinct values, except those
$ variables that are assigned to 0.
$
$ Example
$ (<5, 0, 1, 9, 0, 3>)
$
$ The alldifferent_except_0 constraint holds since all the values (that are different from 0)
$ 5, 1, 9 and 3 are distinct.
$ """
$
$ Note: In Savile Row there is support for alldifferent_except.
$
$ Model created by Hakan Kjellerstrand, hakank@bonetmail.com
$ See also my Essence'/Tailor page: http://www.hakank.org/minion_tailor
$
language ESSENCE' 1.0

letting n be 6
$ given n : int

find x : matrix indexed by [int(1..n)] of int(0..9)
find z : int(0..n) $ number of zeros in x

such that
z = (sum i : int(1..n) . x[i] = 0),
z = 2, $ number of 0's in x

$ all different except 0 (decomposition)
$ forall i,j : int(1..n) . (
$ (i != j) =>
$ (((x[i] != 0) /\ (x[j] != 0)) => (x[i] != x[j]))
$ ),
alldifferent_except(x, 0),

$ symmetry breaking sorted
forall i,j : int(2..n) .
x[i-1] <= x[i]



0 comments on commit 114bb3a

Please sign in to comment.