35
35
import kodkod .ast .Decls ;
36
36
import kodkod .ast .Expression ;
37
37
import kodkod .ast .Formula ;
38
+ import kodkod .ast .IntConstant ;
38
39
import kodkod .ast .Relation ;
39
40
import kodkod .ast .Variable ;
40
41
import kodkod .engine .Evaluator ;
@@ -235,16 +236,25 @@ public TemporalInstance(Instance instance, PardinusBounds extbounds) {
235
236
* Will change <bounds> if not all atoms of the universe are present at <reif>.
236
237
*
237
238
* @assumes reif != null
238
- * @param bounds the declaration of the relations
239
239
* @param reif the previously reified atoms
240
240
* @param formula formula used to identify the relevant relations
241
+ * @param bounds the declaration of the relations
241
242
* @throws NullPointerException reif = null
242
243
* @return the formula representing <this>
243
244
*/
244
245
// [HASLab]
245
246
@ Override
246
- public Formula formulate (Bounds bounds , Map <Object , Expression > reif , Formula formula , boolean someDisj ) {
247
- return formulate (bounds , reif , formula , -1 , null , someDisj );
247
+ public Formula formulate (Map <Object , Expression > reif , Formula formula , boolean someDisj , Bounds bounds ) {
248
+ return formulate (bounds , reif , formula , -1 , null , someDisj , true );
249
+ }
250
+
251
+ @ Override
252
+ public Formula formulate (Map <Object , Expression > reif , Formula formula , boolean someDisj , Bounds bounds , boolean localUniv ) {
253
+ return formulate (bounds , reif , formula , -1 , null , someDisj , localUniv );
254
+ }
255
+
256
+ public Formula formulate (Bounds bounds , Map <Object , Expression > reif , Formula formula , int start , Integer end , boolean someDisj ) {
257
+ return formulate (bounds , reif , formula , start , end , someDisj , true );
248
258
}
249
259
250
260
/**
@@ -274,7 +284,7 @@ public Formula formulate(Bounds bounds, Map<Object, Expression> reif, Formula fo
274
284
* @return the formula representing <this>
275
285
*/
276
286
// [HASLab]
277
- public Formula formulate (Bounds bounds , Map <Object , Expression > reif , Formula formula , int start , Integer end , boolean someDisj ) {
287
+ public Formula formulate (Bounds bounds , Map <Object , Expression > reif , Formula formula , int start , Integer end , boolean someDisj , boolean localUniv ) {
278
288
if (start < -1 )
279
289
throw new IllegalArgumentException ("Segment start must be >= -1." );
280
290
if (end != null && end < start )
@@ -283,22 +293,24 @@ public Formula formulate(Bounds bounds, Map<Object, Expression> reif, Formula fo
283
293
// reify atoms not yet reified
284
294
Universe sta_uni = states .get (0 ).universe ();
285
295
for (int i = 0 ; i < sta_uni .size (); i ++) {
286
- Expression r ;
287
- if (!reif .keySet ().contains (sta_uni .atom (i ))) {
288
- if (someDisj ) {
289
- r = Variable .unary (sta_uni .atom (i ).toString ());
296
+ // integers do not need to be quantified
297
+ if (!sta_uni .atom (i ).toString ().matches ("-?\\ d+" )) {
298
+ Expression r ;
299
+ if (!reif .keySet ().contains (sta_uni .atom (i ))) {
300
+ if (someDisj ) {
301
+ r = Variable .unary (sta_uni .atom (i ).toString ());
302
+ } else {
303
+ r = Relation .atom (sta_uni .atom (i ).toString ());
304
+ }
305
+ reif .put (sta_uni .atom (i ), r );
290
306
} else {
291
- r = Relation . atom (sta_uni .atom (i ). toString ( ));
307
+ r = reif . get (sta_uni .atom (i ));
292
308
}
293
- reif .put (sta_uni .atom (i ), r );
294
- } else {
295
- r = reif .get (sta_uni .atom (i ));
309
+ if (!someDisj && !bounds .relations .contains (r ))
310
+ bounds .boundExactly ((Relation ) r , bounds .universe ().factory ().setOf (sta_uni .atom (i )));
296
311
}
297
- if (!someDisj && !bounds .relations .contains ((Relation ) r ))
298
- bounds .boundExactly ((Relation ) r , bounds .universe ().factory ().setOf (sta_uni .atom (i )));
299
312
}
300
313
301
-
302
314
Set <Relation > staticss = new HashSet <Relation >();
303
315
for (Relation r : states .get (0 ).relations ())
304
316
if (!r .isVariable ())
@@ -318,11 +330,11 @@ public Formula formulate(Bounds bounds, Map<Object, Expression> reif, Formula fo
318
330
// TODO: the looping formula should also be offset in this case!
319
331
if (j == null )
320
332
j = Integer .max (start + (prefixLength () - 1 ) - loop , prefixLength () - 1 );
321
- if (j >= 0 ) {
333
+ if (j != null && j >= 0 ) {
322
334
// the state formulas, start from the end and accumulate afters
323
- res = state (j --).formulate (bounds , reif , slcs .getValue (), someDisj );
335
+ res = state (j --).formulate (reif , slcs .getValue (), someDisj , bounds , ! localUniv );
324
336
for (; j >= Integer .max (0 , start ); j --)
325
- res = state (j ).formulate (bounds , reif , slcs .getValue (), someDisj ).and (res .after ());
337
+ res = state (j ).formulate (reif , slcs .getValue (), someDisj , bounds , ! localUniv ).and (res .after ());
326
338
// after offset when start > 0
327
339
for (; j >= 0 ; j --)
328
340
res = res .after ();
@@ -331,7 +343,7 @@ public Formula formulate(Bounds bounds, Map<Object, Expression> reif, Formula fo
331
343
332
344
// the configuration formula, if start = -1
333
345
if (start < 0 && !slcs .getKey ().equals (Formula .TRUE )) {
334
- Formula sres = states .get (prefixLength () - 1 ).formulate (bounds , reif , slcs .getKey (), someDisj );
346
+ Formula sres = states .get (prefixLength () - 1 ).formulate (reif , slcs .getKey (), someDisj , bounds , false );
335
347
res = res .equals (Formula .TRUE ) ? sres : sres .and (res );
336
348
}
337
349
@@ -340,14 +352,14 @@ public Formula formulate(Bounds bounds, Map<Object, Expression> reif, Formula fo
340
352
// create the looping constraint
341
353
// after^loop always (Sloop => after^(end-loop) Sloop && Sloop+1 =>
342
354
// after^(end-loop) Sloop+1 && ...)
343
- Formula rei = states .get (loop ).formulate (bounds , reif , slcs .getValue (), someDisj );
355
+ Formula rei = states .get (loop ).formulate (reif , slcs .getValue (), someDisj , bounds , ! localUniv );
344
356
Formula rei2 = rei ;
345
357
for (int i = loop ; i < prefixLength (); i ++)
346
358
rei2 = rei2 .after ();
347
359
348
360
Formula looping = rei .implies (rei2 );
349
361
for (int i = loop + 1 ; i < prefixLength (); i ++) {
350
- rei = states .get (i ).formulate (bounds , reif , slcs .getValue (), someDisj );
362
+ rei = states .get (i ).formulate (reif , slcs .getValue (), someDisj , bounds , ! localUniv );
351
363
rei2 = rei ;
352
364
for (int k = loop ; k < prefixLength (); k ++)
353
365
rei2 = rei2 .after ();
@@ -372,7 +384,11 @@ public Formula formulate(Bounds bounds, Map<Object, Expression> reif, Formula fo
372
384
decls = decls .and (((Variable ) e ).oneOf (Expression .UNIV ));
373
385
}
374
386
}
375
- res = (al .eq (Expression .UNIV )).and (res );
387
+ for (int i = 0 ; i < sta_uni .size (); i ++)
388
+ if (sta_uni .atom (i ).toString ().matches ("-?\\ d+" ))
389
+ al = al .union (IntConstant .constant (Integer .valueOf (sta_uni .atom (i ).toString ())).toExpression ());
390
+ if (localUniv )
391
+ res = (al .eq (Expression .UNIV )).and (res );
376
392
res = res .forSome (decls );
377
393
}
378
394
}
0 commit comments