cheddar_3.3.0_aea10b3c/framework/paes/paes-chromosome_data_manipulation_t2p_and_security.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
------------------------------------------------------------------------------
------------------------------------------------------------------------------
-- 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-2016, Frank Singhoff, Alain Plantec, Jerome Legrand
--
-- The Cheddar project was started in 2002 by
-- Frank Singhoff, Lab-STICC UMR 6285 laboratory, 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: 3561 $
--    $Date: 2020-11-02 08:25:02 +0100 (Mon, 02 Nov 2020) $
--    $Author: singhoff $
------------------------------------------------------------------------------
------------------------------------------------------------------------------

with Ada.Numerics.Elementary_Functions; use Ada.Numerics.Elementary_Functions;

with Ada.Strings;               use Ada.Strings;
with Ada.Strings.Fixed;         use Ada.Strings.Fixed;
with Ada.Numerics.Float_Random; use Ada.Numerics.Float_Random;
with unbounded_strings;         use unbounded_strings;
with Ada.Strings.Unbounded;     use Ada.Strings.Unbounded;

with Ada.Strings.Unbounded;    use Ada.Strings.Unbounded;
with unbounded_strings;        use unbounded_strings;
with Ada.Strings;              use Ada.Strings;
with Ada.Text_IO.Unbounded_IO; use Ada.Text_IO.Unbounded_IO;
with Ada.Directories;          use Ada.Directories;
with Ada.Strings.Unbounded;    use Ada.Strings.Unbounded;
with unbounded_strings;        use unbounded_strings;
with convert_unbounded_strings;
use unbounded_strings.unbounded_string_list_package;
use unbounded_strings.strings_table_package;
with Ada.Strings;              use Ada.Strings;
with Ada.Text_IO.Unbounded_IO; use Ada.Text_IO.Unbounded_IO;

with Ada.Text_IO;         use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
with Ada.Float_Text_IO;   use Ada.Float_Text_IO;

with Dependencies;      use Dependencies;
with task_dependencies; use task_dependencies;
with task_dependencies; use task_dependencies.half_dep_set;
with message_set;       use message_set;
with Messages;          use Messages;

with Tasks;        use Tasks;
with task_set;     use task_set;
with Resources;    use Resources;
with resource_set; use resource_set;
with Objects;      use Objects;
with convert_unbounded_strings;
use unbounded_strings.unbounded_string_list_package;

with Scheduler_Interface; use Scheduler_Interface;
with Address_Spaces;      use Address_Spaces;
with address_space_set;   use address_space_set;

with call_framework;           use call_framework;
with Call_Framework_Interface; use Call_Framework_Interface;
use Call_Framework_Interface.Framework_Response_Package;
use Call_Framework_Interface.Framework_Request_Package;
with call_scheduling_framework; use call_scheduling_framework;

with pipe_commands; use pipe_commands;
with Ada.Text_IO;   use Ada.Text_IO;

with Ada.Text_IO.Unbounded_IO; use Ada.Text_IO.Unbounded_IO;
with Ada.Directories;          use Ada.Directories;

with GNAT.OS_Lib; use GNAT.OS_Lib;
with debug;       use debug;

with random_tools; use random_tools;

use unbounded_strings.strings_table_package;

with architecture_factory; use architecture_factory;

with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
with Ada.Float_Text_IO;   use Ada.Float_Text_IO;

with task_set;            use task_set;
with systems;             use systems;
with Processors;          use Processors;
with processor_set;       use processor_set;
with Processor_Interface; use Processor_Interface;
use processor_set.generic_processor_set;

with Core_Units; use Core_Units;
use Core_Units.Core_Units_Table_Package;

with natural_util; use natural_util;
with feasibility_test.feasibility_interval;
use feasibility_test.feasibility_interval;

with integer_util; use integer_util;

use Resources.Resource_Accesses;
with float_util; use float_util;

with Ada.Characters.Latin_1; use Ada.Characters;
with Ada.Text_IO;            use Ada.Text_IO;
with GNAT.String_Split;      use GNAT;
with MILS_Security;          use MILS_Security;

