cheddar_3.3.0_aea10b3c/framework/architecture_generator/architecture_factory.adb

   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
------------------------------------------------------------------------------
------------------------------------------------------------------------------
-- Cheddar is a GNU GPL real-time scheduling analysis tool.
-- This program provides services to automatically check schedulability and
-- other performance criteria of real-time architecture models.
--
-- Copyright (C) 2002-2023, Frank Singhoff, Alain Plantec, Jerome Legrand,
--                          Hai Nam Tran, Stephane Rubini
--
-- The Cheddar project was started in 2002 by
-- Frank Singhoff, Lab-STICC UMR 6285, Université de Bretagne Occidentale
--
-- Cheddar has been published in the "Agence de Protection des Programmes/France" in 2008.
-- Since 2008, Ellidiss technologies also contributes to the development of
-- Cheddar and provides industrial support.
--
-- The full list of contributors and sponsors can be found in README.md
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; either version 2 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
--
--
-- Contact : cheddar@listes.univ-brest.fr
--
------------------------------------------------------------------------------
-- Last update :
--    $Rev: 4589 $
--    $Date: 2023-09-29 16:02:19 +0200 (ven., 29 sept. 2023) $
--    $Author: singhoff $
------------------------------------------------------------------------------
------------------------------------------------------------------------------

with Generic_Graph; use Generic_Graph;
with Tasks;         use Tasks;

with task_set; use task_set;

with Task_Groups; use Task_Groups;

with task_group_set; use task_group_set;

with Buffers; use Buffers;

with Messages; use Messages;

with Dependencies; use Dependencies;

with Resources; use Resources;
use Resources.Resource_Accesses;

with systems; use systems;

with Processors;        use Processors;
with processor_set;     use processor_set;
with Address_Spaces;    use Address_Spaces;
with address_space_set; use address_space_set;
with Caches;            use Caches;
with Caches;            use Caches.Cache_Blocks_Table_Package;
with message_set;       use message_set;

with buffer_set; use buffer_set;

with network_set;        use network_set;
with event_analyzer_set; use event_analyzer_set;
with resource_set;       use resource_set;

with task_dependencies; use task_dependencies;

with Buffers; use Buffers;
use Buffers.Buffer_Roles_Package;

with Queueing_Systems; use Queueing_Systems;

with unbounded_strings; use unbounded_strings;
with convert_strings;
with convert_unbounded_strings;

with Text_IO;             use Text_IO;
with systems;             use systems;
with Objects;             use Objects;
with Parameters.extended; use Parameters.extended;
with Scheduler_Interface; use Scheduler_Interface;

with Ada.Finalization;
with Ada.Float_Text_IO;
with Ada.Numerics.Float_Random;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;

with unbounded_strings; use unbounded_strings;
use unbounded_strings.unbounded_string_list_package;

with architecture_factory; use architecture_factory;

with Memories; use Memories;
use Memories.Memories_Table_Package;

with Unchecked_Deallocation;

with sets;

with Framework_Config; use Framework_Config;

with Offsets;              use Offsets;
with Offsets;              use Offsets.Offsets_Table_Package;
with random_tools;         use random_tools;
with initialize_framework; use initialize_framework;

