MCPcopy Create free account
hub / github.com/Gecode/gecode / p_regular

Function p_regular

gecode/flatzinc/registry.cpp:1156–1202  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1154 }
1155
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;
1160
1161 int noOfTrans = 0;
1162 for (int i=0; i<q; i++) {
1163 for (int j=0; j<symbols; j++) {
1164 if (d[i*symbols+j] > 0)
1165 noOfTrans++;
1166 }
1167 }
1168
1169 Region re;
1170 DFA::Transition* t = re.alloc<DFA::Transition>(noOfTrans+1);
1171 noOfTrans = 0;
1172 for (int i=1; i<=q; i++) {
1173 for (int j=0; j<symbols; j++) {
1174 if (d[(i-1)*symbols+j] > 0) {
1175 t[noOfTrans].i_state = i;
1176 t[noOfTrans].symbol = symbols_min + j;
1177 t[noOfTrans].o_state = d[(i-1)*symbols+j];
1178 noOfTrans++;
1179 }
1180 }
1181 }
1182 t[noOfTrans].i_state = -1;
1183
1184 // Final states
1185 int* f;
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;
1191 } else {
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;
1196 }
1197
1198 DFA dfa(q0,t,f);
1199 free(f);
1200 unshare(s, iv);
1201 extensional(s, iv, s.getSharedDFA(dfa), s.ann2ipl(ann));
1202 }
1203
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(),

Callers 1

p_regular_setFunction · 0.85

Calls 10

unshareFunction · 0.85
getSharedDFAMethod · 0.80
ann2iplMethod · 0.80
arg2intvarargsMethod · 0.80
getIntMethod · 0.80
arg2intargsMethod · 0.80
getSetMethod · 0.80
extensionalFunction · 0.50
rallocMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected