| 1 |
/*** |
| 2 |
!Test |
| 3 |
solvers: [gecode] |
| 4 |
expected: |
| 5 |
- !Result |
| 6 |
solution: !Solution |
| 7 |
reg_input: |
| 8 |
- 1 |
| 9 |
- 2 |
| 10 |
- 3 |
| 11 |
- 3 |
| 12 |
- 3 |
| 13 |
- 2 |
| 14 |
- 1 |
| 15 |
reg_input2: |
| 16 |
- 1 |
| 17 |
- 2 |
| 18 |
- 3 |
| 19 |
- 3 |
| 20 |
- 3 |
| 21 |
- 3 |
| 22 |
- 3 |
| 23 |
- 3 |
| 24 |
- 3 |
| 25 |
- 2 |
| 26 |
- 1 |
| 27 |
***/ |
| 28 |
|
| 29 |
include "regular.mzn"; |
| 30 |
|
| 31 |
%-----------------------------------------------------------------------------% |
| 32 |
% regular |
| 33 |
%-----------------------------------------------------------------------------% |
| 34 |
% regexp is: 123*21. |
| 35 |
|
| 36 |
int: n_states = 5; |
| 37 |
int: input_max = 3; |
| 38 |
int: initial_state = 1; |
| 39 |
set of int: accepting_states = {5}; |
| 40 |
array[1..5, 1..3] of int: transition_fn = |
| 41 |
[|2, 0, 0 % transitions from state 1: --1--> state 2 |
| 42 |
|0, 3, 0 % transitions from state 2: --2--> state 3 |
| 43 |
|0, 4, 3 % transitions from state 3: --2--> state 4, --3--> state 3 |
| 44 |
|5, 0, 0 % transitions from state 4: --1--> state 5 |
| 45 |
|0, 0, 0|];% transitions from state 5: (none) |
| 46 |
|
| 47 |
array[-2..4] of var int: reg_input ::add_to_output = |
| 48 |
array1d(-2..4, [1, 2, _, _, _, 2, 1]); |
| 49 |
array[44..54] of var int: reg_input2 ::add_to_output; |
| 50 |
|
| 51 |
constraint regular(reg_input, n_states, input_max, transition_fn, |
| 52 |
initial_state, accepting_states); |
| 53 |
|
| 54 |
constraint regular(reg_input2, n_states, input_max, transition_fn, |
| 55 |
initial_state, accepting_states); |
| 56 |
|
| 57 |
solve satisfy; |
| 58 |
|
| 59 |
output [ |
| 60 |
"reg_input = array1d(-2..4, ", show(reg_input), ");\n", |
| 61 |
"reg_input2 = array1d(44..54, ", show(reg_input2), ");\n" |
| 62 |
]; |