with random_tools; use random_tools;
with Memories;     use Memories;
with Paes.objective_functions.t2p_and_security;
use Paes.objective_functions.t2p_and_security;
with Paes.security_implementation; use Paes.security_implementation;
package body Paes.chromosome_Data_Manipulation_t2p_and_security is

   --------------
   -- init_T2P --
   --------------

   procedure init_T2P is
      F           : Ada.Text_IO.File_Type;
      gene_i      : Unbounded_String;
      gene_task_i : Unbounded_String;
      gene_com_i  : Unbounded_String;
      chrom_str   : Unbounded_String;
      --  Subs is populated by the actual substrings.
      Subs : String_Split.Slice_Set;
      --  just an arbitrary simple set of whitespace.
      Seps : constant String := " " & Latin_1.HT;
      j, k, m, l, itr, part, full              : Integer;
      My_iterator                              : tasks_dependencies_iterator;
      Dep_Ptr                                  : dependency_ptr;
      My_dependencies                          : tasks_dependencies_ptr;
      A_task_i                                 : generic_task_ptr;
      Sys1, Sys2, Sys3, Sys4, Sys5, Sys6, Sys7 : systems.system;
   begin

      sol_init1 := new solution_t2p;
      sol_init2 := new solution_t2p;
      sol_init3 := new solution_t2p;
      sol_init4 := new solution_t2p;
      sol_init5 := new solution_t2p;
      sol_init6 := new solution_t2p;
      if Using_preprocessed_initial_sol then
         -- Initialize the current solution c with the preprocessed
         -- initial solution

         -- 1/ get the chromosome of the preprocessed initial solution
         -- from the file chrom_preprocessed_initial_solution.txt
         Open
           (File => F,
            Mode => Ada.Text_IO.In_File,
            Name => "chrom_preprocessed_initial_solution.txt");

         loop
            exit when Ada.Text_IO.End_Of_File (F);
            Ada.Strings.Unbounded.Append
              (chrom_str,
               To_Unbounded_String (Get_Line (File => F)));
         end loop;
         Close (F);
         put_debug ("chrom_str: " & To_String (chrom_str));
         -- 2/ extract gene values from chrom_str to initialize the
         -- initial current solution
         -- The following code is inspired from:
         -- http://wiki.ada-dk.org/gnat.string_split_basic_usage_example
         String_Split.Create
           (S          => Subs,
            From       => To_String (chrom_str),
            Separators => Seps,
            Mode       => String_Split.Multiple);
         for i in 1 .. genes loop
            solution_t2p_ptr (c).chrom_task (i) :=
              Integer'value
                (String_Split.Slice (Subs, String_Split.Slice_Number (i + 1)));
         end loop;
         Put ("The initial preprocessed solution: ");
         print_genome (solution_t2p (c.all));

      else

         for n in 1 .. 15 loop
            nb_secu_conf_choice (n) := 0;
         end loop;

         nb_InitSol        := 0;
         nb_NoFeasible_Sol := 0;

         --initialize sol_init2: split equally the tasks into nb_partitions--
         full := genes;
         l    := 1;
         m    := 0;
         itr  := 0;
         for i in 0 .. nb_partitions - 1 loop
            part := full / (nb_partitions - i);
            full := full - part;
            for m in itr + 1 .. itr + part loop
               sol_init2.chrom_task (m) := l;
            end loop;
            l   := l + 1;
            itr := itr + part;

         end loop;

         for i in 1 .. genes loop

            solution_t2p_ptr (c).chrom_task (i) :=
              1;    --All the tasks in the same partition
            sol_init1.chrom_task (i) :=
              1;  --All the tasks in the same partition

            A_task_i :=
              search_task (Initial_System.tasks, suppress_space (i'img));

            -- all tasks with the same confidentiality level should be put in the same partition
            if (A_task_i.mils_confidentiality_level = top_secret) then
               sol_init3.chrom_task (i) := 1;
               sol_init4.chrom_task (i) := 1;
            elsif (A_task_i.mils_confidentiality_level = secret) then
               sol_init3.chrom_task (i) := 2;
               sol_init4.chrom_task (i) := 2;
            elsif (A_task_i.mils_confidentiality_level = classified) then
               sol_init3.chrom_task (i) := 3;
               sol_init4.chrom_task (i) := 3;
            else
               sol_init3.chrom_task (i) := 4;
               sol_init4.chrom_task (i) := 4;
            end if;

-- all tasks with the same integrity level should be put in the same partition

            if (A_task_i.mils_integrity_level = high) then
               sol_init5.chrom_task (i) := 1;
               sol_init6.chrom_task (i) := 1;
            elsif (A_task_i.mils_integrity_level = medium) then
               sol_init5.chrom_task (i) := 2;
               sol_init6.chrom_task (i) := 2;
            else
               sol_init5.chrom_task (i) := 3;
               sol_init6.chrom_task (i) := 3;
            end if;

         end loop;

         New_Line;

         My_dependencies := Initial_System.dependencies;
         if is_empty (My_dependencies.depends) then
            put_debug ("No dependencies");
         else
            j := 1;
            k := 1;
            reset_iterator (My_dependencies.depends, My_iterator);
            loop
               current_element (My_dependencies.depends, Dep_Ptr, My_iterator);
               if (Dep_Ptr.type_of_dependency = precedence_dependency) then
                  if
                    ((Dep_Ptr.precedence_sink.mils_confidentiality_level =
                      unclassified) and
                     ((Dep_Ptr.precedence_source.mils_confidentiality_level =
                       secret) or
                      (Dep_Ptr.precedence_source.mils_confidentiality_level =
                       top_secret))) or
                    ((Dep_Ptr.precedence_source.mils_integrity_level = low) and
                     ((Dep_Ptr.precedence_sink.mils_integrity_level =
                       medium) or
                      (Dep_Ptr.precedence_sink.mils_integrity_level = high)))
                  then
                     -- Resolve confidentiality and integrity constraints problem (communications high)

                     solution_t2p_ptr (c).chrom_com (j).mode        := secure;
                     solution_t2p_ptr (c).chrom_com (j).source_sink :=
                       suppress_space
                         (To_String (Dep_Ptr.precedence_source.name) &
                          "_" &
                          To_String (Dep_Ptr.precedence_sink.name));

                     sol_init1.chrom_com (j).mode        := secure;
                     sol_init1.chrom_com (j).source_sink :=
                       suppress_space
                         (To_String (Dep_Ptr.precedence_source.name) &
                          "_" &
                          To_String (Dep_Ptr.precedence_sink.name));

                     sol_init2.chrom_com (j).mode        := secure;
                     sol_init2.chrom_com (j).source_sink :=
                       suppress_space
                         (To_String (Dep_Ptr.precedence_source.name) &
                          "_" &
                          To_String (Dep_Ptr.precedence_sink.name));

                     sol_init3.chrom_com (j).mode        := secure;
                     sol_init3.chrom_com (j).source_sink :=
                       suppress_space
                         (To_String (Dep_Ptr.precedence_source.name) &
                          "_" &
                          To_String (Dep_Ptr.precedence_sink.name));

                     sol_init4.chrom_com (j).mode        := secure;
                     sol_init4.chrom_com (j).source_sink :=
                       suppress_space
                         (To_String (Dep_Ptr.precedence_source.name) &
                          "_" &
                          To_String (Dep_Ptr.precedence_sink.name));

                     sol_init5.chrom_com (j).mode        := secure;
                     sol_init5.chrom_com (j).source_sink :=
                       suppress_space
                         (To_String (Dep_Ptr.precedence_source.name) &
                          "_" &
                          To_String (Dep_Ptr.precedence_sink.name));

                     sol_init6.chrom_com (j).mode        := secure;
                     sol_init6.chrom_com (j).source_sink :=
                       suppress_space
                         (To_String (Dep_Ptr.precedence_source.name) &
                          "_" &
                          To_String (Dep_Ptr.precedence_sink.name));

                  elsif
                    (Dep_Ptr.precedence_sink.mils_confidentiality_level <
                     Dep_Ptr.precedence_source.mils_confidentiality_level) or
                    (Dep_Ptr.precedence_source.mils_integrity_level <
                     Dep_Ptr.precedence_sink.mils_integrity_level)
                  then
                     -- resolve security problems of solutions c, sol_init4, sol_init6  (communications Low)
                     k := k + 1;

                     solution_t2p_ptr (c).chrom_com (j).mode        := secure;
                     solution_t2p_ptr (c).chrom_com (j).source_sink :=
                       suppress_space
                         (To_String (Dep_Ptr.precedence_source.name) &
                          "_" &
                          To_String (Dep_Ptr.precedence_sink.name));

                     sol_init4.chrom_com (j).mode        := secure;
                     sol_init4.chrom_com (j).source_sink :=
                       suppress_space
                         (To_String (Dep_Ptr.precedence_source.name) &
                          "_" &
                          To_String (Dep_Ptr.precedence_sink.name));

                     sol_init6.chrom_com (j).mode        := secure;
                     sol_init6.chrom_com (j).source_sink :=
                       suppress_space
                         (To_String (Dep_Ptr.precedence_source.name) &
                          "_" &
                          To_String (Dep_Ptr.precedence_sink.name));

                     -- ignore security problems of solutions sol_init1, sol_init2, sol_init3, sol_init5   (communications Low)
                     if (intra_partition_safe = 0) then
                  -- intra partition communications consider as non attackable
                        sol_init1.chrom_com (j).mode :=
                          secure; --all tasks are in the same partition
                        if
                          (sol_init2.chrom_com
                             (Integer'value
                                (To_String (Dep_Ptr.precedence_source.name))) =
                           sol_init2.chrom_com
                             (Integer'value
                                (To_String (Dep_Ptr.precedence_sink.name))))
                        then
                           sol_init2.chrom_com (j).mode := secure;
                        else
                           sol_init2.chrom_com (j).mode := nosecure;
                        end if;
                        if
                          (sol_init2.chrom_com
                             (Integer'value
                                (To_String (Dep_Ptr.precedence_source.name))) =
                           sol_init3.chrom_com
                             (Integer'value
                                (To_String (Dep_Ptr.precedence_sink.name))))
                        then
                           sol_init3.chrom_com (j).mode := secure;
                        else
                           sol_init3.chrom_com (j).mode := nosecure;
                        end if;
                        if
                          (sol_init5.chrom_com
                             (Integer'value
                                (To_String (Dep_Ptr.precedence_source.name))) =
                           sol_init5.chrom_com
                             (Integer'value
                                (To_String (Dep_Ptr.precedence_sink.name))))
                        then
                           sol_init5.chrom_com (j).mode := secure;
                        else
                           sol_init5.chrom_com (j).mode := nosecure;
                        end if;

                     else
                        sol_init1.chrom_com (j).mode := nosecure;
                        sol_init2.chrom_com (j).mode := nosecure;
                        sol_init3.chrom_com (j).mode := nosecure;
                        sol_init5.chrom_com (j).mode := nosecure;
                     end if;

                     sol_init1.chrom_com (j).source_sink :=
                       suppress_space
                         (To_String (Dep_Ptr.precedence_source.name) &
                          "_" &
                          To_String (Dep_Ptr.precedence_sink.name));

                     sol_init2.chrom_com (j).source_sink :=
                       suppress_space
                         (To_String (Dep_Ptr.precedence_source.name) &
                          "_" &
                          To_String (Dep_Ptr.precedence_sink.name));

                     sol_init3.chrom_com (j).source_sink :=
                       suppress_space
                         (To_String (Dep_Ptr.precedence_source.name) &
                          "_" &
                          To_String (Dep_Ptr.precedence_sink.name));

                     sol_init5.chrom_com (j).source_sink :=
                       suppress_space
                         (To_String (Dep_Ptr.precedence_source.name) &
                          "_" &
                          To_String (Dep_Ptr.precedence_sink.name));

                  else
                     -- specify communications with no security problems for all the initial solutions
                     solution_t2p_ptr (c).chrom_com (j).mode        := norisk;
                     solution_t2p_ptr (c).chrom_com (j).source_sink :=
                       suppress_space
                         (To_String (Dep_Ptr.precedence_source.name) &
                          "_" &
                          To_String (Dep_Ptr.precedence_sink.name));

                     sol_init4.chrom_com (j).mode        := norisk;
                     sol_init4.chrom_com (j).source_sink :=
                       suppress_space
                         (To_String (Dep_Ptr.precedence_source.name) &
                          "_" &
                          To_String (Dep_Ptr.precedence_sink.name));

                     sol_init6.chrom_com (j).mode        := norisk;
                     sol_init6.chrom_com (j).source_sink :=
                       suppress_space
                         (To_String (Dep_Ptr.precedence_source.name) &
                          "_" &
                          To_String (Dep_Ptr.precedence_sink.name));

                     sol_init1.chrom_com (j).mode        := norisk;
                     sol_init1.chrom_com (j).source_sink :=
                       suppress_space
                         (To_String (Dep_Ptr.precedence_source.name) &
                          "_" &
                          To_String (Dep_Ptr.precedence_sink.name));

                     sol_init2.chrom_com (j).mode        := norisk;
                     sol_init2.chrom_com (j).source_sink :=
                       suppress_space
                         (To_String (Dep_Ptr.precedence_source.name) &
                          "_" &
                          To_String (Dep_Ptr.precedence_sink.name));

                     sol_init3.chrom_com (j).mode        := norisk;
                     sol_init3.chrom_com (j).source_sink :=
                       suppress_space
                         (To_String (Dep_Ptr.precedence_source.name) &
                          "_" &
                          To_String (Dep_Ptr.precedence_sink.name));

                     sol_init5.chrom_com (j).mode        := norisk;
                     sol_init5.chrom_com (j).source_sink :=
                       suppress_space
                         (To_String (Dep_Ptr.precedence_source.name) &
                          "_" &
                          To_String (Dep_Ptr.precedence_sink.name));

                  end if;
                  j := j + 1;
               end if;
               exit when is_last_element
                   (My_dependencies.depends,
                    My_iterator);
               next_element (My_dependencies.depends, My_iterator);
            end loop;

         end if;
      end if;
      -- Normalize the tasks to partitions assignment
      normalize (solution_t2p (sol_init3.all));
      normalize (solution_t2p (sol_init4.all));
      normalize (solution_t2p (sol_init5.all));
      normalize (solution_t2p (sol_init6.all));
      put_debug ("===============c================");
      --Print the chromosome of the initial solutions
      print_genome (solution_t2p (c.all));
      put_debug ("===============sol_init1================");
      print_genome (solution_t2p (sol_init1.all));
      put_debug ("===============sol_init2================");
      print_genome (solution_t2p (sol_init2.all));
      put_debug ("===============sol_init3================");
      print_genome (solution_t2p (sol_init3.all));
      put_debug ("===============sol_init4================");
      print_genome (solution_t2p (sol_init4.all));
      put_debug ("===============sol_init5================");
      print_genome (solution_t2p (sol_init5.all));
      put_debug ("===============sol_init6================");
      print_genome (solution_t2p (sol_init6.all));

      if Check_Feasibility_of_A_Solution (solution_t2p (sol_init1.all), 0) then
         Put_Line ("===============sol_init1 evaluation ================");

         evaluate_T2P (solution_t2p (sol_init1.all), 0);

         if (Float'value (sol_init1.obj (1)'img) = 0.0) and
           (Float'value (sol_init1.obj (2)'img) = 0.0) and
           (Float'value (sol_init1.obj (3)'img) = 0.0)
         then
            put_debug
              ("MissedDeadlines" &
               sol_init1.obj (1)'img &
               "          Bell    " &
               sol_init1.obj (2)'img &
               "          Biba    " &
               sol_init1.obj (3)'img);
            put_debug ("sol_init1 -- Simple design: no need for optimization");

            archive_soln (generic_solution_ptr (sol_init1));
            Create_system (Sys1, solution_t2p (sol_init1.all));
            Transform_Chromosome_To_CheddarADL_Model
              (Sys1,
               solution_t2p (sol_init1.all));
            write_to_xml_file
              (a_system  => Sys1,
               file_name =>
                 To_String
                   (suppress_space
                      (To_Unbounded_String ("sol_init1" & ".xmlv3"))));
            OS_Exit (0);
         else
            archive_soln (generic_solution_ptr (sol_init1));
            update_grid (generic_solution_ptr (sol_init1));

            Append
              (Data3,
               " 0" &
               "              " &
               sol_init1.obj (1)'img &
               "              " &
               sol_init1.obj (2)'img &
               "              " &
               sol_init1.obj (3)'img &
               "              " &
               sol_init1.security_config'img &
               "              " &
               ASCII.LF);
            put_debug
              ("sol1" &
               "              " &
               sol_init1.obj (1)'img &
               "              " &
               sol_init1.obj (2)'img &
               "              " &
               sol_init1.obj (3)'img &
               "              " &
               ASCII.LF);
            Put_Line
              ("sol1" &
               "              " &
               sol_init1.obj (1)'img &
               "              " &
               sol_init1.obj (2)'img &
               "              " &
               sol_init1.obj (3)'img &
               "              " &
               ASCII.LF);

            nb_InitSol := nb_InitSol + 1;

            Create_system (Sys1, solution_t2p (sol_init1.all));
            Transform_Chromosome_To_CheddarADL_Model
              (Sys1,
               solution_t2p (sol_init1.all));

            write_to_xml_file
              (a_system  => Sys1,
               file_name =>
                 To_String
                   (suppress_space
                      (To_Unbounded_String ("sol_init1" & ".xmlv3"))));
            put_debug
              ("=============== end sol_init1 evaluation ================");
         end if;
      end if;
      --Just for version 3-------
      if (exploration_version = 3) then

         if Check_Feasibility_of_A_Solution
             (solution_t2p (sol_init2.all),
              0)
         then
            Put_Line ("===============sol_init2 evaluation ================");
            put_debug ("===============sol_init2 evaluation ================");
            evaluate_T2P (solution_t2p (sol_init2.all), 0);
            if (Float'value (sol_init2.obj (1)'img) = 0.0) and
              (Float'value (sol_init2.obj (2)'img) = 0.0) and
              (Float'value (sol_init2.obj (3)'img) = 0.0)
            then
               put_debug
                 ("MissedDeadlines" &
                  sol_init2.obj (1)'img &
                  "          Bell    " &
                  sol_init2.obj (2)'img &
                  "          Biba    " &
                  sol_init2.obj (3)'img);
               put_debug
                 ("sol_init2 -- Simple design: no need for optimization");
               archive_soln (generic_solution_ptr (sol_init2));
               Create_system (Sys1, solution_t2p (sol_init2.all));
               Transform_Chromosome_To_CheddarADL_Model
                 (Sys1,
                  solution_t2p (sol_init2.all));
               write_to_xml_file
                 (a_system  => Sys1,
                  file_name =>
                    To_String
                      (suppress_space
                         (To_Unbounded_String ("sol_init2" & ".xmlv3"))));
               OS_Exit (0);
            else

               archive_soln (generic_solution_ptr (sol_init2));
               update_grid (generic_solution_ptr (sol_init2));
               Append
                 (Data3,
                  " 0" &
                  "              " &
                  sol_init2.obj (1)'img &
                  "              " &
                  sol_init2.obj (2)'img &
                  "              " &
                  sol_init2.obj (3)'img &
                  "              " &
                  sol_init2.security_config'img &
                  "              " &
                  ASCII.LF);
               put_debug
                 ("sol2" &
                  "              " &
                  sol_init2.obj (1)'img &
                  "              " &
                  sol_init2.obj (2)'img &
                  "              " &
                  sol_init2.obj (3)'img &
                  "              " &
                  ASCII.LF);

               nb_InitSol := nb_InitSol + 1;

               Create_system (Sys2, solution_t2p (sol_init2.all));
               Transform_Chromosome_To_CheddarADL_Model
                 (Sys2,
                  solution_t2p (sol_init2.all));
               write_to_xml_file
                 (a_system  => Sys2,
                  file_name =>
                    To_String
                      (suppress_space
                         (To_Unbounded_String ("sol_init2" & ".xmlv3"))));

            end if;
         end if;

         if Check_Feasibility_of_A_Solution
             (solution_t2p (sol_init3.all),
              0)
         then
            put_debug ("===============sol_init3 evaluation ================");
            evaluate_T2P (solution_t2p (sol_init3.all), 0);
            if (Float'value (sol_init3.obj (1)'img) = 0.0) and
              (Float'value (sol_init3.obj (2)'img) = 0.0) and
              (Float'value (sol_init3.obj (3)'img) = 0.0)
            then
               put_debug
                 ("MissedDeadlines" &
                  sol_init3.obj (1)'img &
                  "          Bell    " &
                  sol_init3.obj (2)'img &
                  "          Biba    " &
                  sol_init3.obj (3)'img);
               put_debug
                 ("sol_init3 -- Simple design: no need for optimization");
               archive_soln (generic_solution_ptr (sol_init3));
               Create_system (Sys1, solution_t2p (sol_init3.all));
               Transform_Chromosome_To_CheddarADL_Model
                 (Sys1,
                  solution_t2p (sol_init3.all));
               write_to_xml_file
                 (a_system  => Sys1,
                  file_name =>
                    To_String
                      (suppress_space
                         (To_Unbounded_String ("sol_init3" & ".xmlv3"))));
               OS_Exit (0);
            else
               archive_soln (generic_solution_ptr (sol_init3));
               update_grid (generic_solution_ptr (sol_init3));
               Append
                 (Data3,
                  " 0" &
                  "              " &
                  sol_init3.obj (1)'img &
                  "              " &
                  sol_init3.obj (2)'img &
                  "              " &
                  sol_init3.obj (3)'img &
                  "              " &
                  sol_init3.security_config'img &
                  "              " &
                  ASCII.LF);
               put_debug
                 ("sol3" &
                  "              " &
                  sol_init3.obj (1)'img &
                  "              " &
                  sol_init3.obj (2)'img &
                  "              " &
                  sol_init3.obj (3)'img &
                  "              " &
                  ASCII.LF);
               nb_InitSol := nb_InitSol + 1;

               Create_system (Sys3, solution_t2p (sol_init3.all));
               Transform_Chromosome_To_CheddarADL_Model
                 (Sys3,
                  solution_t2p (sol_init3.all));
               write_to_xml_file
                 (a_system  => Sys3,
                  file_name =>
                    To_String
                      (suppress_space
                         (To_Unbounded_String ("sol_init3" & ".xmlv3"))));

            end if;
         end if;

         if Check_Feasibility_of_A_Solution
             (solution_t2p (sol_init4.all),
              0)
         then
            put_debug ("===============sol_init4 evaluation ================");
            evaluate_T2P (solution_t2p (sol_init4.all), 0);
            if (Float'value (sol_init4.obj (1)'img) = 0.0) and
              (Float'value (sol_init4.obj (2)'img) = 0.0) and
              (Float'value (sol_init4.obj (3)'img) = 0.0)
            then
               put_debug
                 ("MissedDeadlines" &
                  sol_init4.obj (1)'img &
                  "          Bell    " &
                  sol_init4.obj (2)'img &
                  "          Biba    " &
                  sol_init4.obj (3)'img);
               put_debug
                 ("sol_init4 -- Simple design: no need for optimization");
               archive_soln (generic_solution_ptr (sol_init4));
               Create_system (Sys1, solution_t2p (sol_init4.all));
               Transform_Chromosome_To_CheddarADL_Model
                 (Sys1,
                  solution_t2p (sol_init4.all));
               write_to_xml_file
                 (a_system  => Sys1,
                  file_name =>
                    To_String
                      (suppress_space
                         (To_Unbounded_String ("sol_init4" & ".xmlv3"))));
               OS_Exit (0);
            else
               archive_soln (generic_solution_ptr (sol_init4));
               update_grid (generic_solution_ptr (sol_init4));
               Append
                 (Data3,
                  " 0" &
                  "              " &
                  sol_init4.obj (1)'img &
                  "              " &
                  sol_init4.obj (2)'img &
                  "              " &
                  sol_init4.obj (3)'img &
                  "              " &
                  sol_init4.security_config'img &
                  "              " &
                  ASCII.LF);
               put_debug
                 ("sol4" &
                  "              " &
                  sol_init4.obj (1)'img &
                  "              " &
                  sol_init4.obj (2)'img &
                  "              " &
                  sol_init4.obj (3)'img &
                  "              " &
                  ASCII.LF);

               nb_InitSol := nb_InitSol + 1;

               Create_system (Sys4, solution_t2p (sol_init4.all));
               Transform_Chromosome_To_CheddarADL_Model
                 (Sys4,
                  solution_t2p (sol_init4.all));
               write_to_xml_file
                 (a_system  => Sys4,
                  file_name =>
                    To_String
                      (suppress_space
                         (To_Unbounded_String ("sol_init4" & ".xmlv3"))));

            end if;
         end if;

         if Check_Feasibility_of_A_Solution
             (solution_t2p (sol_init5.all),
              0)
         then
            put_debug ("===============sol_init5 evaluation ================");
            evaluate_T2P (solution_t2p (sol_init5.all), 0);
            if (Float'value (sol_init5.obj (1)'img) = 0.0) and
              (Float'value (sol_init5.obj (2)'img) = 0.0) and
              (Float'value (sol_init5.obj (3)'img) = 0.0)
            then
               put_debug
                 ("MissedDeadlines" &
                  sol_init5.obj (1)'img &
                  "          Bell    " &
                  sol_init5.obj (2)'img &
                  "          Biba    " &
                  sol_init5.obj (3)'img);
               put_debug
                 ("sol_init5 -- Simple design: no need for optimization");
               archive_soln (generic_solution_ptr (sol_init5));
               Create_system (Sys1, solution_t2p (sol_init5.all));
               Transform_Chromosome_To_CheddarADL_Model
                 (Sys1,
                  solution_t2p (sol_init5.all));
               write_to_xml_file
                 (a_system  => Sys1,
                  file_name =>
                    To_String
                      (suppress_space
                         (To_Unbounded_String ("sol_init5" & ".xmlv3"))));
               OS_Exit (0);
            else
               archive_soln (generic_solution_ptr (sol_init5));
               update_grid (generic_solution_ptr (sol_init5));
               Append
                 (Data3,
                  " 0" &
                  "              " &
                  sol_init5.obj (1)'img &
                  "              " &
                  sol_init5.obj (2)'img &
                  "              " &
                  sol_init5.obj (3)'img &
                  "              " &
                  sol_init5.security_config'img &
                  "              " &
                  ASCII.LF);
               put_debug
                 ("sol5" &
                  "              " &
                  sol_init5.obj (1)'img &
                  "              " &
                  sol_init5.obj (2)'img &
                  "              " &
                  sol_init5.obj (3)'img &
                  "              " &
                  ASCII.LF);

               nb_InitSol := nb_InitSol + 1;

               Create_system (Sys5, solution_t2p (sol_init5.all));
               Transform_Chromosome_To_CheddarADL_Model
                 (Sys5,
                  solution_t2p (sol_init5.all));
               write_to_xml_file
                 (a_system  => Sys5,
                  file_name =>
                    To_String
                      (suppress_space
                         (To_Unbounded_String ("sol_init5" & ".xmlv3"))));

            end if;
         end if;
         if Check_Feasibility_of_A_Solution
             (solution_t2p (sol_init6.all),
              0)
         then
            put_debug ("===============sol_init6 evaluation ================");
            evaluate_T2P (solution_t2p (sol_init6.all), 0);
            if (Float'value (sol_init6.obj (1)'img) = 0.0) and
              (Float'value (sol_init6.obj (2)'img) = 0.0) and
              (Float'value (sol_init6.obj (3)'img) = 0.0)
            then
               put_debug
                 ("MissedDeadlines" &
                  sol_init6.obj (1)'img &
                  "          Bell    " &
                  sol_init6.obj (2)'img &
                  "          Biba    " &
                  sol_init6.obj (3)'img);
               put_debug
                 ("sol_init6 -- Simple design: no need for optimization");
               archive_soln (generic_solution_ptr (sol_init6));
               Create_system (Sys1, solution_t2p (sol_init6.all));
               Transform_Chromosome_To_CheddarADL_Model
                 (Sys1,
                  solution_t2p (sol_init6.all));
               write_to_xml_file
                 (a_system  => Sys1,
                  file_name =>
                    To_String
                      (suppress_space
                         (To_Unbounded_String ("sol_init6" & ".xmlv3"))));
               OS_Exit (0);
            else
               archive_soln (generic_solution_ptr (sol_init6));
               update_grid (generic_solution_ptr (sol_init6));
               Append
                 (Data3,
                  " 0" &
                  "              " &
                  sol_init6.obj (1)'img &
                  "              " &
                  sol_init6.obj (2)'img &
                  "              " &
                  sol_init6.obj (3)'img &
                  "              " &
                  sol_init6.security_config'img &
                  "              " &
                  ASCII.LF);
               put_debug
                 ("sol6" &
                  "              " &
                  sol_init6.obj (1)'img &
                  "              " &
                  sol_init6.obj (2)'img &
                  "              " &
                  sol_init6.obj (3)'img &
                  "              " &
                  ASCII.LF);

               nb_InitSol := nb_InitSol + 1;

               Create_system (Sys6, solution_t2p (sol_init6.all));
               Transform_Chromosome_To_CheddarADL_Model
                 (Sys6,
                  solution_t2p (sol_init6.all));
               write_to_xml_file
                 (a_system  => Sys6,
                  file_name =>
                    To_String
                      (suppress_space
                         (To_Unbounded_String ("sol_init6" & ".xmlv3"))));
            end if;
         end if;

      end if;
      if Check_Feasibility_of_A_Solution (solution_t2p (c.all), 0) then
         evaluate_T2P (solution_t2p (c.all), 0);

         put_debug ("===============c evaluation finish================");

         if (Float'value (c.obj (1)'img) = 0.0) and
           (Float'value (c.obj (2)'img) = 0.0) and
           (Float'value (c.obj (3)'img) = 0.0)
         then
            put_debug
              ("MissedDeadlines" &
               c.obj (1)'img &
               "          Bell    " &
               c.obj (2)'img &
               "          Biba    " &
               c.obj (3)'img);
            put_debug ("Simple design: no need for optimization");

            archive_soln (c);
            Create_system (Sys7, solution_t2p (c.all));
            Transform_Chromosome_To_CheddarADL_Model
              (Sys7,
               solution_t2p (c.all));
            write_to_xml_file
              (a_system  => Sys7,
               file_name =>
                 To_String
                   (suppress_space (To_Unbounded_String ("c" & ".xmlv3"))));

            OS_Exit (0);
         else
            archive_soln (c);
            update_grid (c);
            Append
              (Data3,
               " 0" &
               "              " &
               c.obj (1)'img &
               "              " &
               c.obj (2)'img &
               "              " &
               c.obj (3)'img &
               "              " &
               solution_t2p (c.all).security_config'img &
               "              " &
               ASCII.LF);
            nb_InitSol := nb_InitSol + 1;

            Create_system (Sys7, solution_t2p (c.all));
            Transform_Chromosome_To_CheddarADL_Model
              (Sys7,
               solution_t2p (c.all));
            write_to_xml_file
              (a_system  => Sys7,
               file_name =>
                 To_String
                   (suppress_space (To_Unbounded_String ("c" & ".xmlv3"))));

         end if;
      else  -- if c (that is supposed to be the first current solution) is non feasible
         if arclength > 0 then -- if the archive is not empty
            c.all :=
              arc
                (1).all; --the first element of the archive becomes the first current solution
         else
            put_debug ("All the initial solutions are non feasible");
            return;
         end if;

      end if;

   end init_T2P;

   ----------------
   -- mutate_T2P --
   ----------------

   procedure mutate_T2P
     (s    : in out generic_solution'class;
      eidx : in     Natural)
   is

      random_partition,
      random_app,
      tn,
      x,
      half_iter,
      cn,
      finish,
      sol_config               : Integer;
      l                        : Integer := 0;
      A_system                 : systems.system;
      A_Task_set, New_Task_set : tasks_set;
      counter, counter2        : Integer;

      Sol_is_mutated : Boolean;

      A_sol : solution_t2p;

      G                : Ada.Numerics.Float_Random.Generator;
      New_resource_set : resources_set;

      A_task_source : generic_task_ptr;
      A_task_sink   : generic_task_ptr;

      task_source : Integer;
      task_sink   : Integer;
   begin

      Create_system (A_system, solution_t2p (s));
      Sol_is_mutated := False;
      Reset (G); -- Initialise the float generator
      half_iter := iterations / 2;
      Put_Line ("half_iter: " & half_iter'img);

      -- We  add a counter, if this counter reach a threashold
      -- and it failed to generate a mutated solution then we stop

      counter := 1;

      while (not Sol_is_mutated) and (counter <= 100000) loop

         put_debug
           ("................................................................");
         put_debug
           ("The " & counter'img & " attempt of the mutation procedure ");
         put_debug
           ("................................................................");

         put_debug
           ("................................................................");
         put_debug
           ("The " & counter'img & " attempt of the mutation procedure ");
         put_debug
           ("................................................................");

         A_sol := solution_t2p (s);

         random_partition := 0;
         while (random_partition > nb_partitions) or (random_partition < 1)
         loop
            random_partition := Integer (Float (nb_partitions) * Random (G));
         end loop;
         Put_Line
           ("The randomly chosen partition is : " & random_partition'img);
         if (exploration_version = 1) or
           ((exploration_version = 2) and (iter < half_iter))
         then
            random_app := 0;
            while (random_app > nb_app) or (random_app < 1) loop
               random_app := Integer (Float (nb_app) * Random (G));
            end loop;
            Put_Line
              ("The randomly chosen application is : " & random_app'img);
            -- Move tasks of the random_app to the random_partition
            for l in 1 .. genes loop
               if (task_to_app (l) = random_app) then
                  A_sol.chrom_task (l) := random_partition;
               end if;
               Sol_is_mutated := True;
            end loop;
         elsif (exploration_version = 3) or
           ((exploration_version = 2) and (iter >= half_iter))
         then

            --  choose randomly an index of a task between 1 and genes
            tn := 0;
            while (tn > genes) or (tn < 1) loop
               tn := Integer (Float (genes) * Random (G));
            end loop;

            put_debug ("The randomly chosen task is : " & tn'img);
            -- the task "tn" is not intially in the partition "random_partition" then "tn" is moved
            -- to the partition "random_partition"
            if (random_partition /= A_sol.chrom_task (tn)) then
               A_sol.chrom_task (tn) := random_partition;
               Sol_is_mutated        := True;
            end if;

         end if;

         --  choose randomly the configuration to secure communications
         sol_config := 0;
         Reset (G); -- Initialise the float generator
         if (intra_partition_safe = 1) then
            -- intra partition communications are attackable
            sol_config := 1;
         else
            while (sol_config > 4) or (sol_config < 2) loop
               sol_config := Integer (4.0 * Random (G));
            end loop;
         end if;
         if (sol_config /= A_sol.security_config) then
            A_sol.security_config := sol_config;
            Sol_is_mutated        := True;
         end if;

         Put ("The chosen configuration is : " & sol_config'img);

         -- communication mutation
         -- choose randomly an index of a task between 1 and genes_com between risky communications Low
         x           := 0;
         task_source := 1;
         task_sink   := 1;
         counter2    := 0;
         if (intra_partition_safe = 0) then
            -- intra communications non attackable; so an intra communication should not be chosen
            while
              ((x > Nb_NonSecure_low) or
               (x < 1) or
               (A_sol.chrom_task (task_source) =
                A_sol.chrom_task (task_sink))) and
              (counter2 < 50)
            loop
               counter2 := counter2 + 1;
               x        := Integer (Float (Nb_NonSecure_low) * Random (G));
               if (x <= Nb_NonSecure_low) and (x >= 1) then
                  cn          := NonSecure_list (x);
                  finish      := Index (A_sol.chrom_com (cn).source_sink, "_");
                  task_source :=
                    Integer'value
                      (To_String
                         (suppress_space
                            (Unbounded_Slice
                               (solution_t2p (s).chrom_com (cn).source_sink,
                                1,
                                finish - 1))));
                  task_sink :=
                    Integer'value
                      (To_String
                         (Unbounded_Slice
                            (solution_t2p (s).chrom_com (cn).source_sink,
                             finish + 1,
                             Length
                               (solution_t2p (s).chrom_com (cn)
                                  .source_sink))));
               end if;

            end loop;
            if (counter2 >= 50) then
               New_Line;
               Put_Line
                 ("No inter partition communications choosed to be secured");
            else
               put_debug ("The randomly chosen communication is : " & cn'img);
               put_debug
                 ("This chosen communication is : " &
                  solution_t2p (s).chrom_com (cn).mode'img &
                  " " &
                  To_String (solution_t2p (s).chrom_com (cn).source_sink));
               finish := Index (A_sol.chrom_com (cn).source_sink, "_");

               A_task_source :=
                 search_task
                   (Initial_System.tasks,
                    suppress_space
                      (Unbounded_Slice
                         (solution_t2p (s).chrom_com (cn).source_sink,
                          1,
                          finish - 1)));
               A_task_sink :=
                 search_task
                   (Initial_System.tasks,
                    suppress_space
                      (Unbounded_Slice
                         (solution_t2p (s).chrom_com (cn).source_sink,
                          finish + 1,
                          Length
                            (solution_t2p (s).chrom_com (cn).source_sink))));

               if
                 (A_task_sink.mils_confidentiality_level <
                  A_task_source.mils_confidentiality_level) or
                 (A_task_source.mils_integrity_level <
                  A_task_sink.mils_integrity_level)
               then
                  if
                    ((A_task_sink.mils_task /= downgrader) and
                     (A_task_sink.mils_task /= upgrader) and
                     (A_task_source.mils_task /= downgrader) and
                     (A_task_source.mils_task /= upgrader))
                  then
                     if (A_sol.chrom_com (cn).mode = nosecure) then
                        A_sol.chrom_com (cn).mode := secure;
                        Sol_is_mutated            := True;
                     elsif (A_sol.chrom_com (cn).mode = secure) then
                        A_sol.chrom_com (cn).mode := nosecure;
                        Sol_is_mutated            := True;
                     end if;
                  end if;
               end if;
            end if;

         elsif (intra_partition_safe = 1) then
            while (x > Nb_NonSecure_low) or (x < 1) loop
               x := Integer (Float (Nb_NonSecure_low) * Random (G));
            end loop;
            cn     := NonSecure_list (x);
            finish := Index (A_sol.chrom_com (cn).source_sink, "_");
            put_debug ("The randomly chosen communication is : " & cn'img);
            put_debug
              ("This chosen communication is : " &
               solution_t2p (s).chrom_com (cn).mode'img &
               " " &
               To_String (solution_t2p (s).chrom_com (cn).source_sink));
            finish := Index (A_sol.chrom_com (cn).source_sink, "_");

            A_task_source :=
              search_task
                (Initial_System.tasks,
                 suppress_space
                   (Unbounded_Slice
                      (solution_t2p (s).chrom_com (cn).source_sink,
                       1,
                       finish - 1)));
            A_task_sink :=
              search_task
                (Initial_System.tasks,
                 suppress_space
                   (Unbounded_Slice
                      (solution_t2p (s).chrom_com (cn).source_sink,
                       finish + 1,
                       Length (solution_t2p (s).chrom_com (cn).source_sink))));

            if
              (A_task_sink.mils_confidentiality_level <
               A_task_source.mils_confidentiality_level) or
              (A_task_source.mils_integrity_level <
               A_task_sink.mils_integrity_level)
            then
               if
                 ((A_task_sink.mils_task /= downgrader) and
                  (A_task_sink.mils_task /= upgrader) and
                  (A_task_source.mils_task /= downgrader) and
                  (A_task_source.mils_task /= upgrader))
               then
                  if (A_sol.chrom_com (cn).mode = nosecure) then
                     A_sol.chrom_com (cn).mode := secure;
                     Sol_is_mutated            := True;
                  elsif (A_sol.chrom_com (cn).mode = secure) then
                     A_sol.chrom_com (cn).mode := nosecure;
                     Sol_is_mutated            := True;
                  end if;
               end if;
            end if;

         end if;

         if Sol_is_mutated then

            put_debug (" ");
            put_debug ("The mutated solution is : ");
            print_debug_genome (A_sol);
            put_debug (" ");
            -- normalize the mutate solution
            normalize (A_sol);
            put_debug (" ");
            put_debug ("After normalization the candidate solution is : ");
            Put_Line ("After normalization the candidate solution is : ");
            print_debug_genome (A_sol);
            put_debug (" ");

         -- After generating a mutate solution, we shoud verify
         -- if it is feasible else we must regenerate a new candidate solution:
            --

            if Check_Feasibility_of_A_Solution (A_sol, eidx) then

               put_debug (" The candidate solution is feasible");
               Sol_is_mutated                   := True;
               s := generic_solution'class (A_sol);
               nb_secu_conf_choice (sol_config) :=
                 nb_secu_conf_choice (sol_config) + 1;
            else

               put_debug
                 (" The candidate solution is NOt Feasible " &
                  " we should regenerate another candidate solution");
               Sol_is_mutated    := False;
               counter           := counter + 1;
               nb_NoFeasible_Sol := nb_NoFeasible_Sol + 1;

            end if;

         end if;

      end loop;

      if counter > 100000 then
         put_debug (" ");--New_Line;
         put_debug (" ");--New_Line;
         put_debug
           ("Exit the program, there is no schedulable candidate solution !");
         put_debug (" ");--New_Line;
         put_debug (" ");--New_Line;
         OS_Exit (0);
      end if;

   end mutate_T2P;

   procedure generate_next_element_T2P
     (s    : in out solution_t2p;
      i, j : in out Integer)
   is
   begin
      if (i <= genes) then
         if (s.chrom_task (i) = 0) then
            s.chrom_task (i) := 1;
         else
            s.chrom_task (i) := s.chrom_task (i) + 1;
         end if;
      end if;

      if j <= Nb_NonSecure_low then

         s.chrom_com (NonSecure_list (j)).mode := undefined;
         if (s.chrom_com (NonSecure_list (j)).mode = undefined) then
            s.chrom_com (NonSecure_list (j)).mode := nosecure;

         elsif (s.chrom_com (NonSecure_list (j)).mode = nosecure) then
            s.chrom_com (NonSecure_list (j)).mode := secure;

         elsif (s.chrom_com (NonSecure_list (j)).mode = secure) then
            s.chrom_com (NonSecure_list (j)).mode := undefined;
         end if;

      end if;

   end generate_next_element_T2P;

   --------------------------------
   -- generate_next_solution_T2P --
   --------------------------------

   procedure generate_next_solution_T2P
     (s                         : in out solution_t2p;
      space_search_is_exhausted :    out Boolean)
   is

      i, j, k : Integer;
      g       : solution_t2p;
      non     : Boolean := True;
   begin

      i := 1;
      j := 1;
      k := 1;

      space_search_is_exhausted := False;
      while (space_search_is_exhausted = False) loop

         generate_next_element_T2P (s, i, j);
         if (s.chrom_task (i) <= nb_partitions) and (i < genes) then
            i := i + 1;
         --    j := j+1;
         elsif (s.chrom_task (i) <= nb_partitions) and (i = genes) then

            nb_sol_Exhaus := nb_sol_Exhaus + 1;
            print_genome (s);
            g := s;
         elsif (s.chrom_task (i) > nb_partitions) and (i > 1) then
            s.chrom_task (i) := 0;
            i                := i - 1;
         elsif (s.chrom_task (i) > nb_partitions) and (i = 1) then
            space_search_is_exhausted := True;
         end if;

      end loop;

   end generate_next_solution_T2P;

   ---------------
   -- Normalize --
   ---------------

   procedure normalize (s : in out solution_t2p) is

      nb_partitions : Integer := 1;
      --  the vector var is used to know if a gene is normalized or not yet
      var : chrom_task_type;
   begin
      --  initialization of the vector var.
      for i in 1 .. genes loop
         var (i) := 0;
         --         var2(i) :=0;
      end loop;

      ------------------------------------------------------------
      --  if var(i) = 0   ==>  s.chrom(i) is not yet normalized
      --  if var(i) = 1   ==>  s.chrom(i) is normalized
      ------------------------------------------------------------

      for i in 1 .. genes loop

         if (var (i) = 0) then

            for j in i + 1 .. genes loop
               if (s.chrom_task (j) = s.chrom_task (i))
                 and then (var (j) = 0)
               then
                  var (j) := 1;
                  --  if s.chrom(i) is not normalized then all s.chrom(j) (which egal s.all.chrom(i))
                  --  are not normalized
                  if (s.chrom_task (i) /= nb_partitions) then
                     s.chrom_task (j) := nb_partitions;
                  end if;
               end if;
            end loop;

            -- we normalize s.chrom(i)
            if (s.chrom_task (i) /= nb_partitions) then
               s.chrom_task (i) := nb_partitions;
            end if;
            var (i)       := 1;
            nb_partitions := nb_partitions + 1;
         end if;
      end loop;

   end normalize;

   ---------------------
   -- Number_of_partitions --
   ---------------------

   function Number_of_partitions (s : in solution_t2p) return Integer is
      permutation        : Integer := 1;
      var                : chrom_task_type;
      nb_partitions, tmp : Integer;
   begin
      --  assignment of the table var with elements of s.chrom
      for i in 1 .. genes loop
         var (i) := s.chrom_task (i);
      end loop;

      --  sorting elements of var in the increasing order
      while permutation = 1 loop
         permutation := 0;
         for i in 1 .. genes - 1 loop
            if (var (i) > var (i + 1)) then
               tmp         := var (i);
               var (i)     := var (i + 1);
               var (i + 1) := tmp;
               permutation := 1;
            end if;
         end loop;
      end loop;

      nb_partitions := genes;

      for i in 1 .. genes - 1 loop
         if (var (i) = var (i + 1)) then
            nb_partitions := nb_partitions - 1;
         end if;
      end loop;

      return nb_partitions;

   end Number_of_partitions;

   ----------------------------------------------
   -- Transform_Chromosome_To_CheddarADL_Model --
   ----------------------------------------------

   procedure Transform_Chromosome_To_CheddarADL_Model
     (A_sys : in out systems.system;
      s     : in     solution_t2p)
   is

      A_Tasks_set : tasks_set;
      A_Task      : periodic_task;

      k                              : Integer;
      period_i                       : Natural;
      capacity_i                     : Natural;
      deadline_i                     : Natural;
      priority_i                     : Natural;
      criticality_i                  : Natural;
      confidentiality_i, integrity_i : Unbounded_String;

   begin

      -- 1) Generate the tasks set from the solution s
      --

      initialize (A_sys.tasks);
      initialize (A_sys.dependencies.depends);
      for i in 1 .. genes loop
         k        := s.chrom_task (i);
         period_i :=
           get
             (my_tasks   => Initial_System.tasks,
              task_name  => suppress_space (To_Unbounded_String ("" & i'img)),
              param_name => period);

         capacity_i :=
           get
             (my_tasks   => Initial_System.tasks,
              task_name  => suppress_space (To_Unbounded_String ("" & i'img)),
              param_name => capacity);

         deadline_i :=
           get
             (my_tasks   => Initial_System.tasks,
              task_name  => suppress_space (To_Unbounded_String ("" & i'img)),
              param_name => deadline);
         priority_i :=
           get
             (my_tasks   => Initial_System.tasks,
              task_name  => suppress_space (To_Unbounded_String ("" & i'img)),
              param_name => task_set.priority);
         criticality_i :=
           get
             (my_tasks   => Initial_System.tasks,
              task_name  => suppress_space (To_Unbounded_String ("" & i'img)),
              param_name => criticality);
         confidentiality_i :=
           get
             (my_tasks   => Initial_System.tasks,
              task_name  => suppress_space (To_Unbounded_String ("" & i'img)),
              param_name => mils_confidentiality_level);
         integrity_i :=
           get
             (my_tasks   => Initial_System.tasks,
              task_name  => suppress_space (To_Unbounded_String ("" & i'img)),
              param_name => mils_integrity_level);
         add_task
           (my_tasks           => A_sys.tasks,
            name => suppress_space (To_Unbounded_String ("" & i'img)),
            cpu_name => suppress_space (To_Unbounded_String ("processor1")),
            address_space_name =>
              suppress_space (To_Unbounded_String ("addr" & k'img)),
            core_name => suppress_space (To_Unbounded_String ("")),
            task_type                  => periodic_type,
            start_time                 => 0,
            capacity                   => capacity_i,
            period                     => period_i,
            deadline                   => deadline_i,
            jitter                     => 0,
            blocking_time              => 0,
            priority                   => priority_i,
            criticality                => criticality_i,
            policy                     => Sched_policy,
            mils_confidentiality_level =>
              mils_confidentiality_level_type'value
                (To_String (confidentiality_i)),
            mils_integrity_level =>
              mils_integrity_level_type'value (To_String (integrity_i)));
         --       Put_Line("task "& i'Img & " capacity_i : " & capacity_i'Img);
         New_Line;

      end loop;

      -- 2) Generate the dependencies and secure the system depending on the choosen security configuration
      --
      nb_bell_resolved := 0;
      nb_biba_resolved := 0;
      if (s.security_config = 1) then
         security_configuration1 (A_sys, s);
      elsif (s.security_config = 2) then
         security_configuration2 (A_sys, s);
      elsif (s.security_config = 3) then
         security_configuration3 (A_sys, s);
      elsif (s.security_config = 4) then
         security_configuration4 (A_sys, s);
      end if;

      -- consider inter and intra communications overheads
      com_overhead (A_sys);

      put_debug ("end_transform");
   end Transform_Chromosome_To_CheddarADL_Model;

   -------------------------------------------
   -- consider inter and intra partition --
   -------------------------------------------
   procedure com_overhead (A_sys : in out systems.system) is
      My_iterator     : tasks_dependencies_iterator;
      Dep_Ptr         : dependency_ptr;
      My_dependencies : tasks_dependencies_ptr;
      m               : Integer;
   begin
      My_dependencies := A_sys.dependencies;
      if is_empty (My_dependencies.depends) then
         Put_Line ("NO dependencies");
      else
         reset_iterator (My_dependencies.depends, My_iterator);
         loop
            current_element (My_dependencies.depends, Dep_Ptr, My_iterator);
            m := Integer'value (To_String (Dep_Ptr.precedence_source.name));
            if
              (Dep_Ptr.precedence_source.address_space_name =
               Dep_Ptr.precedence_sink.address_space_name)
            then
               Dep_Ptr.precedence_source.capacity :=
                 Dep_Ptr.precedence_source.capacity +
                 display_blackboard_time_values (task_to_app (m));
               Dep_Ptr.precedence_sink.capacity :=
                 Dep_Ptr.precedence_sink.capacity +
                 read_blackboard_time_values (task_to_app (m));
            else
               Dep_Ptr.precedence_source.capacity :=
                 Dep_Ptr.precedence_source.capacity +
                 write_sampling_port_time_values (task_to_app (m));
               Dep_Ptr.precedence_sink.capacity :=
                 Dep_Ptr.precedence_sink.capacity +
                 read_sampling_port_time_values (task_to_app (m));
            end if;
            exit when is_last_element (My_dependencies.depends, My_iterator);
            next_element (My_dependencies.depends, My_iterator);
         end loop;
      end if;
   end com_overhead;

   -- communication_cost --
   -------------------
   procedure communication_cost
     (sys      : in     systems.system;
      com_cost :    out com_cost_type)
   is
      My_iterator     : tasks_dependencies_iterator;
      Dep_Ptr         : dependency_ptr;
      My_dependencies : tasks_dependencies_ptr;
      m               : Integer;
   begin
      My_dependencies := sys.dependencies;
      if is_empty (My_dependencies.depends) then
         Put_Line ("NO dependencies");
      else
         for i in 1 .. 5 loop
            com_cost (i) := 0.0;
         end loop;
         reset_iterator (My_dependencies.depends, My_iterator);
         loop
            current_element (My_dependencies.depends, Dep_Ptr, My_iterator);
            m := Integer'value (To_String (Dep_Ptr.precedence_source.name));
            if
              (Dep_Ptr.precedence_source.address_space_name =
               Dep_Ptr.precedence_sink.address_space_name)
            then
               com_cost (1) := com_cost (1) + 1.0;
               com_cost (2) := com_cost (2) + 1.0;
               com_cost (5) :=
                 com_cost (5) +
                 Float
                   (display_blackboard_time_values (task_to_app (m)) *
                    (Hyperperiod_of_Initial_Taskset /
                     Dep_Ptr.precedence_source.deadline) +
                    read_blackboard_time_values (task_to_app (m)) *
                      (Hyperperiod_of_Initial_Taskset /
                       Dep_Ptr.precedence_sink.deadline));
            else
               com_cost (3) := com_cost (3) + 1.0;
               com_cost (4) := com_cost (4) + 1.0;
               com_cost (5) :=
                 com_cost (5) +
                 Float
                   (write_sampling_port_time_values (task_to_app (m)) *
                    (Hyperperiod_of_Initial_Taskset /
                     Dep_Ptr.precedence_source.deadline) +
                    read_sampling_port_time_values (task_to_app (m)) *
                      (Hyperperiod_of_Initial_Taskset /
                       Dep_Ptr.precedence_sink.deadline));
            end if;
            exit when is_last_element (My_dependencies.depends, My_iterator);
            next_element (My_dependencies.depends, My_iterator);
         end loop;
      end if;
   end communication_cost;

   -------------------
   -- Create_system --
   -------------------

   procedure Create_system
     (A_system : in out systems.system;
      s        : in     solution_t2p)
   is

      a_core                    : core_unit_ptr;
      a_core_unit_table         : core_units_table;
      mem                       : memories_table;
      partition_sched_file_name : Unbounded_String;
      nb_part                   : Integer;

   begin

      initialize (A_system);

      -- Generate partitions
      for i in 1 .. Number_of_partitions (s) loop
         --    for i in 1.. nb_partitions loop
         --            if (s.chrom_partition_PU(i)=j) then
         add_address_space
           (my_address_spaces => A_system.address_spaces,
            name => suppress_space (To_Unbounded_String ("addr" & i'img)),
            cpu_name => suppress_space (To_Unbounded_String ("processor1")),
            text_memory_size  => 0,
            stack_memory_size => 0,
            data_memory_size  => 0,
            heap_memory_size  => 0,
            a_scheduler       => posix_1003_highest_priority_first_protocol);
      end loop;

      if (s.security_config < 10) then
         nb_part := Number_of_partitions (s);
      else
         nb_part := Number_of_partitions (s) + 1;
      end if;
      partition_sched_file_name :=
        suppress_space
          (To_Unbounded_String
             ("partition_scheduling_paes" & nb_part'img & ".xml"));
      add_core_unit
        (my_core_units            => A_system.core_units,
         a_core_unit              => a_core,
         name => suppress_space (To_Unbounded_String ("core1")),
         is_preemptive            => preemptive,
         quantum                  => 0,
         speed                    => 1,
         capacity                 => 0,
         period                   => 0,
         priority                 => 0,
         file_name                => partition_sched_file_name,
         scheduling_protocol_name => suppress_space (To_Unbounded_String ("")),
         a_scheduler              => The_Scheduler,
         mem                      => mem);

      add (a_core_unit_table, a_core);

      add_processor
        (my_processors => A_system.processors,
         name          => suppress_space (To_Unbounded_String ("processor1")),
         a_core        => a_core);

   end Create_system;

end Paes.chromosome_Data_Manipulation_t2p_and_security;