@@ -1153,17 +1153,15 @@ namespace Gecode { namespace FlatZinc {
11531153 argmax (s, bv, offset, s.arg2IntVar (ce[2 ]), true , s.ann2ipl (ann));
11541154 }
11551155
1156- void p_regular (FlatZincSpace& s, const ConExpr& ce, AST::Node* ann) {
1157- IntVarArgs iv = s.arg2intvarargs (ce[0 ]);
1158- int q = ce[1 ]->getInt ();
1159- int symbols = ce[2 ]->getInt ();
1160- IntArgs d = s.arg2intargs (ce[3 ]);
1161- int q0 = ce[4 ]->getInt ();
1156+ void p_regular (FlatZincSpace& s, IntVarArgs iv, int q, int symbols_min,
1157+ int symbols_max, IntArgs d, int q0, AST::SetLit* finals,
1158+ AST::Node* ann) {
1159+ int symbols = symbols_max - symbols_min + 1 ;
11621160
11631161 int noOfTrans = 0 ;
1164- for (int i=1 ; i<= q; i++) {
1165- for (int j=1 ; j<= symbols; j++) {
1166- if (d[(i- 1 ) *symbols+(j- 1 ) ] > 0 )
1162+ for (int i=0 ; i<q; i++) {
1163+ for (int j=0 ; j<symbols; j++) {
1164+ if (d[i *symbols+j ] > 0 )
11671165 noOfTrans++;
11681166 }
11691167 }
@@ -1172,38 +1170,48 @@ namespace Gecode { namespace FlatZinc {
11721170 DFA::Transition* t = re.alloc <DFA::Transition>(noOfTrans+1 );
11731171 noOfTrans = 0 ;
11741172 for (int i=1 ; i<=q; i++) {
1175- for (int j=1 ; j<= symbols; j++) {
1176- if (d[(i-1 )*symbols+(j- 1 ) ] > 0 ) {
1173+ for (int j=0 ; j<symbols; j++) {
1174+ if (d[(i-1 )*symbols+j ] > 0 ) {
11771175 t[noOfTrans].i_state = i;
1178- t[noOfTrans].symbol = j;
1179- t[noOfTrans].o_state = d[(i-1 )*symbols+(j- 1 ) ];
1176+ t[noOfTrans].symbol = symbols_min + j;
1177+ t[noOfTrans].o_state = d[(i-1 )*symbols+j ];
11801178 noOfTrans++;
11811179 }
11821180 }
11831181 }
11841182 t[noOfTrans].i_state = -1 ;
11851183
11861184 // Final states
1187- AST::SetLit* sl = ce[5 ]->getSet ();
11881185 int * f;
1189- if (sl ->interval ) {
1190- f = static_cast <int *>(heap.ralloc (sizeof (int )*(sl ->max -sl ->min +2 )));
1191- for (int i=sl ->min ; i<=sl ->max ; i++)
1192- f[i-sl ->min ] = i;
1193- f[sl ->max -sl ->min +1 ] = -1 ;
1186+ if (finals ->interval ) {
1187+ f = static_cast <int *>(heap.ralloc (sizeof (int )*(finals ->max -finals ->min +2 )));
1188+ for (int i=finals ->min ; i<=finals ->max ; i++)
1189+ f[i-finals ->min ] = i;
1190+ f[finals ->max -finals ->min +1 ] = -1 ;
11941191 } else {
1195- f = static_cast <int *>(heap.ralloc (sizeof (int )*(sl ->s .size ()+1 )));
1196- for (int j=sl ->s .size (); j--; )
1197- f[j] = sl ->s [j];
1198- f[sl ->s .size ()] = -1 ;
1192+ f = static_cast <int *>(heap.ralloc (sizeof (int )*(finals ->s .size ()+1 )));
1193+ for (int j=finals ->s .size (); j--; )
1194+ f[j] = finals ->s [j];
1195+ f[finals ->s .size ()] = -1 ;
11991196 }
12001197
12011198 DFA dfa (q0,t,f);
12021199 free (f);
12031200 unshare (s, iv);
1204- extensional (s, iv, s.getSharedDFA (dfa), s.ann2ipl (ann));
1201+ extensional (s, iv, s.getSharedDFA (dfa), s.ann2ipl (ann));
12051202 }
12061203
1204+ void p_regular (FlatZincSpace& s, const ConExpr& ce, AST::Node* ann) {
1205+ p_regular (s, s.arg2intvarargs (ce[0 ]), ce[1 ]->getInt (), 1 , ce[2 ]->getInt (),
1206+ s.arg2intargs (ce[3 ]), ce[4 ]->getInt (), ce[5 ]->getSet (), ann);
1207+ }
1208+
1209+ void p_regular_set (FlatZincSpace& s, const ConExpr& ce, AST::Node* ann) {
1210+ p_regular (s, s.arg2intvarargs (ce[0 ]), ce[1 ]->getInt (), ce[2 ]->getInt (),
1211+ ce[3 ]->getInt (), s.arg2intargs (ce[4 ]), ce[5 ]->getInt (),
1212+ ce[6 ]->getSet (), ann);
1213+ }
1214+
12071215 void
12081216 p_sort (FlatZincSpace& s, const ConExpr& ce, AST::Node* ann) {
12091217 IntVarArgs x = s.arg2intvarargs (ce[0 ]);
@@ -1788,6 +1796,7 @@ namespace Gecode { namespace FlatZinc {
17881796 registry ().add (" gecode_maximum_arg_bool_offset" , &p_maximum_arg_bool);
17891797 registry ().add (" array_int_maximum" , &p_maximum);
17901798 registry ().add (" gecode_regular" , &p_regular);
1799+ registry ().add (" gecode_regular_set" , &p_regular_set);
17911800 registry ().add (" sort" , &p_sort);
17921801 registry ().add (" inverse_offsets" , &p_inverse_offsets);
17931802 registry ().add (" increasing_int" , &p_increasing_int);
0 commit comments