# \[AMPL 24668\] AMPL for modelling dice rolls

**URL:** <https://discuss.ampl.com/t/ampl-24668-ampl-for-modelling-dice-rolls/568>\
**Category:** Google Group Mirror\
**Created:** [May 21, 2023, 9:17pm UTC](https://discuss.ampl.com/t/ampl-24668-ampl-for-modelling-dice-rolls/568 "2023-05-21T21:17:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Francesco](https://avatars.discourse-cdn.com/v4/letter/f/e47c2d/32.png) [@Francesco](https://discuss.ampl.com/u/Francesco)\
**Post date:** [May 21, 2023, 9:17pm UTC](https://discuss.ampl.com/t/ampl-24668-ampl-for-modelling-dice-rolls/568/1 "2023-05-21T21:17:52Z")

</div>

I need to create a model to assert which are the letters on each face of a 4 dices, given the results of generic 4 dices rolls. Each of the 6 faces of the 4 dices has a different letter (24 letters, J and X are missing). For example: rolling 12 times the dices and combining every time the obtained letters, we got the following words: AGHI EZIO SLAM BOVE MICK TAEG CLUB NAVE TUFO DROP QUAD YORK I can’t find an objective to solve this problem. Right now I got: .dat set I := “AGHI”,“EZIO”,“SLAM”,“BOVE”,“MICK”,“TAEG”,“CLUB”,“NAVE”,“TUFO”,“DROP”,“QUAD”,“YORK”;  
set L:= A B C D E F G H I K L M N O P Q R S T U V W Y Z;  
set D:= 1 2 3 4;  
set F:= 1 2 3 4 5 6; .mod set I;  
set L;  
set D;  
set F;

subject to Entry{i in I, d in D}: sum{f in F}(A[d,f,substr(i,0,1)] + A[d,f,substr(i,1,1)] + A[d,f,substr(i,2,1)] + A[d,f,substr(i,3,1)]) = 1;

subject to Unique{l in L}: sum{d in D, f in F}A[d,f,l] = 1;

subject to Unique2{d in D, f in F}: sum{l in L}A[d,f,l] = 1; But I can’t get anything out of it. Do you have suggestions? Thanks!!!

---

<div class="post-metadata">

**Author:** ![hakank](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/hakank/32/82_2.png) [@hakank](https://discuss.ampl.com/u/hakank)\
**Post date:** [May 22, 2023, 8:33am UTC](https://discuss.ampl.com/t/ampl-24668-ampl-for-modelling-dice-rolls/568/2 "2023-05-22T08:33:11Z")

</div>

This problem seems to be very similar to some other puzzles (Labeled Dice and Building Blocks) that I modeled in AMPL many years ago.

At the AMPL repo ([ampl.github.io/models/hakan at master · ampl/ampl.github.io · GitHub](https://github.com/ampl/ampl.github.io/tree/master/models/hakan/) ) there are some AMPL models that you can be inspired by:

- [ampl.github.io/building\_blocks.mod at master · ampl/ampl.github.io · GitHub](https://github.com/ampl/ampl.github.io/blob/master/models/hakan/building_blocks.mod)

- [ampl.github.io/labeled\_dice.mod at master · ampl/ampl.github.io · GitHub](https://github.com/ampl/ampl.github.io/blob/master/models/hakan/labeled_dice.mod)

- [ampl.github.io/labeled\_dice2.mod at master · ampl/ampl.github.io · GitHub](https://github.com/ampl/ampl.github.io/blob/master/models/hakan/labeled_dice2.mod)

- [ampl.github.io/labeled\_dice3.mod at master · ampl/ampl.github.io · GitHub](https://github.com/ampl/ampl.github.io/blob/master/models/hakan/labeled_dice3.mod)  
with the data files:

- [ampl.github.io/labeled\_dice.dat at master · ampl/ampl.github.io · GitHub](https://github.com/ampl/ampl.github.io/blob/master/models/hakan/labeled_dice.dat)
- [ampl.github.io/building\_blocks.dat at master · ampl/ampl.github.io · GitHub](https://github.com/ampl/ampl.github.io/blob/master/models/hakan/building_blocks.dat)

Note that all the models use the alldiff and element constraints which might not be suitable for you.

(These models are also available at my AMPL page: [My AMPL page](http://hakank.org/ampl/) and my GitHub repo: [hakank/ampl at master · hakank/hakank · GitHub](https://github.com/hakank/hakank/tree/master/ampl/) . )

Hope this helps

/Hakan

---

<div class="post-metadata">

**Author:** ![AMPL\_Google\_Group](https://avatars.discourse-cdn.com/v4/letter/a/9dc877/32.png) [@AMPL\_Google\_Group](https://discuss.ampl.com/u/AMPL_Google_Group)\
**Post date:** [May 24, 2023, 11:58am UTC](https://discuss.ampl.com/t/ampl-24668-ampl-for-modelling-dice-rolls/568/3 "2023-05-24T11:58:50Z")

</div>

You want to find an assignment of letters to the dice, so that all of the 12 observed words can be produced. So I would say that in AMPL, you just have a feasibility problem, where you want to assign values to the variables that satisfy all of the constraints. For a feasibility problem, you do not need to specify any objective.

The model that you give will not work, however, because it does not have a “var” statement to define the variables:

var A {D,F,L} binary;

You should choose a linear solver that accepts integer-valued variables, such as Gurobi, CPLEX, Xpress, or HiGHS.
