lemon-project-template-glpk

annotate deps/glpk/examples/crypto.mod @ 9:33de93886c88

Import GLPK 4.47
author Alpar Juttner <alpar@cs.elte.hu>
date Sun, 06 Nov 2011 20:59:10 +0100
parents
children
rev   line source
alpar@9 1 /* CRYPTO, a crypto-arithmetic puzzle */
alpar@9 2
alpar@9 3 /* Written in GNU MathProg by Andrew Makhorin <mao@gnu.org> */
alpar@9 4
alpar@9 5 /* This problem comes from the newsgroup rec.puzzle.
alpar@9 6 The numbers from 1 to 26 are assigned to the letters of the alphabet.
alpar@9 7 The numbers beside each word are the total of the values assigned to
alpar@9 8 the letters in the word (e.g. for LYRE: L, Y, R, E might be to equal
alpar@9 9 5, 9, 20 and 13, or any other combination that add up to 47).
alpar@9 10 Find the value of each letter under the equations:
alpar@9 11
alpar@9 12 BALLET 45 GLEE 66 POLKA 59 SONG 61
alpar@9 13 CELLO 43 JAZZ 58 QUARTET 50 SOPRANO 82
alpar@9 14 CONCERT 74 LYRE 47 SAXOPHONE 134 THEME 72
alpar@9 15 FLUTE 30 OBOE 53 SCALE 51 VIOLIN 100
alpar@9 16 FUGUE 50 OPERA 65 SOLO 37 WALTZ 34
alpar@9 17
alpar@9 18 Solution:
alpar@9 19 A, B,C, D, E,F, G, H, I, J, K,L,M, N, O, P,Q, R, S,T,U, V,W, X, Y, Z
alpar@9 20 5,13,9,16,20,4,24,21,25,17,23,2,8,12,10,19,7,11,15,3,1,26,6,22,14,18
alpar@9 21
alpar@9 22 Reference:
alpar@9 23 Koalog Constraint Solver <http://www.koalog.com/php/jcs.php>,
alpar@9 24 Simple problems, the crypto-arithmetic puzzle ALPHACIPHER. */
alpar@9 25
alpar@9 26 set LETTERS :=
alpar@9 27 { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
alpar@9 28 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'
alpar@9 29 };
alpar@9 30 /* set of letters */
alpar@9 31
alpar@9 32 set VALUES := 1..card(LETTERS);
alpar@9 33 /* set of values assigned to the letters */
alpar@9 34
alpar@9 35 set WORDS;
alpar@9 36 /* set of words */
alpar@9 37
alpar@9 38 param total{word in WORDS};
alpar@9 39 /* total[word] is the total of the values assigned to the letters in
alpar@9 40 the word */
alpar@9 41
alpar@9 42 var x{i in LETTERS, j in VALUES}, binary;
alpar@9 43 /* x[i,j] = 1 means that letter i is assigned value j */
alpar@9 44
alpar@9 45 s.t. phi{i in LETTERS}: sum{j in VALUES} x[i,j] = 1;
alpar@9 46
alpar@9 47 s.t. psi{j in VALUES}: sum{i in LETTERS} x[i,j] = 1;
alpar@9 48
alpar@9 49 s.t. eqn{word in WORDS}: sum{k in 1..length(word), j in VALUES}
alpar@9 50 j * x[substr(word,k,1), j] = total[word];
alpar@9 51
alpar@9 52 solve;
alpar@9 53
alpar@9 54 printf{i in LETTERS} " %s", i;
alpar@9 55 printf "\n";
alpar@9 56
alpar@9 57 printf{i in LETTERS} " %2d", sum{j in VALUES} j * x[i,j];
alpar@9 58 printf "\n";
alpar@9 59
alpar@9 60 data;
alpar@9 61
alpar@9 62 param : WORDS : total :=
alpar@9 63 BALLET 45
alpar@9 64 CELLO 43
alpar@9 65 CONCERT 74
alpar@9 66 FLUTE 30
alpar@9 67 FUGUE 50
alpar@9 68 GLEE 66
alpar@9 69 JAZZ 58
alpar@9 70 LYRE 47
alpar@9 71 OBOE 53
alpar@9 72 OPERA 65
alpar@9 73 POLKA 59
alpar@9 74 QUARTET 50
alpar@9 75 SAXOPHONE 134
alpar@9 76 SCALE 51
alpar@9 77 SOLO 37
alpar@9 78 SONG 61
alpar@9 79 SOPRANO 82
alpar@9 80 THEME 72
alpar@9 81 VIOLIN 100
alpar@9 82 WALTZ 34 ;
alpar@9 83
alpar@9 84 end;