Code Duplication    Length = 185-185 lines in 2 locations

src/main/java/it/cnr/istc/pst/platinum/ai/framework/microkernel/resolver/plan/TimelineAwarePlanRefinementResolver.java 1 location

@@ 1442-1626 (lines=185) @@
1439
		Decision goal = expansion.getGoalDecision();
1440
		
1441
		// check subgoals from selected synchronization rule if any
1442
		if (expansion.hasSubGoals()) {
1443
			
1444
			// get the rule to apply
1445
			SynchronizationRule rule = expansion.getSynchronizationRule();
1446
			// create an index of token variable
1447
			Map<TokenVariable, Decision> var2dec = new HashMap<>();
1448
			var2dec.put(rule.getTriggerer(), goal);
1449
			// add pending decisions
1450
			for (TokenVariable var : rule.getTokenVariables()) {
1451
				
1452
				// get target component
1453
				DomainComponent target = var.getValue().getComponent(); 
1454
				// create a pending decision
1455
				Decision pending = target.create(
1456
						var.getValue(),
1457
						var.getParameterLabels());
1458
				
1459
				// set causal link
1460
				pending.setCausalLink(goal);
1461
				// check solving knowledge
1462
				if (var.isMandatoryExpansion()) {
1463
					pending.setMandatoryExpansion();
1464
				}
1465
1466
				// check solving knowledge
1467
				if (var.isMandatoryUnificaiton()) {
1468
					pending.setMandatoryUnification();
1469
				}
1470
				
1471
				// add entry to cache
1472
				var2dec.put(var, pending);
1473
				// add created decision
1474
				expansion.addCreatedDecision(pending);
1475
			}
1476
			
1477
			// add pending relations
1478
			for (SynchronizationConstraint c : rule.getConstraints()) {
1479
				// check category
1480
				switch (c.getCategory()) {
1481
1482
					// temporal category
1483
					case TEMPORAL_CONSTRAINT : {
1484
						
1485
						// temporal constraint
1486
						TemporalSynchronizationConstraint tc = (TemporalSynchronizationConstraint) c;
1487
						// get decisions
1488
						Decision reference = var2dec.get(tc.getReference());
1489
						Decision target = var2dec.get(tc.getTarget());
1490
						// get reference component
1491
						DomainComponent refComp = reference.getComponent();
1492
						// create pending relation
1493
						TemporalRelation rel = refComp.create(tc.getType(), reference, target);
1494
						// set bounds
1495
						rel.setBounds(tc.getBounds());
1496
						// add created relation
1497
						expansion.addCreatedRelation(rel);
1498
					}
1499
					break;
1500
					
1501
					// parameter category
1502
					case PARAMETER_CONSTRAINT: {
1503
						
1504
						// parameter constraint
1505
						ParameterSynchronizationConstraint pc = (ParameterSynchronizationConstraint) c;
1506
						// get decisions
1507
						Decision reference = var2dec.get(pc.getReference());
1508
						Decision target = var2dec.get(pc.getTarget());
1509
						// get reference component
1510
						DomainComponent refComp = reference.getComponent();
1511
						// create pending relation
1512
						ParameterRelation rel = (ParameterRelation) refComp.create(pc.getType(), reference, target);
1513
						
1514
						// check parameter relation type
1515
						switch (rel.getType()) {
1516
						
1517
							// bind parameter relation
1518
							case BIND_PARAMETER : {
1519
								
1520
								// bind constraint
1521
								BindParameterRelation bind = (BindParameterRelation) rel;
1522
								// set binding value
1523
								bind.setValue(pc.getTargetLabel());
1524
								// set reference label
1525
								if (pc.getReference().equals(rule.getTriggerer())) {
1526
									
1527
									// get trigger label index
1528
									int index = rule.getTriggerer().getParameterIndexByLabel(pc.getReferenceLabel());
1529
									// set decision's label
1530
									String label = goal.getParameterLabelByIndex(index);
1531
									// set label
1532
									bind.setReferenceParameterLabel(label);
1533
									
1534
								} else {
1535
									
1536
									bind.setReferenceParameterLabel(pc.getReferenceLabel());
1537
								}
1538
							}
1539
							break;
1540
							
1541
							// equal parameter relation
1542
							case EQUAL_PARAMETER : {
1543
								
1544
								// get relation
1545
								EqualParameterRelation eq = (EqualParameterRelation) rel;
1546
								
1547
								// check if source is the trigger
1548
								if (pc.getReference().equals(rule.getTriggerer())) {
1549
									
1550
									// get trigger label index
1551
									int index = rule.getTriggerer().getParameterIndexByLabel(pc.getReferenceLabel());
1552
									// get decions's label
1553
									String label = goal.getParameterLabelByIndex(index);
1554
									// set label
1555
									eq.setReferenceParameterLabel(label);
1556
									
1557
								} else {
1558
									
1559
									// directly set the label
1560
									eq.setReferenceParameterLabel(pc.getReferenceLabel());
1561
								}
1562
								
1563
								// check if target is the trigger
1564
								if (pc.getTarget().equals(rule.getTriggerer())) {
1565
									
1566
									// get trigger label index
1567
									int index = rule.getTriggerer().getParameterIndexByLabel(pc.getTargetLabel());
1568
									// get decision's label
1569
									String label = goal.getParameterLabelByIndex(index);
1570
									// set label
1571
									eq.setTargetParameterLabel(label);
1572
									
1573
								} else {
1574
									
1575
									// directly set the label
1576
									eq.setTargetParameterLabel(pc.getTargetLabel());
1577
								}
1578
							}
1579
							break;
1580
							
1581
							// not-equal parameter relation
1582
							case NOT_EQUAL_PARAMETER : {
1583
								
1584
								// get relation
1585
								NotEqualParameterRelation neq = (NotEqualParameterRelation) rel;
1586
								
1587
								// check if source is the trigger
1588
								if (pc.getReference().equals(rule.getTriggerer())) {
1589
									
1590
									// get trigger label index
1591
									int index = rule.getTriggerer().getParameterIndexByLabel(pc.getReferenceLabel());
1592
									// get decions's label
1593
									String label = goal.getParameterLabelByIndex(index);
1594
									// set label
1595
									neq.setReferenceParameterLabel(label);
1596
									
1597
								} else {
1598
									
1599
									// directly set the label
1600
									neq.setReferenceParameterLabel(pc.getReferenceLabel());
1601
								}
1602
								
1603
								// check if target is the trigger
1604
								if (pc.getTarget().equals(rule.getTriggerer())) {
1605
									
1606
									// get trigger label index
1607
									int index = rule.getTriggerer().getParameterIndexByLabel(pc.getTargetLabel());
1608
									// get decision's label
1609
									String label = goal.getParameterLabelByIndex(index);
1610
									// set label
1611
									neq.setTargetParameterLabel(label);
1612
									
1613
								} else {
1614
									// directly set the label
1615
									neq.setTargetParameterLabel(pc.getTargetLabel());
1616
								}
1617
							}
1618
							break;
1619
							
1620
							default : {
1621
								throw new RuntimeException("Unknown parameter constraint type - " + rel.getType());
1622
							}
1623
						}
1624
						
1625
						// add created relation
1626
						expansion.addCreatedRelation(rel);
1627
					}
1628
				}
1629
			}

src/main/java/it/cnr/istc/pst/platinum/ai/framework/microkernel/resolver/plan/PlanRefinementResolver.java 1 location

@@ 1257-1441 (lines=185) @@
1254
		// get goal
1255
		Decision goal = expansion.getGoalDecision();
1256
		// check subgoals from selected synchronization rule if any
1257
		if (expansion.hasSubGoals()) {
1258
			
1259
			// get the rule to apply
1260
			SynchronizationRule rule = expansion.getSynchronizationRule();
1261
			// create an index of token variable
1262
			Map<TokenVariable, Decision> var2dec = new HashMap<>();
1263
			var2dec.put(rule.getTriggerer(), goal);
1264
			// add pending decisions
1265
			for (TokenVariable var : rule.getTokenVariables()) {
1266
				
1267
				// get target component
1268
				DomainComponent target = var.getValue().getComponent(); 
1269
				// create a pending decision
1270
				Decision pending = target.create(
1271
						var.getValue(),
1272
						var.getParameterLabels());
1273
				
1274
				// set causal link
1275
				pending.setCausalLink(goal);
1276
				// check solving knowledge
1277
				if (var.isMandatoryExpansion()) {
1278
					pending.setMandatoryExpansion();
1279
				}
1280
1281
				// check solving knowledge
1282
				if (var.isMandatoryUnificaiton()) {
1283
					pending.setMandatoryUnification();
1284
				}
1285
				
1286
				// add entry to cache
1287
				var2dec.put(var, pending);
1288
				// add created decision
1289
				expansion.addCreatedDecision(pending);
1290
			}
1291
			
1292
			// add pending relations
1293
			for (SynchronizationConstraint c : rule.getConstraints()) {
1294
				// check category
1295
				switch (c.getCategory()) {
1296
1297
					// temporal category
1298
					case TEMPORAL_CONSTRAINT : {
1299
						
1300
						// temporal constraint
1301
						TemporalSynchronizationConstraint tc = (TemporalSynchronizationConstraint) c;
1302
						// get decisions
1303
						Decision reference = var2dec.get(tc.getReference());
1304
						Decision target = var2dec.get(tc.getTarget());
1305
						// get reference component
1306
						DomainComponent refComp = reference.getComponent();
1307
						// create pending relation
1308
						TemporalRelation rel = refComp.create(tc.getType(), reference, target);
1309
						// set bounds
1310
						rel.setBounds(tc.getBounds());
1311
						// add created relation
1312
						expansion.addCreatedRelation(rel);
1313
					}
1314
					break;
1315
					
1316
					// parameter category
1317
					case PARAMETER_CONSTRAINT: {
1318
						
1319
						// parameter constraint
1320
						ParameterSynchronizationConstraint pc = (ParameterSynchronizationConstraint) c;
1321
						// get decisions
1322
						Decision reference = var2dec.get(pc.getReference());
1323
						Decision target = var2dec.get(pc.getTarget());
1324
						// get reference component
1325
						DomainComponent refComp = reference.getComponent();
1326
						// create pending relation
1327
						ParameterRelation rel = (ParameterRelation) refComp.create(pc.getType(), reference, target);
1328
						
1329
						// check parameter relation type
1330
						switch (rel.getType()) {
1331
						
1332
							// bind parameter relation
1333
							case BIND_PARAMETER : {
1334
								
1335
								// bind constraint
1336
								BindParameterRelation bind = (BindParameterRelation) rel;
1337
								// set binding value
1338
								bind.setValue(pc.getTargetLabel());
1339
								// set reference label
1340
								if (pc.getReference().equals(rule.getTriggerer())) {
1341
									
1342
									// get trigger label index
1343
									int index = rule.getTriggerer().getParameterIndexByLabel(pc.getReferenceLabel());
1344
									// set decision's label
1345
									String label = goal.getParameterLabelByIndex(index);
1346
									// set label
1347
									bind.setReferenceParameterLabel(label);
1348
									
1349
								} else {
1350
									
1351
									bind.setReferenceParameterLabel(pc.getReferenceLabel());
1352
								}
1353
							}
1354
							break;
1355
							
1356
							// equal parameter relation
1357
							case EQUAL_PARAMETER : {
1358
								
1359
								// get relation
1360
								EqualParameterRelation eq = (EqualParameterRelation) rel;
1361
								
1362
								// check if source is the trigger
1363
								if (pc.getReference().equals(rule.getTriggerer())) {
1364
									
1365
									// get trigger label index
1366
									int index = rule.getTriggerer().getParameterIndexByLabel(pc.getReferenceLabel());
1367
									// get decions's label
1368
									String label = goal.getParameterLabelByIndex(index);
1369
									// set label
1370
									eq.setReferenceParameterLabel(label);
1371
									
1372
								} else {
1373
									
1374
									// directly set the label
1375
									eq.setReferenceParameterLabel(pc.getReferenceLabel());
1376
								}
1377
								
1378
								// check if target is the trigger
1379
								if (pc.getTarget().equals(rule.getTriggerer())) {
1380
									
1381
									// get trigger label index
1382
									int index = rule.getTriggerer().getParameterIndexByLabel(pc.getTargetLabel());
1383
									// get decision's label
1384
									String label = goal.getParameterLabelByIndex(index);
1385
									// set label
1386
									eq.setTargetParameterLabel(label);
1387
									
1388
								} else {
1389
									
1390
									// directly set the label
1391
									eq.setTargetParameterLabel(pc.getTargetLabel());
1392
								}
1393
							}
1394
							break;
1395
							
1396
							// not-equal parameter relation
1397
							case NOT_EQUAL_PARAMETER : {
1398
								
1399
								// get relation
1400
								NotEqualParameterRelation neq = (NotEqualParameterRelation) rel;
1401
								
1402
								// check if source is the trigger
1403
								if (pc.getReference().equals(rule.getTriggerer())) {
1404
									
1405
									// get trigger label index
1406
									int index = rule.getTriggerer().getParameterIndexByLabel(pc.getReferenceLabel());
1407
									// get decions's label
1408
									String label = goal.getParameterLabelByIndex(index);
1409
									// set label
1410
									neq.setReferenceParameterLabel(label);
1411
									
1412
								} else {
1413
									
1414
									// directly set the label
1415
									neq.setReferenceParameterLabel(pc.getReferenceLabel());
1416
								}
1417
								
1418
								// check if target is the trigger
1419
								if (pc.getTarget().equals(rule.getTriggerer())) {
1420
									
1421
									// get trigger label index
1422
									int index = rule.getTriggerer().getParameterIndexByLabel(pc.getTargetLabel());
1423
									// get decision's label
1424
									String label = goal.getParameterLabelByIndex(index);
1425
									// set label
1426
									neq.setTargetParameterLabel(label);
1427
									
1428
								} else {
1429
									// directly set the label
1430
									neq.setTargetParameterLabel(pc.getTargetLabel());
1431
								}
1432
							}
1433
							break;
1434
							
1435
							default : {
1436
								throw new RuntimeException("Unknown parameter constraint type - " + rel.getType());
1437
							}
1438
						}
1439
						
1440
						// add created relation
1441
						expansion.addCreatedRelation(rel);
1442
					}
1443
				}
1444
			}