package body architecture_factory is

   cpt : Integer;
   procedure initialize_cpt is
   begin
      cpt := Integer (0);
   end initialize_cpt;

   -- 0 --------= System =--------
   procedure create_time_triggered_communication_system
     (s                     : in out system;
      number_tasks          : in     Integer;
      number_resources      : in     Integer;
      number_messages       : in     Integer;
      number_dependencies   : in     Integer;
      number_core_units     : in     Integer;
      number_processors     : in     Integer;
      number_buffers        : in     Integer;
      number_address_spaces : in     Integer)
   is
      i       : Integer;
      preempt : preemptives_type;
      sched   : schedulers_type;
   begin
      initialize (s);

      initialize_cpt;

      preempt := random_preemptivity;
      sched   := restrained_random_scheduler;

      i := 0;

      while (i < number_core_units) loop
         add_core_unit_to_system (s);
         i := i + 1;
      end loop;
      i := 0;
      while (i < number_processors) loop
         add_mono_core_processor_to_system (s, preempt, sched);
         i := i + 1;
      end loop;
      i := 0;
      while (i < number_address_spaces) loop
         add_address_space_to_system
           (s,
            get_random_element (s.processors).name);
         i := i + 1;
      end loop;
      i := 0;
      while (i < number_buffers) loop
         add_buffer_to_system (s);
         i := i + 1;
      end loop;
      i := 0;
      while (i < number_messages) loop
         i := i + 1;
      end loop;

      add_multiple_tasks_to_system (s, number_tasks, periodic_type);
      i := 0;
      while (i < number_resources) loop
         add_resource_to_system (s, 2);
         i := i + 1;
      end loop;
      i := 0;
      while (i < number_dependencies) loop
         add_time_triggered_communication_dependency_to_system (s);
         i := i + 1;
      end loop;

   end create_time_triggered_communication_system;

   procedure create_ravenscar_system
     (s                     : in out system;
      number_tasks          : in     Integer;
      number_resources      : in     Integer;
      number_messages       : in     Integer;
      number_dependencies   : in     Integer;
      number_core_units     : in     Integer;
      number_processors     : in     Integer;
      number_buffers        : in     Integer;
      number_address_spaces : in     Integer)
   is
      i       : Integer;
      preempt : preemptives_type;
      sched   : schedulers_type;
   begin
      initialize (s);
      initialize_cpt;

      preempt := random_preemptivity;
      sched   := restrained_random_scheduler;

      i := 0;

      while (i < number_core_units) loop
         add_core_unit_to_system (s);
         i := i + 1;
      end loop;
      i := 0;
      while (i < number_processors) loop
         add_mono_core_processor_to_system (s, preempt, sched);
         i := i + 1;
      end loop;

      i := 0;
      while (i < number_address_spaces) loop
         add_address_space_to_system
           (s,
            get_random_element (s.processors).name);
         i := i + 1;
      end loop;
      i := 0;
      while (i < number_buffers) loop
         add_buffer_to_system (s);
         i := i + 1;
      end loop;
      i := 0;
      while (i < number_messages) loop
         --Add_Message_To_System (S);
         i := i + 1;
      end loop;

      add_multiple_tasks_to_system (s, number_tasks, periodic_type);
      i := 0;
      while (i < number_resources) loop
         add_resource_to_system (s, 0);
         i := i + 1;
      end loop;
      i := 0;
      while (i < number_dependencies) loop
         add_time_triggered_communication_dependency_to_system (s);
         i := i + 1;
      end loop;

   end create_ravenscar_system;

   -- -------------------------------------------------------------------------
   --------------------
   -- This procedure creates X multiframes and adds frames to them.
   -- It first adds one frame to each at least
   -- Then it adds frames randomly to any multiframe
   -- X% of frames are added with respect to mf_period
   -- X% is computed according to sync_ratio (ratio of multiframes that have
   --the same mf_period)
   -- Synched multiframes have their tail frame's interarrival modified to
   --match mf_period
   -- Prec_Deps are added by going through synched multiframes.
   -- For each frame, a Prec_Dep is added with a probability of prec_prob
   -- The Prec_Dep is from the current multiframe's frame to the next
   --multiframe's random frame
   ----------------------------------------------------------------------------
   --------------------
   procedure create_mf_system
     (s                               : in out system;
      number_groups                   : in     Integer;
      number_frames                   : in     Integer;
      number_resources                : in     Integer;
      number_resource_usages          : in     Integer;
      number_core_units_per_processor : in     Integer;
      number_processors               : in     Integer;
      number_address_spaces           : in     Integer;
      sched                           : in     schedulers_type;
      mf_period                       : in     Integer := 0;
      sync_ratio                      : in     Double  := 0.0;
      number_precedences              : in     Integer := 0)
   is

      preempt : preemptives_type;
      i       : Integer;

   begin
      initialize (s);
      initialize_cpt;

      preempt := preemptive;

      -- ***** Processors generation *****
      add_multiple_processors_to_system
        (s,
         number_processors,
         number_core_units_per_processor,
         sched,
         preempt);

      -- ***** Address_Spaces generation *****
      add_multiple_address_spaces_consistently_to_system
        (s,
         number_processors,
         number_address_spaces);

      -- ***** Task Groups generation *****
      add_multiple_task_groups_to_system (s, number_groups, multiframe_type);

      -- ***** Tasks generation *****
      add_multiple_frame_tasks_to_system
        (s,
         number_frames,
         mf_period,
         sync_ratio);

      -- ***** Resources generation *****
      i := 0;
      while (i < number_resources) loop
         add_resource_to_system (s, number_resource_usages);
         i := i + 1;
      end loop;

      -- ***** Precedence Dependencies generation *****
      add_multiple_mf_precedence_dependencies_to_system
        (s,
         number_precedences,
         number_groups,
         sync_ratio);

   end create_mf_system;

   --------------------------------------------
   -- Generate_A_Customized_Ravenscar_System --
   --------------------------------------------

   procedure generate_a_customized_ravenscar_system
     (my_system               : in out system;
      n                       : in     Integer; -- number of tasks
      target_cpu_utilization  : in     Float; -- desired cpu utilization
      current_cpu_utilization : out Float; -- cpu utilization of the generated system
      n_diff_periods : in     Integer; -- number of maximum different periods
      n_resources             : in     Integer; -- number of resources
      rsf                     : in     Float; -- resource sharing factor
      csr                     : in     Float; -- critical section ratio
      a_sched_policy          : in     policies)

   is

      use Ada.Float_Text_IO;

      my_resources : resources_set;
      my_tasks     : tasks_set;

      suited_current_cpu_utilization : Boolean := False;
      schedulable                    : Boolean := False;
      variation_percentage           : Float   :=
        0.09;   -- Tolerated percentage of variation from the target cpu_utilization

   begin

      while not suited_current_cpu_utilization loop

         suited_current_cpu_utilization := False;

         current_cpu_utilization := 0.0;

         create_independant_periodic_taskset_system
           (s                       => my_system,
            current_cpu_utilization => current_cpu_utilization,
            n_tasks                 => n,
            target_cpu_utilization  => target_cpu_utilization,
            d_min                   => 1.0,
            d_max                   => 1.0,
            is_synchronous          => True,
            n_different_periods     => n_diff_periods, --10,
            a_sched_policy          => a_sched_policy);

         add_resource_set_to_system
           (s                       => my_system,
            n_resources             => n_resources,
            resource_sharing_factor => rsf,
            critical_section_ratio  => csr);

         if abs (target_cpu_utilization - current_cpu_utilization) <=
           variation_percentage
         then
            suited_current_cpu_utilization := True;
         end if;

      end loop;

   end generate_a_customized_ravenscar_system;

   ------------------------------------------------
   -- Create_Independant_Periodic_TaskSet_System --
   ------------------------------------------------

   procedure create_independant_periodic_taskset_system
     (s                       : in out system;
      current_cpu_utilization : in out Float;
      n_tasks                 : in     Integer;
      target_cpu_utilization  : in     Float;
      d_min                   : in     Float   := 1.0;
      d_max                   : in     Float   := 1.0;
      is_synchronous          : in     Boolean := True;
      n_different_periods     : in     Integer;
      a_sched_policy          : in     policies)

   is
      use Ada.Numerics.Float_Random;

      a_factor          : Integer;
      u_values          : random_tools.float_array (0 .. n_tasks - 1);
      t_values          : random_tools.integer_array (1 .. n_tasks);
      a_capacity        : Natural := 0;
      a_period          : Natural := 0;
      a_deadline        : Natural := 0;
      a_start_time      : Natural := 0;
      a_random_deadline : Float;
      omin, omax        : Float;
      a_random_offset   : Float;
      my_resources      : resources_set;
      my_tasks          : tasks_set;
      a_task_priority   : Integer;
      g                 : Ada.Numerics.Float_Random.Generator;

   begin

      if a_sched_policy = sched_fifo then
         a_task_priority := 1;
      else
         a_task_priority := 0;
      end if;

      a_factor := 1;--N_Tasks;
      Reset (g);

      u_values := gen_uunifast (n_tasks, target_cpu_utilization);

      t_values :=
        generate_period_set_with_limited_hyperperiod
          (n_tasks,
           n_different_periods);

      initialize (my_tasks);
      for i in 1 .. n_tasks loop

         a_period :=
           Natural
             (t_values (i) *
              a_factor); -- A_factor inflates the periods to avoid too much execution times
         -- equal to zero due to integer rounding

         a_capacity :=
           Integer (Float'rounding (Float (a_period) * u_values (i - 1)));
         if a_capacity = 0 then
            a_capacity := 1;
         end if;

         a_random_deadline := d_min + Random (g) * (d_max - d_min);
         while (a_random_deadline > d_max) or (a_random_deadline < d_min) loop
            a_random_deadline := d_min + Random (g) * (d_max - d_min);
         end loop;

         a_deadline :=
           Integer
             (Float'rounding
                (Float (a_period - a_capacity) * a_random_deadline)) +
           a_capacity;

         omin := 0.0;
         omax := Float (a_period);

         if (not is_synchronous) then
            a_random_offset := omin + Random (g) * (omax - omin);
            while (a_random_offset > omax) or (a_random_offset < omin) loop
               a_random_offset := omin + Random (g) * (omax - omin);
            end loop;
            a_start_time := Integer (Float'rounding (a_random_offset));
         else
            a_start_time := 0;
         end if;

         current_cpu_utilization :=
           current_cpu_utilization + Float (a_capacity) / Float (a_period);

         add_task
           (my_tasks           => my_tasks,
            name => suppress_space (To_Unbounded_String ("Task" & i'img)),
            cpu_name           => To_Unbounded_String ("processor1"),
            address_space_name => To_Unbounded_String ("addr1"),
            core_name          => empty_string,
            task_type          => periodic_type,
            start_time         => a_start_time,
            capacity           => a_capacity,
            period             => a_period,
            deadline           => a_deadline,
            jitter             => 0,
            blocking_time      => 0,
            priority           => a_task_priority,
            criticality        => 0,
            policy             => a_sched_policy);

      end loop;

      s.tasks := my_tasks;

   end create_independant_periodic_taskset_system;

   ------------------------------------------------
   -- Create_Independant_Periodic_TaskSet_System by generating only capacity--
   ------------------------------------------------

   procedure create_independant_periodic_taskset_system
     (s                       : in out system;
      current_cpu_utilization : in out Float;
      n_tasks                 : in     Integer;
      target_cpu_utilization  : in     Float;
      t_values                : in     integer_array;
      priority_values         : in     integer_array)

   is
      use Ada.Numerics.Float_Random;

      u_values        : random_tools.float_array (0 .. n_tasks - 1);
      a_capacity      : Natural := 0;
      a_period        : Natural := 0;
      a_deadline      : Natural := 0;
      a_start_time    : Natural := 0;
      my_resources    : resources_set;
      my_tasks        : tasks_set;
      a_task_priority : Integer;
      g               : Ada.Numerics.Float_Random.Generator;

   begin

      Reset (g);

      u_values := gen_uunifast (n_tasks, target_cpu_utilization);

--      T_values := Generate_Period_set_with_Limited_HyperPeriod (N_Tasks, N_Different_Periods);

      initialize (my_tasks);
      for i in 1 .. n_tasks loop

         a_task_priority := priority_values (i);
         a_period        := t_values (i);
         a_deadline      := a_period;
         a_capacity      :=
           Integer (Float'rounding (Float (a_period) * u_values (i - 1)));
         if a_capacity = 0 then
            a_capacity := 1;
         end if;

         current_cpu_utilization :=
           current_cpu_utilization + Float (a_capacity) / Float (a_period);

         add_task
           (my_tasks           => my_tasks,
            name => suppress_space (To_Unbounded_String ("Task" & i'img)),
            cpu_name           => To_Unbounded_String ("processor1"),
            address_space_name => To_Unbounded_String ("addr1"),
            core_name          => empty_string,
            task_type          => periodic_type,
            start_time         => a_start_time,
            capacity           => a_capacity,
            period             => a_period,
            deadline           => a_deadline,
            jitter             => 0,
            blocking_time      => 0,
            priority           => a_task_priority,
            criticality        => 0,
            policy             => sched_fifo);

      end loop;

      s.tasks := my_tasks;

   end create_independant_periodic_taskset_system;

   -- 8 --------= Tasks_Set =--------

   procedure add_task_deadline_equals_period_to_system
     (s                  : in out system;
      name               : in     Unbounded_String;
      cpu_name           : in     Unbounded_String;
      address_space_name : in     Unbounded_String;
      task_type          : in     tasks_type)
   is
      i : Integer;

   begin

      i := random_integer (64);
      add_task
        (my_tasks           => s.tasks,
         name               => name,
         cpu_name           => cpu_name,
         address_space_name => address_space_name,
         core_name          => empty_string,
         task_type          => task_type,
         start_time         => 0,
         capacity           => 1,
         period             => i,
         deadline           => i,
         jitter             => 0,
         blocking_time      => 0,
         priority           => (cpt mod 230) + 10,
         criticality        => 1,
         policy             => sched_fifo);
   end add_task_deadline_equals_period_to_system;

   procedure add_task_deadline_larger_than_period_to_system
     (s                  : in out system;
      name               : in     Unbounded_String;
      cpu_name           : in     Unbounded_String;
      address_space_name : in     Unbounded_String;
      task_type          : in     tasks_type)
   is
   begin
      add_task
        (my_tasks           => s.tasks,
         name               => name,
         cpu_name           => cpu_name,
         address_space_name => address_space_name,
         core_name          => empty_string,
         task_type          => task_type,
         start_time         => 0,
         capacity           => 1,
         period             => cpt,
         deadline           => cpt + 1,
         jitter             => 0,
         blocking_time      => 0,
         priority           => (cpt mod 230) + 10,
         criticality        => 1,
         policy             => sched_fifo);

      cpt := cpt + 1;
   end add_task_deadline_larger_than_period_to_system;

   procedure add_task_deadline_smaller_than_period_to_system
     (s                  : in out system;
      name               : in     Unbounded_String;
      cpu_name           : in     Unbounded_String;
      address_space_name : in     Unbounded_String;
      task_type          : in     tasks_type)
   is
   begin
      add_task
        (my_tasks           => s.tasks,
         name               => name,
         cpu_name           => cpu_name,
         address_space_name => address_space_name,
         core_name          => empty_string,
         task_type          => task_type,
         start_time         => 0,
         capacity           => 1,
         period             => cpt + 1,
         deadline           => cpt,
         jitter             => 0,
         blocking_time      => 0,
         priority           => (cpt mod 230) + 10,
         criticality        => 1,
         policy             => sched_fifo);
      cpt := cpt + 1;
   end add_task_deadline_smaller_than_period_to_system;

   procedure add_aperiodic_task_to_system
     (s                  : in out system;
      name               : in     Unbounded_String;
      cpu_name           : in     Unbounded_String;
      address_space_name : in     Unbounded_String)
   is
   begin
      add_task
        (my_tasks           => s.tasks,
         name               => name,
         cpu_name           => cpu_name,
         address_space_name => address_space_name,
         core_name          => empty_string,
         task_type          => aperiodic_type,
         start_time         => 0,
         capacity           => 1,
         period             => 0,
         deadline           => cpt,
         jitter             => 0,
         blocking_time      => 0,
         priority           => (cpt mod 230) + 10,
         criticality        => 1,
         policy             => sched_fifo);
   end add_aperiodic_task_to_system;

   procedure add_parametic_task_to_system
     (s                  : in out system;
      name               : in     Unbounded_String;
      cpu_name           : in     Unbounded_String;
      address_space_name : in     Unbounded_String)
   is
   begin
      add_task
        (my_tasks           => s.tasks,
         name               => name,
         cpu_name           => cpu_name,
         address_space_name => address_space_name,
         core_name          => empty_string,
         task_type          => parametric_type,
         start_time         => 0,
         capacity           => 1,
         period             => 0,
         deadline           => cpt,
         jitter             => 0,
         blocking_time      => 0,
         priority           => (cpt mod 230) + 10,
         criticality        => 1,
         policy             => sched_fifo);
   end add_parametic_task_to_system;

   procedure add_poisson_task_to_system
     (s                  : in out system;
      name               : in     Unbounded_String;
      cpu_name           : in     Unbounded_String;
      address_space_name : in     Unbounded_String)
   is
   begin
      add_task
        (my_tasks           => s.tasks,
         name               => name,
         cpu_name           => cpu_name,
         address_space_name => address_space_name,
         core_name          => empty_string,
         task_type          => poisson_type,
         start_time         => 0,
         capacity           => 1,
         period             => 0,
         deadline           => cpt,
         jitter             => 0,
         blocking_time      => 0,
         priority           => (cpt mod 230) + 10,
         criticality        => 1,
         policy             => sched_fifo);
   end add_poisson_task_to_system;

   procedure add_periodic_task_to_system
     (s                  : in out system;
      name               : in     Unbounded_String;
      cpu_name           : in     Unbounded_String;
      address_space_name : in     Unbounded_String)
   is
      i : Integer;

   begin

      i := random_integer (3);

      case i is
         when 0 =>
            add_task_deadline_smaller_than_period_to_system
              (s,
               name,
               cpu_name,
               address_space_name,
               periodic_type);
         when 1 =>
            add_task_deadline_larger_than_period_to_system
              (s,
               name,
               cpu_name,
               address_space_name,
               periodic_type);
         when others =>
            add_task_deadline_equals_period_to_system
              (s,
               name,
               cpu_name,
               address_space_name,
               periodic_type);
      end case;

   end add_periodic_task_to_system;

   procedure add_frame_task_to_system
     (s                  : in out system;
      name               : in     Unbounded_String;
      cpu_name           : in     Unbounded_String;
      address_space_name : in     Unbounded_String)
   is
      i : Integer;

   begin
      -- TODO MF logic to respect
      i := random_integer (3);

      case i is
         when 0 =>
            add_task_deadline_smaller_than_period_to_system
              (s,
               name,
               cpu_name,
               address_space_name,
               frame_task_type);
         when 1 =>
            add_task_deadline_larger_than_period_to_system
              (s,
               name,
               cpu_name,
               address_space_name,
               frame_task_type);
         when others =>
            add_task_deadline_equals_period_to_system
              (s,
               name,
               cpu_name,
               address_space_name,
               frame_task_type);
      end case;

   end add_frame_task_to_system;

   procedure add_multiple_tasks_to_system
     (s         : in out system;
      n         :        Integer;
      task_type : in     tasks_type)
   is

      i : Integer;

   begin

      i := 0;

      while (i < n) loop

         case task_type is
            when periodic_type =>
               add_periodic_task_to_system
                 (s,
                  suppress_space (To_Unbounded_String ("Task" & cpt'img)),
                  get_random_element (s.processors).name,
                  get_random_element (s.address_spaces).name);
            when aperiodic_type =>
               add_aperiodic_task_to_system
                 (s,
                  suppress_space (To_Unbounded_String ("Task" & cpt'img)),
                  get_random_element (s.processors).name,
                  get_random_element (s.address_spaces).name);
            when frame_task_type =>
               add_frame_task_to_system
                 (s,
                  suppress_space (To_Unbounded_String ("Task" & cpt'img)),
                  get_random_element (s.processors).name,
                  get_random_element (s.address_spaces).name);
            when others =>
               add_periodic_task_to_system
                 (s,
                  suppress_space (To_Unbounded_String ("Task" & cpt'img)),
                  get_random_element (s.processors).name,
                  get_random_element (s.address_spaces).name);
         end case;

         i   := i + 1;
         cpt := cpt + 1;
      end loop;

   end add_multiple_tasks_to_system;

   procedure add_multiple_frame_tasks_to_system
     (s             : in out system;
      number_frames : in     Integer;
      mf_period     : in     Integer;
      sync_ratio    : in     Double)
   is

      use generic_task_group_set;
      use Generic_Task_List_Package;

      number_groups : constant task_groups_range :=
        get_number_of_elements (s.task_groups);

      sync_number        : Integer;
      remaining_period   : Integer;
      interarrival       : Integer;
      remaining_frames   : Integer;
      group_tasks_number : Natural;
      j                  : task_groups_range;

      a_task_group    : generic_task_group_ptr;
      a_multiframe    : multiframe_task_group_ptr;
      tail_frame_task : frame_task_ptr;

      an_address_space   : address_space_ptr;
      address_space_name : Unbounded_String;
      cpu_name           : Unbounded_String;

   begin

      -- Sync_Number: The first "sync_number" multiframes have the same
      --mf_period
      sync_number := Integer (Double (number_groups) * sync_ratio);  -- TODO:
      --Round
      --up or
      --down?

      for i in 0 .. (number_groups - 1) loop
         get_element_number (s.task_groups, a_task_group, i);

         if (is_empty (a_task_group.task_list)) then
            -- First frame so a random interarrival no matter the sync_number
            interarrival := random_integer (mf_period / 2) + 1;

            -- Get random addr and cpu
            an_address_space   := get_random_element (s.address_spaces);
            address_space_name := an_address_space.name;
            cpu_name           := an_address_space.cpu_name;
         end if;

         group_tasks_number :=
           get_number_of_elements (a_task_group.task_list) + 1;

         add_task
           (my_tasks        => s.tasks,
            my_task_groups  => s.task_groups,
            task_group_name => a_task_group.name,
            name            =>
              suppress_space
                (a_task_group.name &
                 To_Unbounded_String ("_") &
                 group_tasks_number'img),
            cpu_name           => cpu_name,
            address_space_name => address_space_name,
            task_type          => frame_task_type,
            start_time         => 0,
            capacity           => random_integer (mf_period / 2) + 1,
            period             => interarrival, -- period ~ interarrival
            deadline           => 99999,
            jitter             => 0,
            blocking_time      => 0,
            priority           => 1,
            criticality        => 0,
            policy             => sched_fifo);

      end loop;

      remaining_frames := number_frames - Integer (number_groups);
      while (remaining_frames > 0) loop
         j := task_groups_range (random_integer (Integer (number_groups)));
         get_element_number (s.task_groups, a_task_group, j);

         tail_frame_task := frame_task_ptr (get_tail (a_task_group.task_list));

         -- Addr and CPU must match for all frames
         address_space_name := tail_frame_task.address_space_name;
         cpu_name           := tail_frame_task.cpu_name;

         if (Integer (j) < sync_number) then
            -- Compute allowed random value of interarrival (in interval
            --between last interarrival and mf_period)
            remaining_period := mf_period - tail_frame_task.period;

            if (remaining_period > 0) then
               interarrival := random_integer (remaining_period) + 1;
            else
               interarrival := 0;
            end if;
         else
            interarrival := random_integer (mf_period / 2) + 1;
         end if;

         group_tasks_number :=
           get_number_of_elements (a_task_group.task_list) + 1;

         add_task
           (my_tasks        => s.tasks,
            my_task_groups  => s.task_groups,
            task_group_name => a_task_group.name,
            name            =>
              suppress_space
                (a_task_group.name &
                 To_Unbounded_String ("_") &
                 group_tasks_number'img),
            cpu_name           => cpu_name,
            address_space_name => address_space_name,
            task_type          => frame_task_type,
            start_time         => 0,
            capacity           => random_integer (mf_period / 2) + 1,
            period             => interarrival, -- period ~ interarrival
            deadline           => 99999,
            jitter             => 0,
            blocking_time      => 0,
            priority           => 1,
            criticality        => 0,
            policy             => sched_fifo);

         remaining_frames := remaining_frames - 1;
      end loop;

      -- Modify synched multiframes' tail_task interarrival, so the
      --multiframe's period matches mf_period
      for i in 0 .. (sync_number - 1) loop
         j := task_groups_range (i);

         -- Get the multiframe
         get_element_number (s.task_groups, a_task_group, j);
         a_multiframe := multiframe_task_group_ptr (a_task_group);

         -- Get tail task
         tail_frame_task := frame_task_ptr (get_tail (a_task_group.task_list));

         -- Compute allowed random value of interarrival (in interval between
         --last interarrival and mf_period)
         interarrival :=
           tail_frame_task.interarrival + mf_period - tail_frame_task.period;
         set_interarrival (tail_frame_task, a_multiframe, interarrival);
      end loop;

      -- Set precedence dependencies between frames of a same multiframe group
      set_multiframe_precedences (s.task_groups, s.dependencies);

   end add_multiple_frame_tasks_to_system;

   -- 9 --------= Resources_Set =--------

   procedure add_resource_to_system
     (s                 : in out system;
      n_dependent_tasks :        Integer)
   is
      use generic_task_set;

      local_affected_tasks : resource_accesses_table;
      res                  : critical_section;
      i                    : Integer;
      item                 : resource_accesses_range;
      range_end            : resource_accesses_range;
      name1                : Unbounded_String;
      name2                : Unbounded_String;
      protocol             : resources_type;
      resource_priority    : Integer := 10;
      a_task               : generic_task_ptr;

   begin
      i        := 1;
      protocol := restrained_random_resource_type;
      a_task   := get_random_element (s.tasks);
      name1    := a_task.name;
      Initialize (res);
      loop
         name2 := get_random_element (s.tasks).name;
         exit when name1 /= name2 or get_number_of_elements (s.tasks) = 1;
      end loop;

      add (local_affected_tasks, name2, Copy (res).all);
      add (local_affected_tasks, name1, Copy (res).all);

      initialize (local_affected_tasks);
      for i in 1 .. (n_dependent_tasks - 2) loop
         -- Note: scheduler considers resource usages start at 1 instead of 0
         --in a task's execution interval,
         --       but end at task's execution interval upper bound. I.e. shift
         --+1 start but keep end.
         res.task_begin := random_integer (a_task.capacity) + 1;  -- start in
         --[1 ;
         --task.capaci
         --ty]
         res.task_end := random_integer (res.task_begin, a_task.capacity);
         -- end in [start ; task.capacity]

         add
           (local_affected_tasks,
            get_random_element (s.tasks).name,
            Copy (res).all);
      end loop;

      add_resource
        (s.resources,
         suppress_space (To_Unbounded_String ("resource_" & cpt'img)),
         0,
         0,
         1,
         get_random_element (s.processors).name,
         get_random_element (s.address_spaces).name,
         protocol,
         local_affected_tasks,
         resource_priority,
         automatic_assignment);

      range_end :=
        search_resource
          (s.resources,
           suppress_space (To_Unbounded_String ("resource_" & cpt'img)))
          .critical_sections
          .nb_entries;
      item := 0;
      loop
         add_one_task_dependency_resource
           (s.dependencies,
            search_task
              (s.tasks,
               search_resource
                 (s.resources,
                  suppress_space (To_Unbounded_String ("resource_" & cpt'img)))
                 .critical_sections
                 .entries
                 (item)
                 .item),
            search_resource
              (s.resources,
               suppress_space (To_Unbounded_String ("resource_" & cpt'img))));
         item := item + 1;

         exit when item >= range_end;
      end loop;

      if (protocol = priority_ceiling_protocol) or
        (protocol = immediate_priority_ceiling_protocol)
      then
         --Priority_Constrained_Resource_Ptr (Search_Resource
         --                                    (S.Resources,
         --                                   Suppress_Space
         --                                    (To_Unbounded_String
         --                                      ("resource_" &
         --                                     cpt'Img)))).
         --  ceiling_priority := 254;
         generic_resource_ptr
           (search_resource
              (s.resources,
               suppress_space (To_Unbounded_String ("resource_" & cpt'img))))
           .priority :=
           254;
      end if;

      cpt := cpt + 1;
   end add_resource_to_system;

   procedure add_resource_to_system
     (s                 : in out system;
      name              : in     Unbounded_String;
      n_dependent_tasks :        Integer)
   is
      local_affected_tasks : resource_accesses_table;
      res                  : critical_section;
      i                    : Integer;
      item                 : resource_accesses_range;
      range_end            : resource_accesses_range;
      name1                : Unbounded_String;
      name2                : Unbounded_String;
      resource_priority    : Integer := 10;

   begin
      i := 1;

      name1 := get_random_element (s.tasks).name;
      loop
         name2 := get_random_element (s.tasks).name;
         exit when name1 /= name2;
      end loop;
      for i in 1 .. n_dependent_tasks loop
         initialize (local_affected_tasks);
         res.task_begin := 0;
         res.task_end   := 1;
         add
           (local_affected_tasks,
            get_random_element (s.tasks).name,
            Copy (res).all);
      end loop;
      add_resource
        (s.resources,
         name,
         0,
         0,
         1,
         get_random_element (s.processors).name,
         get_random_element (s.address_spaces).name,
         restrained_random_resource_type,
         local_affected_tasks,
         resource_priority,
         automatic_assignment);

      range_end :=
        search_resource
          (s.resources,
           suppress_space (To_Unbounded_String ("resource_" & cpt'img)))
          .critical_sections
          .nb_entries;
      item := 0;
      loop
         add_one_task_dependency_resource
           (s.dependencies,
            search_task
              (s.tasks,
               search_resource
                 (s.resources,
                  suppress_space (To_Unbounded_String ("resource_" & cpt'img)))
                 .critical_sections
                 .entries
                 (item)
                 .item),
            search_resource
              (s.resources,
               suppress_space (To_Unbounded_String ("resource_" & cpt'img))));
         item := item + 1;
         exit when item >= range_end;
      end loop;

      cpt := cpt + 1;
   end add_resource_to_system;

   procedure add_multiple_resources_to_system
     (s : in out system;
      n :        Integer)
   is
   begin
      null;
   end add_multiple_resources_to_system;

   procedure add_resource_set_to_system
     (s                       : in out system;
      n_resources             : in     Integer;
      resource_sharing_factor : in     Float;
      critical_section_ratio  : in     Float := 0.0)

   is

      n_tasks : tasks_range :=
        get_number_of_task_from_processor
          (s.tasks,
           To_Unbounded_String ("processor1"));
      max_accessed_tasks : Integer :=
        Integer (Float'ceiling (Float (n_tasks) * resource_sharing_factor));
      max_all_sc : Integer := max_accessed_tasks * n_resources;
      type array_of_integer is array (1 .. 1500) of Integer;
      --type array_of_integer is array (1 .. Max_all_sc) of integer;
      affected_tasks_tab : array_of_integer;
      -- Resource_tab is an array where each element represents the number of
      -- of critical sections per resource
      resource_tab                   : array (1 .. n_resources) of Integer;
      k, h                           : Integer;
      n_critical_sections            : Integer;
      a_task_index, n_accessed_tasks : Integer;
      is_used                        : Boolean;
      critical_sections_tab          : array (1 .. 1500) of critical_section;
      --Critical_sections_tab              : array (1 .. Max_all_sc) of critical_section;
      length_a_cs                  : Integer;
      cs                           : critical_section;
      critical_section_ratio_final : Float;
      task_capacity                : Natural;
      a_resource_set               : resources_set;
      rt                           : resource_accesses_table;
      n_cs_of_a_resource           : Integer;
      a_task_name                  : Unbounded_String;
      rnd                          : Integer;
      function find_an_element
        (an_array    : in array_of_integer;
         element     : in Integer;
         start_index : in Integer;
         last_index  : in Integer) return Boolean
      is
         is_found : Boolean := False;
         k        : Integer;
      begin

         k := start_index;
         while (not is_found) and (k <= last_index) loop
            if an_array (k) = element then
               is_found := True;
            end if;
            k := k + 1;
         end loop;

         return is_found;

      end find_an_element;

   begin

      -- 2) Each resource Rj is accessed by a number of different functions
      --    randomly chosen from the set of functions.
      --    This number is randomly chosen in the range [2 , Resource_sharing_factor * N_tasks]
      --
      k                         := 0;
      affected_tasks_tab (1500) := 0;
      for i in 1 .. n_resources loop
         if max_accessed_tasks > 2 then
            n_accessed_tasks := random_integer (2, max_accessed_tasks);
         else
            n_accessed_tasks := 2;
         end if;
         h                := k + 1;
         resource_tab (i) := n_accessed_tasks;
         for j in 1 .. n_accessed_tasks loop
            is_used := True;
            while is_used loop
               a_task_index := random_integer (1, Integer (n_tasks));
               is_used      :=
                 find_an_element (affected_tasks_tab, a_task_index, h, k);
            end loop;
            k                      := k + 1;
            affected_tasks_tab (k) := a_task_index;
         end loop;
      end loop;

      n_critical_sections := k;

      -- 3) Each Task Task_i that accesses a given resource Rj,
      --    issues only a single request of Rj per a job
      --    with a critical section Length:
      --       • The length of each critical section CS executed by a Task Task_j , is set as follows:
      --              Length(CS) = Integer(Float'Ceiling(critical_section_ratio * float(capacity(Task_j)))
      --          If the critical section ratio = 0.0 then
      --                it will be chosen randomly from the set {0.1, 0.3, 0.5}
      --            else (i.e the critical section ratio is given by user)
      --                we use the given value
      --
      --       • CS.task_begin : randomly generated in the range [1, capacity(Task_j) – Length(CS) + 1 ]
      --       • CS.task_end = CS.task_begin + Length(CS) – 1
      --
      for i in 1 .. n_critical_sections loop

         if critical_section_ratio = 0.0 then
            -- The critical section ratio is chosen
            -- randomly from the set {0.1, 0.3, 0.5}
            rnd := random_integer (1, 3);
            if rnd = 1 then
               critical_section_ratio_final := 0.1;
            elsif rnd = 2 then
               critical_section_ratio_final := 0.3;
            else
               critical_section_ratio_final := 0.5;
            end if;

         else
            critical_section_ratio_final := critical_section_ratio;
         end if;

         task_capacity :=
           get
             (my_tasks  => s.tasks,
              task_name =>
                suppress_space
                  (To_Unbounded_String
                     ("Task" & Integer'image (affected_tasks_tab (i)))),
              param_name => capacity);

         length_a_cs :=
           Integer
             (Float'ceiling
                (critical_section_ratio_final * Float (task_capacity)));
	 Initialize (cs);
         cs.task_begin :=
           Natural (random_integer (1, task_capacity - length_a_cs + 1));
         cs.task_end := cs.task_begin + Natural (length_a_cs) - 1;
         critical_sections_tab (i) := cs;
      end loop;

      -- Assign to each resource its critical sections
      --
      for i in 1 .. n_resources loop

         n_cs_of_a_resource := resource_tab (i);

         initialize (rt);

         k := 0;
         for l in 1 .. i - 1 loop
            k := k + resource_tab (l);
         end loop;
         k := k + 1;

         for j in 1 .. n_cs_of_a_resource loop

            a_task_name :=
              suppress_space
                (To_Unbounded_String
                   ("Task" & Integer'image (affected_tasks_tab (k))));
            cs := critical_sections_tab (k);
            -- Add the computed critical_section_j to the table of
            -- critical sections of the Resource_i
            --
            add (rt, a_task_name, cs);
            k := k + 1;
         end loop;

         -- Add the resource Ri to the set of resources
         --
         add_resource
           (a_resource_set,
            suppress_space (To_Unbounded_String ("R" & i'img)),
            1,
            0,
            0,
            To_Unbounded_String ("processor1"),
            To_Unbounded_String ("addr1"),
            priority_ceiling_protocol,
            rt,
            0,
            automatic_assignment);
      end loop;

      -- Assign the resource set to the system
      --
      s.resources := a_resource_set;

   end add_resource_set_to_system;

   -- 3 --------= Messages_Set =--------

   procedure add_message_to_system (s : in out system) is
   begin

      add_message
        (s.messages,
         suppress_space (To_Unbounded_String ("message" & cpt'img)),
         1,
         0,
         0,
         0,
         no_user_defined_parameter,
         0,
         0);
      cpt := cpt + 1;
   end add_message_to_system;

   procedure add_message_to_system
     (s    : in out system;
      name : in     Unbounded_String)
   is
   begin

      add_message
        (s.messages,
         name,
         1,
         0,
         0,
         0,
         no_user_defined_parameter,
         0,
         0);
      cpt := cpt + 1;
   end add_message_to_system;

   procedure add_multiple_messages_to_system
     (s : in out system;
      n :        Integer)
   is
      i : Integer;

   begin

      i := 0;

      while (i < n) loop
         add_message_to_system (s);
         i := i + 1;
      end loop;
   end add_multiple_messages_to_system;

   -- 10 --------= Dependecies =--------

   procedure add_time_triggered_communication_dependency_to_system
     (s : in out system)
   is
      src, dest : generic_task_ptr;

   begin
      -- SR Src and Dest Tasks must be different
      src := get_random_element (s.tasks);
      loop
         dest := get_random_element (s.tasks);
         exit when src /= dest;
      end loop;

      add_one_task_dependency_time_triggered
        (s.dependencies,
         src,
         dest,
         sampled_timing);
   end add_time_triggered_communication_dependency_to_system;

   procedure add_dependency_to_system
     (s    : in out system;
      name : in     Unbounded_String)
   is
   begin
      null;
   end add_dependency_to_system;

   procedure add_multiple_dependencies_to_system
     (s : in out system;
      n :        Integer)
   is
   begin
      null;
   end add_multiple_dependencies_to_system;

   procedure add_multiple_mf_precedence_dependencies_to_system
     (s                  : in out system;
      number_precedences : in     Integer;
      number_groups      : in     Integer;
      sync_ratio         : in     Double)
   is

      use generic_task_group_set;
      use Generic_Task_List_Package;

      a, b, i, sync_number, max_precs : Integer;
      task_group_a, task_group_b      : generic_task_group_ptr;
      task_a, task_b                  : generic_task_ptr;

   begin
      -- Sync_Number: The first "sync_number" multiframes have the same
      --mf_period
      sync_number := Integer (Double (number_groups) * sync_ratio);  -- TODO:
      --Round
      --up or
      --down?*

      -- Only on group is synched
      if (sync_number <= 1 or number_groups = 1) then
         return;
      end if;

      max_precs :=
        get_no_deadlocks_precedences_number (s.task_groups, sync_number);

      i := 0;
      while (i < number_precedences and i < max_precs) loop
         loop
            loop
               a := random_integer (sync_number);
               b := random_integer (sync_number);
               --             a := Random_Integer(sync_number - 1);
               --             b := Random_Integer(a, sync_number);

               get_element_number
                 (s.task_groups,
                  task_group_a,
                  task_groups_range (a));
               get_element_number
                 (s.task_groups,
                  task_group_b,
                  task_groups_range (b));

               exit when (task_group_a.name /= task_group_b.name);
            end loop;

            task_a := get_random_element (task_group_a.task_list);
            task_b := get_random_element (task_group_b.task_list);

            exit when
              (is_unique_precedence_dependency
                 (s.dependencies,
                  task_a,
                  task_b) and
               no_precedence_dependency_deadlock
                 (s.dependencies,
                  task_a,
                  task_b));
         end loop;

         add_one_task_dependency_precedence
           (s.dependencies,
            search_task (s.tasks, task_a.name),
            search_task (s.tasks, task_b.name));

         i := i + 1;
      end loop;

   end add_multiple_mf_precedence_dependencies_to_system;

   -- 11 --------= Task_Groups_Set =--------

   procedure add_task_group_to_system
     (s               : in out system;
      task_group_type : in     task_groups_type)
   is

   begin

      add_task_group_to_system
        (s,
         suppress_space (To_Unbounded_String ("TaskGroup" & cpt'img)),
         task_group_type);

      cpt := cpt + 1;

   end add_task_group_to_system;

   procedure add_task_group_to_system
     (s               : in out system;
      name            : in     Unbounded_String;
      task_group_type : in     task_groups_type)
   is

   begin

      add_task_group (s.task_groups, name, task_group_type);

   end add_task_group_to_system;

   procedure add_multiple_task_groups_to_system
     (s               : in out system;
      n               :        Integer;
      task_group_type : in     task_groups_type)
   is

      i : Integer;

   begin

      i := 0;

      while (i < n) loop

         case task_group_type is
            when multiframe_type =>
               add_task_group_to_system (s, multiframe_type);
            when transaction_type =>
               add_task_group_to_system (s, transaction_type);
            when others =>
               null;
         end case;

         i := i + 1;
      end loop;

   end add_multiple_task_groups_to_system;

   -- 1 --------= Core_Units_Set =--------

   procedure add_core_unit_to_system (s : in out system) is
      mem : memories_table;
   begin

      add_core_unit
        (s.core_units,
         suppress_space (To_Unbounded_String ("core_unit" & cpt'img)),
         preemptive,
         0,
         0,
         0,
         0,
         0,
         empty_string,
         empty_string,
         earliest_deadline_first_protocol,
         mem);
      cpt := cpt + 1;

   end add_core_unit_to_system;

   procedure add_core_unit_to_system
     (s     : in out system;
      sched : in     schedulers_type)
   is
      mem : memories_table;
   begin

      add_core_unit
        (s.core_units,
         suppress_space (To_Unbounded_String ("core_unit" & cpt'img)),
         preemptive,
         0,
         1,
         0,
         0,
         0,
         empty_string,
         empty_string,
         sched,
         mem);
      cpt := cpt + 1;

   end add_core_unit_to_system;

   procedure add_core_unit_to_system
     (s    : in out system;
      name : in     Unbounded_String)
   is
      mem : memories_table;
   begin
      add_core_unit
        (s.core_units,
         name,
         preemptive,
         0,
         0,
         0,
         0,
         0,
         empty_string,
         empty_string,
         earliest_deadline_first_protocol,
         mem);
      cpt := cpt + 1;
   end add_core_unit_to_system;

   procedure add_core_unit_to_system
     (s                       : in out system;
      a_multi_cores_processor : in     multi_cores_processor_ptr;
      sched                   : in     schedulers_type;
      preempt                 : in     preemptives_type)
   is

      a_core_unit    : core_unit_ptr;
      name_core_unit : Unbounded_String;
      mem            : memories_table;

   begin

      name_core_unit :=
        suppress_space (To_Unbounded_String ("core_unit" & cpt'img));
      add_core_unit
        (s.core_units,
         a_core_unit,
         name_core_unit,
         preempt,
         0,
         1,
         0,
         0,
         0,
         empty_string,
         empty_string,
         sched,
         mem);

      --        Put_Line ("after adding core unit to system");
      --        Put (Sched'Img);

      add
        (a_multi_cores_processor.all.cores,
         search_core_unit (s.core_units, name_core_unit));
      --        Put(Search_core_unit (S.Core_units, name_core_unit));
      --        Put_Line ("after adding core unit to processor");
      cpt := cpt + 1;

   end add_core_unit_to_system;

   -- 2 --------= Processors_Set =--------
   -- SR to obtain the id fo the new CPU
--procedure Add_Mono_Core_Processor_To_System
--  (S            : in out System;
--  Id_Cpu       : in out Unbounded_String;
-- Preemptivity : in Preemptives_Type;
--   Sched        : in Schedulers_Type)
-- is
--     Id_Cpt   : Integer;
--   begin
--      Id_Cpt := Cpt + 1;
--      Id_Cpu := suppress_space (To_Unbounded_String ("cpu" & Id_Cpt'Img)) ;
--      Add_Mono_Core_Processor_To_System (S, Preemptivity,  Sched );
--   end Add_Mono_Core_Processor_To_System;

   procedure add_mono_core_processor_to_system
     (s            : in out system;
      preemptivity : in     preemptives_type;
      sched        : in     schedulers_type)
   is
      obj            : mono_core_processor_ptr;
      a_core_unit    : core_unit_ptr;
      name_core_unit : Unbounded_String;
      mem            : memories_table;
   begin

      name_core_unit :=
        suppress_space (To_Unbounded_String ("core_unit" & cpt'img));
      add_core_unit
        (s.core_units,
         a_core_unit,
         name_core_unit,
         preemptivity,
         0,
         0,
         0,
         0,
         0,
         empty_string,
         empty_string,
         sched,
         mem);

      --        Put_Line ("after adding core unit to system");
      --        Put (Sched'Img);
      obj          := new mono_core_processor;
      obj.all.core := search_core_unit (s.core_units, name_core_unit);
      --        Put(Search_core_unit (S.Core_units, name_core_unit));
      --        Put_Line ("after adding core unit to processor");
      cpt := cpt + 1;
      add_processor
        (s.processors,
         suppress_space (To_Unbounded_String ("cpu" & cpt'img)),
         a_core_unit);
      cpt := cpt + 1;
   end add_mono_core_processor_to_system;

   procedure add_mono_core_processor_to_system
     (s            : in out system;
      preemptivity : in     preemptives_type;
      sched        : in     schedulers_type;
      core         :        core_unit_ptr)
   is
      obj : mono_core_processor_ptr;
   -- SR obj2 : Core_Unit_Ptr;
   begin

      obj := new mono_core_processor;
      -- SR Core parameter seems to be unused... remove Add_Core
      -- obj.all.core := Core;
      -- cpt          := cpt + 1;
      --Add_core_unit
      --  (S.Core_units,
      --   obj2,
      --   suppress_space (To_Unbounded_String ("core" & cpt'Img)),
      --   Preemptivity,
      --   0,
      --   0.0,
      --   1,
      --   1,
      --   0,
      --   empty_string,
      --   Sched,
      --   empty_string);
      add_processor
        (s.processors,
         generic_processor_ptr (obj),
         suppress_space (To_Unbounded_String ("core" & cpt'img)),
         core);                         -- SR previously obj2;
      cpt := cpt + 1;
   end add_mono_core_processor_to_system;

   procedure add_mono_core_processor_to_system
     (s            : in out system;
      name         : in     Unbounded_String;
      preemptivity : in     preemptives_type;
      sched        : in     schedulers_type)
   is
      obj : mono_core_processor_ptr;
      mem : memories_table;
   begin

      add_core_unit
        (s.core_units,
         suppress_space (To_Unbounded_String ("core_unit" & cpt'img)),
         preemptive,
         0,
         0,
         0,
         0,
         0,
         empty_string,
         empty_string,
         sched,
         mem);

      -- SR    cpt := cpt + 1;
      add_processor
        (s.processors,
         generic_processor_ptr (obj),
         name,
         search_core_unit
           (s.core_units,
            suppress_space (To_Unbounded_String ("core_unit" & cpt'img))));

   end add_mono_core_processor_to_system;

   procedure add_multiple_mono_core_processors_to_system
     (s : in out system;
      n :        Integer)
   is

      i : Integer;

   begin

      i := 0;

      while (i < n) loop
         add_mono_core_processor_to_system
           (s,
            To_Unbounded_String ("cpu" & i'img),
            random_preemptivity,
            random_scheduler);
         i := i + 1;
      end loop;

   end add_multiple_mono_core_processors_to_system;

   procedure add_multi_cores_processor_to_system
     (s                 : in out system;
      number_core_units : in     Integer;
      preemptivity      : in     preemptives_type;
      sched             : in     schedulers_type)
   is

      a_core_unit        : core_unit_ptr;
      name_core_unit     : Unbounded_String;
      a_core_units_table : core_units_table;
      i                  : Integer;
      mem                : memories_table;

   begin

      if (number_core_units > 1) then
         i := 0;
         while (i < number_core_units) loop
            name_core_unit :=
              suppress_space (To_Unbounded_String ("core_unit_" & cpt'img));

            add_core_unit
              (s.core_units,
               a_core_unit,
               name_core_unit,
               preemptivity,
               0,
               1,
               0,
               0,
               0,
               empty_string,
               empty_string,
               sched,
               mem);

            add (a_core_units_table, a_core_unit);

            cpt := cpt + 1;
            i   := i + 1;
         end loop;
      end if;

      add_processor
        (s.processors,
         To_Unbounded_String ("cpu" & cpt'img),
         a_core_units_table);

      cpt := cpt + 1;

   end add_multi_cores_processor_to_system;

   procedure add_multiple_processors_to_system
     (s                               : in out system;
      number_processors               : in     Integer;
      number_core_units_per_processor : in     Integer;
      sched                           : in     schedulers_type;
      preempt                         : in     preemptives_type)
   is

      i : Integer;

   begin

      if (number_core_units_per_processor = 1) then -- Only monocores
         i := 0;
         while (i < number_processors) loop
            add_mono_core_processor_to_system (s, preempt, sched);
            i := i + 1;
         end loop;
      else
         i := 0;
         while (i < number_processors) loop
            add_multi_cores_processor_to_system
              (s,
               number_core_units_per_processor,
               preempt,
               sched);
            i := i + 1;
         end loop;
      end if;

   end add_multiple_processors_to_system;

   -- 7 --------= Buffers_Set =--------

   procedure add_buffer_to_system (s : in out system) is
      addr_name : Unbounded_String;
   begin
      addr_name := get_random_element (s.address_spaces).name;
      add_buffer_to_system
        (s,
         search_address_space (s.address_spaces, addr_name).cpu_name,
         addr_name);

   end add_buffer_to_system;

   procedure add_buffer_to_system
     (s                  : in out system;
      cpu_name           : in     Unbounded_String;
      address_space_name : in     Unbounded_String)
   is
      roles : buffer_roles_table;
   begin
      initialize (roles);
      add_buffer
        (s.buffers,
         suppress_space (To_Unbounded_String ("buffer" & cpt'img)),
         5,
         cpu_name,
         address_space_name,
         qs_pp1,
         roles);
      cpt := cpt + 1;
   end add_buffer_to_system;

   procedure add_buffer_to_system
     (s                  : in out system;
      name               : in     Unbounded_String;
      cpu_name           : in     Unbounded_String;
      address_space_name : in     Unbounded_String)
   is
      roles : buffer_roles_table;
   begin
      initialize (roles);
      add_buffer
        (s.buffers,
         name,
         1,
         cpu_name,
         address_space_name,
         qs_pp1,
         roles);
      cpt := cpt + 1;
   end add_buffer_to_system;

   procedure add_multiple_buffers_to_system (s : in out system; n : Integer) is
      i : Integer;

   begin

      i := 0;

      while (i < n) loop
         add_buffer_to_system (s);
         i := i + 1;
      end loop;
   end add_multiple_buffers_to_system;

   -- 4 --------= Networks_Set =--------

   -- 5 --------= Event_Analyzers_Set =--------

   -- 6 --------= Address_Spaces_Set =--------

   procedure add_address_space_to_system
     (s        : in out system;
      cpu_name :        Unbounded_String)
   is
   begin
      add_address_space
        (s.address_spaces,
         suppress_space (To_Unbounded_String ("addr" & cpt'img)),
         cpu_name,
         0,
         0,
         0,
         0);
      cpt := cpt + 1;
   end add_address_space_to_system;

   procedure add_address_space_to_system
     (s        : in out system;
      name     : in     Unbounded_String;
      cpu_name :        Unbounded_String)
   is
   begin
      add_address_space (s.address_spaces, name, cpu_name, 0, 0, 0, 0);
      cpt := cpt + 1;
   end add_address_space_to_system;

   procedure add_multiple_address_spaces_to_system
     (s : in out system;
      n :        Integer)
   is

      i : Integer;

   begin

      i := 0;

      while (i < n) loop
         add_address_space_to_system
           (s,
            get_random_element (s.processors).name);
         i := i + 1;
      end loop;
   end add_multiple_address_spaces_to_system;

   procedure add_multiple_address_spaces_consistently_to_system
     (s                     : in out system;
      number_processors     : in     Integer;
      number_address_spaces : in     Integer)
   is

      processor_iterator : processors_iterator;
      a_processor        : generic_processor_ptr;

      address_spaces_left : Integer;

   begin

      -- Add at least an ADDR to each CPU
      reset_iterator (s.processors, processor_iterator);
      loop
         current_element (s.processors, a_processor, processor_iterator);
         add_address_space_to_system (s, a_processor.name);
         exit when is_last_element (s.processors, processor_iterator);
         next_element (s.processors, processor_iterator);
      end loop;

      -- Fill remaining ADDRs randomly if there are more ADDRs than CPUs
      address_spaces_left := number_address_spaces - number_processors;
      while (address_spaces_left > 0) loop
         add_address_space_to_system
           (s,
            get_random_element (s.processors).name);
         address_spaces_left := address_spaces_left - 1;
      end loop;

   end add_multiple_address_spaces_consistently_to_system;

   -- X --------= Random Functionnalities =--------

   function random_preemptivity return preemptives_type is
      type preempt_range is range 0 .. 1;
      package rand is new Ada.Numerics.Discrete_Random (preempt_range);
      use rand;
      p : preempt_range;
      g : generator;
   begin
      Reset (g);
      p := Random (g);
      case p is
         when preempt_range (0) =>
            return preemptive;
         when others =>
            return not_preemptive;
      end case;
   end random_preemptivity;

   function random_scheduler return schedulers_type is
      type sched_range is range 0 .. 22;
      package rand is new Ada.Numerics.Discrete_Random (sched_range);
      use rand;
      p : sched_range;
      g : generator;
   begin
      Reset (g);
      p := Random (g);
      case p is
         when sched_range (0) =>
            return compiled_user_defined_protocol;
         when sched_range (1) =>
            return automata_user_defined_protocol;
         when sched_range (2) =>
            return pipeline_user_defined_protocol;
         when sched_range (3) =>
            return user_defined_protocol;
         when sched_range (4) =>
            return earliest_deadline_first_protocol;
         when sched_range (5) =>
            return least_laxity_first_protocol;
         when sched_range (6) =>
            return rate_monotonic_protocol;
         when sched_range (7) =>
            return deadline_monotonic_protocol;
         when sched_range (8) =>
            return round_robin_protocol;
         when sched_range (9) =>
            return time_sharing_based_on_wait_time_protocol;
         when sched_range (10) =>
            return posix_1003_highest_priority_first_protocol;
         when sched_range (11) =>
            return d_over_protocol;
         when sched_range (12) =>
            return maximum_urgency_first_based_on_laxity_protocol;
         when sched_range (13) =>
            return maximum_urgency_first_based_on_deadline_protocol;
         when sched_range (14) =>
            return time_sharing_based_on_cpu_usage_protocol;
         when sched_range (15) =>
            return no_scheduling_protocol;
         when sched_range (16) =>
            return hierarchical_cyclic_protocol;
         when sched_range (17) =>
            return hierarchical_round_robin_protocol;
         when sched_range (18) =>
            return hierarchical_fixed_priority_protocol;
         when sched_range (19) =>
            return hierarchical_polling_aperiodic_server_protocol;
         when sched_range (20) =>
            return hierarchical_priority_exchange_aperiodic_server_protocol;
         when sched_range (21) =>
            return hierarchical_sporadic_aperiodic_server_protocol;
         when others =>
            return hierarchical_deferrable_aperiodic_server_protocol;
      end case;
   end random_scheduler;

   function restrained_random_scheduler return schedulers_type is
      type sched_range is range 0 .. 3;
      package rand is new Ada.Numerics.Discrete_Random (sched_range);
      use rand;
      p : sched_range;
      g : generator;
   begin
      Reset (g);
      p := Random (g);
      case p is
         when sched_range (0) =>
            return earliest_deadline_first_protocol;
         when sched_range (1) =>
            return rate_monotonic_protocol;
         when sched_range (2) =>
            return deadline_monotonic_protocol;
         when others =>
            return posix_1003_highest_priority_first_protocol;
      end case;
   end restrained_random_scheduler;

   function random_dependency_type return dependency_type is
      type depend_range is range 0 .. 4;
      package rand is new Ada.Numerics.Discrete_Random (depend_range);
      use rand;
      p : depend_range;
      g : generator;
   begin
      Reset (g);
      p := Random (g);
      case p is
         when depend_range (0) =>
            return precedence_dependency;
         when depend_range (1) =>
            return queueing_buffer_dependency;
         when depend_range (2) =>
            return asynchronous_communication_dependency;
         when depend_range (3) =>
            return time_triggered_communication_dependency;
         when others =>
            return resource_dependency;
      end case;
   end random_dependency_type;

   function random_resource_type return resources_type is
      type resource_range is range 0 .. 3;
      package rand is new Ada.Numerics.Discrete_Random (resource_range);
      use rand;
      p : resource_range;
      g : generator;
   begin
      Reset (g);
      p := Random (g);
      case p is
         when resource_range (0) =>
            return no_protocol;
         when resource_range (1) =>
            return priority_ceiling_protocol;
         when resource_range (2) =>
            return priority_inheritance_protocol;
         when others =>
            return immediate_priority_ceiling_protocol;
      end case;
   end random_resource_type;

   function restrained_random_resource_type return resources_type is
      use rand_res;
      p : resource_range;
      g : generator;
   begin
      Reset (g_res);
      p := Random (g_res);
      case p is
         when resource_range (0) =>
            return priority_ceiling_protocol;
         when resource_range (1) =>
            return priority_inheritance_protocol;
         when others =>
            return immediate_priority_ceiling_protocol;
      end case;
   end restrained_random_resource_type;

   function random_task_type return tasks_type is
      type task_range is range 0 .. 4;
      package rand is new Ada.Numerics.Discrete_Random (task_range);
      use rand;
      p : task_range;
      g : generator;
   begin
      Reset (g);
      p := Random (g);
      case p is
         when task_range (0) =>
            return periodic_type;
         when task_range (1) =>
            return aperiodic_type;
         when task_range (2) =>
            return sporadic_type;
         when task_range (3) =>
            return poisson_type;
         when others =>
            return parametric_type;
      end case;
   end random_task_type;

   function random_integer (n : Integer) return Integer is
      use rand_int;
      p : int_range;
   begin
      p := Random (g_int);
      return Integer (p) mod n;
   end random_integer;

   function random_integer (n1 : Integer; n2 : Integer) return Integer is
      use rand_int;
      n : Integer;
      p : int_range;
   begin
      if (n1 = n2) then
         return n1;
      end if;

      p := Random (g_int);

      if (n1 > n2) then
         n := n1 - n2;
         return (Integer (p) mod n) + n2;
      end if;

      n := n2 - n1;

      return (Integer (p) mod n) + n1;
   end random_integer;

   procedure compliant_time_triggered_communication (sys : out system) is
      a_core            : core_unit_ptr;
      a_core_unit_table : core_units_table;
      mem               : memories_table;

   begin

      initialize (sys);
      add_core_unit
        (sys.core_units,
         a_core,
         To_Unbounded_String ("core1"),
         preemptive,
         0,
         1,
         101,
         102,
         103,
         To_Unbounded_String (""),
         To_Unbounded_String (""),
         rate_monotonic_protocol,
         mem);
      add (a_core_unit_table, a_core);

      add_processor
        (sys.processors,
         To_Unbounded_String ("processor1"),
         a_core_unit_table);

      add_address_space
        (sys.address_spaces,
         To_Unbounded_String ("addr1"),
         To_Unbounded_String ("processor1"),
         0,
         0,
         0,
         0);

      add_task
        (sys.tasks,
         To_Unbounded_String ("T1"),
         To_Unbounded_String ("processor1"),
         To_Unbounded_String ("addr1"),
         To_Unbounded_String (""),
         periodic_type,
         0,
         2,
         4,
         4,
         0,
         10,
         1,
         0,
         sched_fifo);
      add_task
        (sys.tasks,
         To_Unbounded_String ("T2"),
         To_Unbounded_String ("processor1"),
         To_Unbounded_String ("addr1"),
         To_Unbounded_String (""),
         periodic_type,
         0,
         3,
         5,
         5,
         0,
         10,
         2,
         0,
         sched_fifo);
      add_task
        (sys.tasks,
         To_Unbounded_String ("T3"),
         To_Unbounded_String ("processor1"),
         To_Unbounded_String ("addr1"),
         To_Unbounded_String (""),
         periodic_type,
         0,
         7,
         20,
         20,
         0,
         10,
         3,
         0,
         sched_fifo);

      add_one_task_dependency_time_triggered
        (sys.dependencies,
         search_task (sys.tasks, To_Unbounded_String ("T1")),
         search_task (sys.tasks, To_Unbounded_String ("T2")),
         sampled_timing);
      add_one_task_dependency_time_triggered
        (sys.dependencies,
         search_task (sys.tasks, To_Unbounded_String ("T2")),
         search_task (sys.tasks, To_Unbounded_String ("T3")),
         sampled_timing);

   end compliant_time_triggered_communication;

   procedure uncompliant_time_triggered_communication (sys : out system) is
      a_core            : core_unit_ptr;
      a_core_unit_table : core_units_table;
      mem               : memories_table;
   begin

      initialize (sys);
      add_core_unit
        (sys.core_units,
         a_core,
         To_Unbounded_String ("core1"),
         preemptive,
         0,
         1,
         101,
         102,
         103,
         To_Unbounded_String (""),
         To_Unbounded_String (""),
         rate_monotonic_protocol,
         mem);
      add (a_core_unit_table, a_core);

      add_processor
        (sys.processors,
         To_Unbounded_String ("processor1"),
         a_core_unit_table);

      add_address_space
        (sys.address_spaces,
         To_Unbounded_String ("addr1"),
         To_Unbounded_String ("processor1"),
         0,
         0,
         0,
         0);

      add_task
        (sys.tasks,
         To_Unbounded_String ("T1"),
         To_Unbounded_String ("processor1"),
         To_Unbounded_String ("addr1"),
         To_Unbounded_String (""),
         sporadic_type,
         0,
         2,
         4,
         4,
         0,
         10,
         1,
         0,
         sched_fifo);
      add_task
        (sys.tasks,
         To_Unbounded_String ("T2"),
         To_Unbounded_String ("processor1"),
         To_Unbounded_String ("addr1"),
         To_Unbounded_String (""),
         periodic_type,
         0,
         3,
         5,
         5,
         0,
         10,
         2,
         0,
         sched_fifo);
      add_task
        (sys.tasks,
         To_Unbounded_String ("T3"),
         To_Unbounded_String ("processor1"),
         To_Unbounded_String ("addr1"),
         To_Unbounded_String (""),
         periodic_type,
         0,
         7,
         20,
         20,
         0,
         10,
         3,
         0,
         sched_fifo);

      add_one_task_dependency_time_triggered
        (sys.dependencies,
         search_task (sys.tasks, To_Unbounded_String ("T1")),
         search_task (sys.tasks, To_Unbounded_String ("T2")),
         sampled_timing);
      add_one_task_dependency_time_triggered
        (sys.dependencies,
         search_task (sys.tasks, To_Unbounded_String ("T2")),
         search_task (sys.tasks, To_Unbounded_String ("T3")),
         sampled_timing);
   end uncompliant_time_triggered_communication;

   procedure compliant_unplugged (sys : out system) is
      a_core            : core_unit_ptr;
      a_core_unit_table : core_units_table;
      mem               : memories_table;

   begin

      initialize (sys);
      add_core_unit
        (sys.core_units,
         a_core,
         To_Unbounded_String ("core1"),
         preemptive,
         0,
         1,
         101,
         102,
         103,
         To_Unbounded_String (""),
         To_Unbounded_String (""),
         earliest_deadline_first_protocol,
         mem);
      add (a_core_unit_table, a_core);

      add_processor
        (sys.processors,
         To_Unbounded_String ("processor1"),
         a_core_unit_table);

      add_address_space
        (sys.address_spaces,
         To_Unbounded_String ("addr1"),
         To_Unbounded_String ("processor1"),
         0,
         0,
         0,
         0);

      add_task
        (sys.tasks,
         To_Unbounded_String ("T1"),
         To_Unbounded_String ("processor1"),
         To_Unbounded_String ("addr1"),
         To_Unbounded_String (""),
         periodic_type,
         0,
         2,
         4,
         4,
         0,
         10,
         1,
         0,
         sched_fifo);
      add_task
        (sys.tasks,
         To_Unbounded_String ("T2"),
         To_Unbounded_String ("processor1"),
         To_Unbounded_String ("addr1"),
         To_Unbounded_String (""),
         periodic_type,
         0,
         3,
         5,
         5,
         0,
         10,
         2,
         0,
         sched_fifo);
      add_task
        (sys.tasks,
         To_Unbounded_String ("T3"),
         To_Unbounded_String ("processor1"),
         To_Unbounded_String ("addr1"),
         To_Unbounded_String (""),
         periodic_type,
         0,
         7,
         20,
         20,
         0,
         10,
         3,
         0,
         sched_fifo);

   end compliant_unplugged;

   procedure uncompliant_unplugged (sys : out system) is
      a_core            : core_unit_ptr;
      a_core_unit_table : core_units_table;
      mem               : memories_table;

   begin

      initialize (sys);
      add_core_unit
        (sys.core_units,
         a_core,
         To_Unbounded_String ("core1"),
         preemptive,
         0,
         1,
         101,
         102,
         103,
         To_Unbounded_String (""),
         To_Unbounded_String (""),
         earliest_deadline_first_protocol,
         mem);
      add (a_core_unit_table, a_core);

      add_processor
        (sys.processors,
         To_Unbounded_String ("processor1"),
         a_core);

      add_address_space
        (sys.address_spaces,
         To_Unbounded_String ("addr1"),
         To_Unbounded_String ("processor1"),
         0,
         0,
         0,
         0);

      add_task
        (sys.tasks,
         To_Unbounded_String ("T1"),
         To_Unbounded_String ("processor1"),
         To_Unbounded_String ("addr1"),
         To_Unbounded_String (""),
         periodic_type,
         0,
         2,
         4,
         4,
         0,
         10,
         1,
         0,
         sched_fifo);
      add_task
        (sys.tasks,
         To_Unbounded_String ("T2"),
         To_Unbounded_String ("processor1"),
         To_Unbounded_String ("addr1"),
         To_Unbounded_String (""),
         periodic_type,
         0,
         3,
         5,
         5,
         0,
         10,
         2,
         0,
         sched_fifo);
      add_task
        (sys.tasks,
         To_Unbounded_String ("T3"),
         To_Unbounded_String ("processor1"),
         To_Unbounded_String ("addr1"),
         To_Unbounded_String (""),
         periodic_type,
         0,
         7,
         20,
         20,
         0,
         10,
         3,
         0,
         sched_fifo);
      add_task
        (sys.tasks,
         To_Unbounded_String ("A"),
         To_Unbounded_String ("processor1"),
         To_Unbounded_String ("addr1"),
         To_Unbounded_String (""),
         aperiodic_type,
         4,
         3,
         0,
         20,
         0,
         0,
         3,
         0,
         sched_fifo);

   end uncompliant_unplugged;

   procedure compliant_ravenscar (sys : out system) is
      a_core            : core_unit_ptr;
      a_core_unit_table : core_units_table;
      rt                : resource_accesses_table;
      r                 : critical_section;
      item              : resource_accesses_range;
      range_end         : resource_accesses_range;

      re_pr1 : Integer := 10; -- for resource priority
      mem    : memories_table;

   begin

      initialize (sys);
      add_core_unit
        (sys.core_units,
         a_core,
         To_Unbounded_String ("core1"),
         preemptive,
         0,
         1,
         101,
         102,
         103,
         To_Unbounded_String (""),
         To_Unbounded_String (""),
         posix_1003_highest_priority_first_protocol,
         mem);
      add (a_core_unit_table, a_core);

      add_processor
        (sys.processors,
         To_Unbounded_String ("processor1"),
         a_core_unit_table);

      add_address_space
        (sys.address_spaces,
         To_Unbounded_String ("addr1"),
         To_Unbounded_String ("processor1"),
         0,
         0,
         0,
         0);

      add_task
        (sys.tasks,
         To_Unbounded_String ("T1"),
         To_Unbounded_String ("processor1"),
         To_Unbounded_String ("addr1"),
         To_Unbounded_String (""),
         periodic_type,
         0,
         2,
         4,
         4,
         0,
         10,
         1,
         0,
         sched_fifo);
      add_task
        (sys.tasks,
         To_Unbounded_String ("T2"),
         To_Unbounded_String ("processor1"),
         To_Unbounded_String ("addr1"),
         To_Unbounded_String (""),
         periodic_type,
         0,
         3,
         5,
         5,
         0,
         10,
         2,
         0,
         sched_fifo);
      add_task
        (sys.tasks,
         To_Unbounded_String ("T3"),
         To_Unbounded_String ("processor1"),
         To_Unbounded_String ("addr1"),
         To_Unbounded_String (""),
         periodic_type,
         0,
         7,
         20,
         20,
         0,
         10,
         3,
         0,
         sched_fifo);

      r.task_begin := 1;
      r.task_end   := 1;
      add (rt, To_Unbounded_String ("T1"), r);
      add (rt, To_Unbounded_String ("T2"), r);

      add_resource
        (sys.resources,
         To_Unbounded_String ("R1"),
         1,
         0,
         0,
         To_Unbounded_String ("processor1"),
         To_Unbounded_String ("addr1"),
         priority_inheritance_protocol,
         rt,
         re_pr1,
         automatic_assignment);

      range_end :=
        search_resource
          (sys.resources,
           suppress_space (To_Unbounded_String ("R1")))
          .critical_sections
          .nb_entries;
      item := 0;
      loop
         add_one_task_dependency_resource
           (sys.dependencies,
            search_task
              (sys.tasks,
               search_resource
                 (sys.resources,
                  suppress_space (To_Unbounded_String ("R1")))
                 .critical_sections
                 .entries
                 (item)
                 .item),
            search_resource
              (sys.resources,
               suppress_space (To_Unbounded_String ("R1"))));
         item := item + 1;
         exit when item >= range_end;
      end loop;

   end compliant_ravenscar;

   procedure uncompliant_ravenscar (sys : out system) is
      a_core            : core_unit_ptr;
      a_core_unit_table : core_units_table;
      rt                : resource_accesses_table;
      r                 : critical_section;
      item              : resource_accesses_range;
      range_end         : resource_accesses_range;

      --re_pr1   : integer; -- for resource_priority
      mem : memories_table;

   begin

      initialize (sys);
      add_core_unit
        (sys.core_units,
         a_core,
         To_Unbounded_String ("core1"),
         preemptive,
         0,
         1,
         101,
         102,
         103,
         To_Unbounded_String (""),
         To_Unbounded_String (""),
         posix_1003_highest_priority_first_protocol,
         mem);
      add (a_core_unit_table, a_core);

      add_processor
        (sys.processors,
         To_Unbounded_String ("processor1"),
         a_core_unit_table);

      add_address_space
        (sys.address_spaces,
         To_Unbounded_String ("addr1"),
         To_Unbounded_String ("processor1"),
         0,
         0,
         0,
         0);

      add_task
        (sys.tasks,
         To_Unbounded_String ("T1"),
         To_Unbounded_String ("processor1"),
         To_Unbounded_String ("addr1"),
         To_Unbounded_String (""),
         periodic_type,
         0,
         2,
         4,
         4,
         0,
         10,
         1,
         0,
         sched_fifo);
      add_task
        (sys.tasks,
         To_Unbounded_String ("T2"),
         To_Unbounded_String ("processor1"),
         To_Unbounded_String ("addr1"),
         To_Unbounded_String (""),
         periodic_type,
         0,
         3,
         5,
         5,
         0,
         10,
         2,
         0,
         sched_fifo);
      add_task
        (sys.tasks,
         To_Unbounded_String ("T3"),
         To_Unbounded_String ("processor1"),
         To_Unbounded_String ("addr1"),
         To_Unbounded_String (""),
         periodic_type,
         0,
         7,
         20,
         20,
         0,
         10,
         3,
         0,
         sched_fifo);

      r.task_begin := 1;
      r.task_end   := 1;
      add (rt, To_Unbounded_String ("T1"), r);
      add (rt, To_Unbounded_String ("T2"), r);

      add_resource
        (sys.resources,
         To_Unbounded_String ("R1"),
         1,
         0,
         0,
         To_Unbounded_String ("processor1"),
         To_Unbounded_String ("addr1"),
         no_protocol,
         rt,
         1,
         automatic_assignment);

      range_end :=
        search_resource
          (sys.resources,
           suppress_space (To_Unbounded_String ("R1")))
          .critical_sections
          .nb_entries;
      item := 0;
      loop
         add_one_task_dependency_resource
           (sys.dependencies,
            search_task
              (sys.tasks,
               search_resource
                 (sys.resources,
                  suppress_space (To_Unbounded_String ("R1")))
                 .critical_sections
                 .entries
                 (item)
                 .item),
            search_resource
              (sys.resources,
               suppress_space (To_Unbounded_String ("R1"))));
         item := item + 1;
         exit when item >= range_end;
      end loop;

   end uncompliant_ravenscar;

   procedure uncompliant_buffer (sys : out system) is
      a_core                 : core_unit_ptr;
      a_core_unit_table      : core_units_table;
      bt                     : buffer_roles_table;
      b                      : buffer_role;
      t1_ref, t2_ref, t3_ref : generic_task_ptr;
      mem                    : memories_table;
   begin

      initialize (sys);
      add_core_unit
        (sys.core_units,
         a_core,
         To_Unbounded_String ("core1"),
         preemptive,
         0,
         1,
         101,
         102,
         103,
         To_Unbounded_String (""),
         To_Unbounded_String (""),
         posix_1003_highest_priority_first_protocol,
         mem);
      add (a_core_unit_table, a_core);

      add_processor
        (sys.processors,
         To_Unbounded_String ("processor1"),
         a_core_unit_table);

      add_address_space
        (sys.address_spaces,
         To_Unbounded_String ("addr1"),
         To_Unbounded_String ("processor1"),
         0,
         0,
         0,
         0);

      add_task
        (my_tasks           => sys.tasks,
         a_task             => t1_ref,
         name               => To_Unbounded_String ("T1"),
         cpu_name           => To_Unbounded_String ("processor1"),
         address_space_name => To_Unbounded_String ("addr1"),
         core_name          => empty_string,
         task_type          => periodic_type,
         start_time         => 0,
         capacity           => 1,
         period             => 2,
         deadline           => 2,
         jitter             => 0,
         blocking_time      => 0,
         priority           => 1,
         criticality        => 0,
         policy             => sched_fifo);

      add_task
        (my_tasks           => sys.tasks,
         a_task             => t2_ref,
         name               => To_Unbounded_String ("T2"),
         cpu_name           => To_Unbounded_String ("processor1"),
         address_space_name => To_Unbounded_String ("addr1"),
         core_name          => empty_string,
         task_type          => periodic_type,
         start_time         => 0,
         capacity           => 1,
         period             => 3,
         deadline           => 3,
         jitter             => 0,
         blocking_time      => 0,
         priority           => 2,
         criticality        => 0,
         policy             => sched_fifo);

      add_task
        (my_tasks           => sys.tasks,
         a_task             => t3_ref,
         name               => To_Unbounded_String ("T3"),
         cpu_name           => To_Unbounded_String ("processor1"),
         address_space_name => To_Unbounded_String ("addr1"),
         core_name          => empty_string,
         task_type          => periodic_type,
         start_time         => 0,
         capacity           => 2,
         period             => 9,
         deadline           => 9,
         jitter             => 0,
         blocking_time      => 0,
         priority           => 1,
         criticality        => 0,
         policy             => sched_fifo);

      b.the_role := queuing_producer;
      b.size     := 1;
      b.time     := 1;
      add (bt, To_Unbounded_String ("T1"), b);
      b.the_role := queuing_consumer;
      b.size     := 2;
      b.time     := 2;
      add (bt, To_Unbounded_String ("T2"), b);

      add_buffer
        (sys.buffers,
         To_Unbounded_String ("B1"),
         1,
         To_Unbounded_String ("processor1"),
         To_Unbounded_String ("addr1"),
         qs_mm1,
         bt);

      add_one_task_dependency_time_triggered
        (sys.dependencies,
         search_task (sys.tasks, To_Unbounded_String ("T1")),
         search_task (sys.tasks, To_Unbounded_String ("T2")),
         sampled_timing);
      add_one_task_dependency_time_triggered
        (sys.dependencies,
         search_task (sys.tasks, To_Unbounded_String ("T2")),
         search_task (sys.tasks, To_Unbounded_String ("T3")),
         sampled_timing);

      Put_Line (To_String (xml_string (sys, 0)));

   end uncompliant_buffer;

   procedure add_multiple_periodic_tasks_to_set_uunifast
     (my_tasks : in out tasks_set;
      n        : in     Integer;
      u        : in     Float)
   is
      use Ada.Float_Text_IO;
      i          : Integer;
      capacity   : Integer := 0;
      period     : Integer := 0;
      deadline   : Integer := 0;
      start_time : Integer := 0;

      a_offset   : offset_type;
      offset_t_a : offsets_table;

      u_array : random_tools.float_array (0 .. n - 1);
      flag    : Boolean := True;
   begin
      i := 0;
      while (flag) loop
         u_array := gen_uunifast (n => n, u => u);

         flag := False;

         for i in 0 .. n - 1 loop
            if (u_array (i) < 0.03) then
               flag := True;
            end if;
         end loop;
      end loop;

      while (i < n) loop

         Initialize (a_offset);
         initialize (offset_t_a);

         capacity := 0;
         period   := 0;
         deadline := 0;

         while (capacity <= 0 or period <= 0 or a_offset.offset_value <= 0)
         loop
            capacity   := random_integer (n1 => 10, n2 => 15);
            period := Integer (Float'ceiling (Float (capacity) / u_array (i)));
            start_time := random_integer (n1 => 1, n2 => 30);
            deadline   := period;
         end loop;

         add_task
           (my_tasks           => my_tasks,
            name => suppress_space (To_Unbounded_String ("Task" & i'img)),
            cpu_name           => To_Unbounded_String ("processor1"),
            address_space_name => To_Unbounded_String ("addr1"),
            core_name          => empty_string,
            task_type          => periodic_type,
            start_time         => start_time,
            capacity           => capacity,
            period             => period,
            deadline           => deadline,
            jitter             => 0,
            blocking_time      => 0,
            priority           => 1,
            criticality        => 0,
            policy             => sched_fifo);
         i := i + 1;
      end loop;

   end add_multiple_periodic_tasks_to_set_uunifast;

   procedure add_multiple_periodic_tasks_harmonic_with_direct_mapped_instruction_cache_utilization_to_set_uunifast
     (my_tasks                 : in out tasks_set;
      n                        : in     Integer;
      pu                       : in     Float;
      cu                       : in     Float;
      cs                       : in     Integer;
      rf                       : in     Float;
      my_instruction_cache     : in     instruction_cache_ptr;
      my_cache_access_profiles :    out cache_access_profiles_set)
   is
      use Ada.Float_Text_IO;
      i          : Integer;
      capacity   : Integer := 0;
      period     : Integer := 0;
      deadline   : Integer := 0;
      start_time : Integer := 0;

      pu_array               : random_tools.float_array (0 .. n - 1);
      flag                   : Boolean := True;
      a_task                 : generic_task_ptr;
      a_cache_access_profile : cache_access_profile_ptr;
      ------------------------------------------
      cu_array : random_tools.float_array (0 .. n - 1);

      start_set : Integer := 0;
      end_set   : Integer := 0;
      ecb       : Integer := 0;
      ucb       : Integer := 0;

      ucb_counter : Integer := 0;

      periods : array (0 .. 6) of Integer :=
        (1250, 2500, 3125, 6250, 12500, 15625, 31250);
   --Periods : array (0..6) of Integer := (10,15,20,30,40,60,120);
   begin
      set_initialize;
      i := 0;

      --GENERATE PROCESSOR UTILIZATION
      pu_array := gen_uunifast (n => n, u => pu);
      --GENERATE CACHE UTILIZATION
      cu_array := gen_uunifast (n => n, u => cu);

      while (i < n) loop
         capacity := 0;
         period   := 0;
         deadline := 0;

         start_time := random_integer (n1 => 1, n2 => 50) * 10;

         --start_time:= Random_Integer(n1 => 1, n2 => 20);

         period := periods (random_integer (n1 => 0, n2 => 6));

         deadline := period;
         capacity := Integer (Float'floor (Float (period) * pu_array (i)));

         if (capacity <= 0) then
            capacity := 1;
         end if;

         a_cache_access_profile      := new cache_access_profile;
         a_cache_access_profile.name :=
           suppress_space (To_Unbounded_String ("CAP_" & i'img));
         ----------------------------------------------------------------

         ecb := Integer (Float'floor (Float (cs) * cu_array (i)));
         ucb := Integer (Float'floor (Float (ecb) * rf));

         end_set := (start_set + ecb) mod cs;

         ucb_counter := 0;

         if (start_set < end_set and ecb < cs) then
            for j in start_set .. end_set - 1 loop
               add
                 (a_cache_access_profile.ECBs,
                  my_instruction_cache.cache_blocks.entries
                    (Caches.cache_blocks_range (j)));
               if (ucb_counter <= ucb) then
                  add
                    (a_cache_access_profile.UCBs,
                     my_instruction_cache.cache_blocks.entries
                       (Caches.cache_blocks_range (j)));
                  ucb_counter := ucb_counter + 1;
               end if;
            end loop;
         end if;

         if (start_set > end_set and ecb < cs) then
            for j in start_set .. cs - 1 loop
               add
                 (a_cache_access_profile.ECBs,
                  my_instruction_cache.cache_blocks.entries
                    (Caches.cache_blocks_range (j)));
               if (ucb_counter <= ucb) then
                  add
                    (a_cache_access_profile.UCBs,
                     my_instruction_cache.cache_blocks.entries
                       (Caches.cache_blocks_range (j)));
                  ucb_counter := ucb_counter + 1;
               end if;
            end loop;
            for j in 0 .. end_set - 1 loop
               add
                 (a_cache_access_profile.ECBs,
                  my_instruction_cache.cache_blocks.entries
                    (Caches.cache_blocks_range (j)));
               if (ucb_counter <= ucb) then
                  add
                    (a_cache_access_profile.UCBs,
                     my_instruction_cache.cache_blocks.entries
                       (Caches.cache_blocks_range (j)));
                  ucb_counter := ucb_counter + 1;
               end if;
            end loop;
         end if;

         if (ecb > cs) then
            for j in 0 .. cs - 1 loop
               add
                 (a_cache_access_profile.ECBs,
                  my_instruction_cache.cache_blocks.entries
                    (Caches.cache_blocks_range (j)));
               if (ucb_counter <= ucb) then
                  add
                    (a_cache_access_profile.UCBs,
                     my_instruction_cache.cache_blocks.entries
                       (Caches.cache_blocks_range (j)));
                  ucb_counter := ucb_counter + 1;
               end if;
            end loop;
         end if;

         start_set := end_set;
         add (my_cache_access_profiles, a_cache_access_profile);
         ----------------------------------------------------------------

         add_task
           (my_tasks                  => my_tasks,
            a_task                    => a_task,
            name => suppress_space (To_Unbounded_String ("Task" & i'img)),
            cpu_name                  => To_Unbounded_String ("CPU_01"),
            address_space_name => To_Unbounded_String ("Address_Space_01"),
            core_name                 => empty_string,
            task_type                 => periodic_type,
            start_time                => start_time,
            capacity                  => capacity,
            period                    => period,
            deadline                  => deadline,
            jitter                    => 0,
            blocking_time             => 0,
            priority                  => 1,
            criticality               => 0,
            policy                    => sched_fifo,
            cache_access_profile_name => a_cache_access_profile.name);
         i := i + 1;
      end loop;
   end add_multiple_periodic_tasks_harmonic_with_direct_mapped_instruction_cache_utilization_to_set_uunifast;

   procedure add_multiple_periodic_tasks_no_offset_with_direct_mapped_instruction_cache_utilization_to_set_uunifast
     (my_tasks                 : in out tasks_set;
      min_period               : in     Integer;
      max_period               : in     Integer;
      n                        : in     Integer;
      pu                       : in     Float;
      cu                       : in     Float;
      cs                       : in     Integer;
      rf                       : in     Float;
      my_instruction_cache     : in     instruction_cache_ptr;
      my_cache_access_profiles :    out cache_access_profiles_set)
   is
      use Ada.Float_Text_IO;
      i          : Integer;
      capacity   : Integer := 0;
      period     : Integer := 0;
      deadline   : Integer := 0;
      start_time : Integer := 0;

      pu_array               : random_tools.float_array (0 .. n - 1);
      flag                   : Boolean := True;
      a_task                 : generic_task_ptr;
      a_cache_access_profile : cache_access_profile_ptr;
      ------------------------------------------
      cu_array : random_tools.float_array (0 .. n - 1);

      start_set : Integer := 0;
      end_set   : Integer := 0;
      ecb       : Integer := 0;
      ucb       : Integer := 0;

      ucb_counter : Integer := 0;

      periods : array (0 .. 6) of Integer :=
        (1250, 2500, 3125, 6250, 12500, 15625, 31250);
   --Periods : array (0..6) of Integer := (10,15,20,30,40,60,120);
   begin
      set_initialize;
      i := 0;

      --GENERATE PROCESSOR UTILIZATION
      pu_array := gen_uunifast (n => n, u => pu);
      --GENERATE CACHE UTILIZATION
      cu_array := gen_uunifast (n => n, u => cu);

      while (i < n) loop
         capacity := 0;
         period   := 0;
         deadline := 0;

         start_time := 0;
         period     :=
           (random_integer (n1 => min_period, n2 => max_period) / 10) * 10;

         deadline := period;
         capacity := Integer (Float'floor (Float (period) * pu_array (i)));

         if (capacity <= 0) then
            capacity := 1;
         end if;

         a_cache_access_profile      := new cache_access_profile;
         a_cache_access_profile.name :=
           suppress_space (To_Unbounded_String ("CAP_" & i'img));
         ----------------------------------------------------------------

         ecb := Integer (Float'floor (Float (cs) * cu_array (i)));
         ucb := Integer (Float'floor (Float (ecb) * rf));

         if (ecb <= 0) then
            ecb := 1;
            ucb := 1;
         end if;

         end_set := (start_set + ecb) mod cs;

         ucb_counter := 0;

         if (start_set < end_set and ecb < cs) then
            for j in start_set .. end_set - 1 loop
               add
                 (a_cache_access_profile.ECBs,
                  my_instruction_cache.cache_blocks.entries
                    (Caches.cache_blocks_range (j)));
               if (ucb_counter <= ucb) then
                  add
                    (a_cache_access_profile.UCBs,
                     my_instruction_cache.cache_blocks.entries
                       (Caches.cache_blocks_range (j)));
                  ucb_counter := ucb_counter + 1;
               end if;
            end loop;
         end if;

         if (start_set > end_set and ecb < cs) then
            for j in start_set .. cs - 1 loop
               add
                 (a_cache_access_profile.ECBs,
                  my_instruction_cache.cache_blocks.entries
                    (Caches.cache_blocks_range (j)));
               if (ucb_counter <= ucb) then
                  add
                    (a_cache_access_profile.UCBs,
                     my_instruction_cache.cache_blocks.entries
                       (Caches.cache_blocks_range (j)));
                  ucb_counter := ucb_counter + 1;
               end if;
            end loop;
            for j in 0 .. end_set - 1 loop
               add
                 (a_cache_access_profile.ECBs,
                  my_instruction_cache.cache_blocks.entries
                    (Caches.cache_blocks_range (j)));
               if (ucb_counter <= ucb) then
                  add
                    (a_cache_access_profile.UCBs,
                     my_instruction_cache.cache_blocks.entries
                       (Caches.cache_blocks_range (j)));
                  ucb_counter := ucb_counter + 1;
               end if;
            end loop;
         end if;

         if (ecb > cs) then
            for j in 0 .. cs - 1 loop
               add
                 (a_cache_access_profile.ECBs,
                  my_instruction_cache.cache_blocks.entries
                    (Caches.cache_blocks_range (j)));
               if (ucb_counter <= ucb) then
                  add
                    (a_cache_access_profile.UCBs,
                     my_instruction_cache.cache_blocks.entries
                       (Caches.cache_blocks_range (j)));
                  ucb_counter := ucb_counter + 1;
               end if;
            end loop;
         end if;

         start_set := end_set;
         add (my_cache_access_profiles, a_cache_access_profile);
         ----------------------------------------------------------------

         add_task
           (my_tasks                  => my_tasks,
            a_task                    => a_task,
            name => suppress_space (To_Unbounded_String ("Task" & i'img)),
            cpu_name                  => To_Unbounded_String ("CPU_01"),
            address_space_name => To_Unbounded_String ("Address_Space_01"),
            core_name                 => empty_string,
            task_type                 => periodic_type,
            start_time                => start_time,
            capacity                  => capacity,
            period                    => period,
            deadline                  => deadline,
            jitter                    => 0,
            blocking_time             => 0,
            priority                  => 1,
            criticality               => 0,
            policy                    => sched_fifo,
            cache_access_profile_name => a_cache_access_profile.name);
         i := i + 1;
      end loop;
   end add_multiple_periodic_tasks_no_offset_with_direct_mapped_instruction_cache_utilization_to_set_uunifast;
begin

   rand_int.Reset (g_int);
   rand_res.Reset (g_res);

end architecture_factory;