with Text_IO; use Text_IO; with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; with unbounded_strings; use unbounded_strings; use unbounded_strings.strings_table_package; use unbounded_strings.unbounded_string_list_package; with unbounded_strings; use unbounded_strings; with Parameters; use Parameters; with Parameters.extended; use Parameters.extended; use Parameters.Framework_Parameters_Table_Package; with Systems; use Systems; with Framework; use Framework; 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 Ada.Directories; use Ada.Directories; with Ada.text_IO; use Ada.text_IO; with Ada.Command_Line; use Ada.Command_Line; with GNAT.Command_Line; use GNAT.Command_Line; with GNAT.OS_Lib; use GNAT.OS_Lib; 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.Calendar; use Ada.Calendar; with Ada.Calendar.Formatting; use Ada.Calendar.Formatting; with Ada.Text_IO; use Ada.Text_IO; with Paes_For_Clustering; with Paes; use Paes; with unbounded_strings; use unbounded_strings; with Tasks; use Tasks; with Task_Set; use Task_Set; with Task_Clustering_Rules; use Task_Clustering_Rules; with feasibility_test.feasibility_interval; use feasibility_test.feasibility_interval; with Pipe_Commands; use Pipe_Commands; with Ada.Text_IO; use Ada.Text_IO; with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; with Ada.Text_IO.Unbounded_IO; use Ada.Text_IO.Unbounded_IO; with Ada.Directories; use Ada.Directories; with Paes_For_Clustering; use Paes_For_Clustering; with Hypervolume_computation; use Hypervolume_computation; with scheduler_Interface; use scheduler_Interface; with framework_config; use framework_config; with Ada.Integer_Text_IO; use Ada.Integer_Text_IO; with exact_front_computation1; use exact_front_computation1; with Ada.Containers.Vectors; use Ada.Containers; use Ada.Containers; procedure call_exact_front_computation is package Fix_IO is new Ada.Text_IO.Fixed_IO(DAY_DURATION); use Fix_IO; My_tasks : Tasks_set; Dir : unbounded_string; Dir2 : unbounded_string; Data,Data2,Data3,Data4,Data5 : Unbounded_String; F : Ada.Text_IO.File_Type; dir1 : unbounded_string_list; A_capacity : natural; A_period : natural; A_deadline : natural; H : integer; FileStream : stream; command : unbounded_String; F1,F2,F3,F4,F5 : Ada.Text_IO.File_Type; line : unbounded_String; Buffer : unbounded_String; scheduler_Name : unbounded_String; obj2_Name : unbounded_String; initial_task_set_file_name : unbounded_string; Max_hyperperiod : integer; package Flt_IO is new Ada.Text_IO.Float_IO(FLOAT); use Flt_IO; Year,Month,Day : INTEGER; Start,Ends,Duration : DAY_DURATION; Time_And_Date : TIME; --All_consistent_valid_solutions : tab_sol_type(1..1000); --nb_consistent : integer; --nb_consistent_sched : integer; --dom_tab : Int_Array(1..1000); Nb_Non_dominated_sol : integer := 0; Exact_Pareto_front : tab_sol_type(1..100); package dom_Container is new Vectors (Positive, Integer); use dom_Container; dom_tab : dom_Container.Vector; Cursor1,Cursor2 : Solution_Container.Cursor; Cursor3 : dom_Container.Cursor; k, j : integer; begin Call_Framework.initialize (False); -- Get arguments -- loop case GNAT.Command_Line.Getopt ("n: sched: obj2: i:") is when ASCII.NUL => exit; when 'n' => genes := Integer'Value(GNAT.Command_Line.Parameter); Put_Line ("Number of functions = " & genes'img); when 's' => if Full_Switch = "sched" then scheduler_Name := To_Unbounded_String (GNAT.Command_Line.Parameter); Put_Line ("The scheduler is " & To_string(scheduler_Name)); if scheduler_Name = "RM" then The_Scheduler := Rate_Monotonic_Protocol; Task_priority := 1; Sched_policy := SCHED_FIFO; elsif scheduler_Name = "EDF" then The_Scheduler := Earliest_Deadline_First_Protocol; Task_priority := 0; Sched_policy := SCHED_OTHERS; else OS_Exit (0); end if; end if; when 'o' => if Full_Switch = "obj2" then obj2_Name := To_Unbounded_String (GNAT.Command_Line.Parameter); if obj2_Name = "sum_lax" or obj2_Name = "min_lax" then Second_fitness_function := obj2_Name; Put_Line ("The second fitness function is " & To_string(obj2_Name)); else OS_Exit (0); end if; end if; when 'i' => initial_task_set_file_name := To_Unbounded_String (GNAT.Command_Line.Parameter); Put_Line ("The initial_task_set_file_name is " & To_string(initial_task_set_file_name)); when others => OS_Exit (0); end case; end loop; Create(F3,Ada.Text_IO.Out_File,"Time_of_execution.txt"); Time_And_Date := Clock; Split(Time_And_Date, Year, Month, Day, Start); -- we use the task set described in the xml file given in argument initialize(Sys); Read_From_Xml_File (Sys, dir1, initial_task_set_file_name); My_tasks := Sys.Tasks; Build_xml_model (My_tasks, "candidate_solution.xmlv3"); H := Scheduling_Period (Sys.Tasks, to_unbounded_string("processor1")); Hyperperiod_of_Initial_Taskset := H; -- Check the schedulability of the given task set command := To_Unbounded_String("/media/DATA/These_Rahma/CHEDDAR/trunk/src/call_cheddar_d " & Hyperperiod_of_Initial_Taskset'img & " candidate_solution.xmlv3"); FileStream := execute(To_String(command), read_file); loop begin Buffer := read_next(FileStream); exception when Pipe_Commands.End_of_file => exit; end; end loop; close(FileStream); Open(F1, Ada.Text_IO.In_File,"Output.txt"); line := To_Unbounded_String(get_line(F1)); line := Unbounded_Slice(line,1,3); if line = "sch" then Initial_tasks_set := My_tasks; Put_Line ("The initial tasks set is schedulable"); line := To_Unbounded_String(get_line(F1)); line := Unbounded_Slice(line, index(line,"=") + 3, length(line)); Nb_preemption_of_the_candidate_sol := integer'Value(to_string(Unbounded_Slice(line,1,length(line)))); put_line("Nb_preemptions = " & Nb_preemption_of_the_candidate_sol'Img); line := To_Unbounded_String(get_line(F1)); line := Unbounded_Slice(line, index(line,"=") + 3, length(line)); Sum_laxities_of_the_candidate_sol := integer'Value (to_string(Unbounded_Slice(line,1,length(line)))); put_line("sum_lax = " & Sum_laxities_of_the_candidate_sol'Img); line := To_Unbounded_String(get_line(F1)); line := Unbounded_Slice(line, index(line,"=") + 3, length(line)); Min_laxities_of_the_candidate_sol := integer'Value (to_string(Unbounded_Slice(line,1,length(line)))); put_line("Min_lax = " & Min_laxities_of_the_candidate_sol'Img); else Put_Line ("The initial tasks set is not schedulable!"); return; end if; Close(F1); build_xml_model (Initial_tasks_set, "initial_tasks_set.xmlv3"); for i in 1..genes loop A_capacity := Task_Set.Get (My_Tasks => Initial_tasks_set, Task_Name => Suppress_Space (To_Unbounded_String ("Task" & i'Img)), Param_Name => Capacity); A_period := Task_Set.Get (My_Tasks => Initial_tasks_set, Task_Name => Suppress_Space (To_Unbounded_String ("Task" & i'Img)), Param_Name => Period); A_deadline := Task_Set.Get (My_Tasks => Initial_tasks_set, Task_Name => Suppress_Space (To_Unbounded_String ("Task" & i'Img)), Param_Name => Deadline); Ada.text_IO.Put (" C" & i'Img & " = " & A_capacity'Img); Ada.text_IO.Put (" T" & i'Img & " = " & A_period'Img); Ada.text_IO.Put (" D" & i'Img & " = " & A_deadline'Img); New_Line; end loop; New_Line; H := Scheduling_Period (Initial_tasks_set, to_unbounded_string("processor1")); Hyperperiod_of_Initial_Taskset := H; Put_Line ("The hyperperiod of the initial task set = " & H'Img); Max_hyperperiod := Hyperperiod_of_Initial_Taskset; -------------------------------------- -- Exact search of the pareto front -- -------------------------------------- New_Line; New_Line; enumerate_sol; Put_Line(" ************************************************************************************************ "); Put_Line(" The number of all consistent solutions = " & nb_consistent'Img); Put_Line(" The number of all consistent and schedulable solutions = " & nb_consistent_sched'Img); Put_Line(" consistent and schedulable solutions are ... "); Cursor1 := Solution_Container.First(All_consistent_valid_solutions); k := 1; while Solution_Container.Has_Element(Cursor1) loop Append(Data4, Integer(Solution_Container.Element(Cursor1).obj(1))'Img & "," & Integer(Solution_Container.Element(Cursor1).obj(2))'Img & ASCII.LF); Append(Data5, Integer(Solution_Container.Element(Cursor1).obj(1))'Img & "," & Integer(Hyperperiod_of_Initial_Taskset - Integer(Solution_Container.Element(Cursor1).obj(2)))'Img & ASCII.LF); Put_Line("---------------------------------------------------------------------------------------"); Put("Solution " & k'img & ": "); print_genome(Solution_Container.Element(Cursor1)); Put_Line("Objectives of solution " & k'img & " : "); Put_Line (" | Number of preemptions = " & Integer(Solution_Container.Element(Cursor1).obj(1))'Img & " | " & To_String(Second_fitness_function) & " = " & Integer(Hyperperiod_of_Initial_Taskset - Integer(Solution_Container.Element(Cursor1).obj(2)))'Img & " "); Put_Line("---------------------------------------------------------------------------------------"); Solution_Container.Next(Cursor1); k := k + 1; end loop; New_Line; Put_Line(" *********************************************************************************************** "); -- Compute the exact pareto front from all consistent and schedulable solutions for i in 1 .. nb_consistent_sched loop dom_Container.Append(dom_tab, -1); --dom_tab(i) := -1; end loop; Cursor1 := Solution_Container.First(All_consistent_valid_solutions); k := 1; while Solution_Container.Has_Element(Cursor1) loop Cursor2 := Solution_Container.First(All_consistent_valid_solutions); j := 1; while Solution_Container.Has_Element(Cursor2) loop if (k /= j) then if ( (Solution_Container.Element(Cursor1).obj(1) >= Solution_Container.Element(Cursor2).obj(1)) and (Solution_Container.Element(Cursor1).obj(2) >= Solution_Container.Element(Cursor2).obj(2)) ) then if ( (Solution_Container.Element(Cursor1).obj(1) > Solution_Container.Element(Cursor2).obj(1)) or (Solution_Container.Element(Cursor1).obj(2) > Solution_Container.Element(Cursor2).obj(2)) ) then dom_Container.Replace_Element (Container => dom_tab, Index => k, New_Item => 1); --dom_tab(i) := 1; end if; end if; end if; Solution_Container.Next(Cursor2); j := j + 1; end loop; k := k + 1; Solution_Container.Next(Cursor1); end loop; k := 1; Cursor3 := dom_Container.First(dom_tab); while dom_Container.Has_Element(Cursor3) loop if (dom_Container.Element(Cursor3) = -1) then Nb_Non_dominated_sol := Nb_Non_dominated_sol + 1; Exact_Pareto_front (Nb_Non_dominated_sol) := Solution_Container.Element(All_consistent_valid_solutions,k); end if; k := k + 1; dom_Container.Next(Cursor3); end loop; Put_Line("====================================================================================================== "); Put_Line(" The number of the exact pareto front solutions = " & Nb_Non_dominated_sol'Img); Put_Line(" The exact pareto front solutions are ... "); for i in 1..Nb_Non_dominated_sol loop Append(Data2, Integer(Exact_Pareto_front(i).obj(1))'Img & "," & Integer(Exact_Pareto_front(i).obj(2))'Img & ASCII.LF); Put_Line("---------------------------------------------------------------------------------------"); Put("Solution " & i'img & ": "); print_genome(Exact_Pareto_front(i)); build_xml_model (Appling_clustering_rules(Exact_Pareto_front(i)), To_string(Suppress_Space (To_Unbounded_String ("solution" & i'Img & ".xmlv3")))); Put_Line ("Objectives of solution " & i'img & " : "); Put_Line (" || Number of preemptions = " & Integer(Exact_Pareto_front(i).obj(1))'Img & " | " & To_String(Second_fitness_function) & " = " & Integer(Hyperperiod_of_Initial_Taskset - Integer(Exact_Pareto_front(i).obj(2)))'Img & " || "); Put_Line("---------------------------------------------------------------------------------------"); end loop; Put_Line("====================================================" & "================================================== "); Create(F2,Ada.Text_IO.Out_File,"exact_front.txt"); Unbounded_IO.Put_Line(F2, Data2); Close(F2); Create(F4,Ada.Text_IO.Out_File,"Valid_sol2.txt"); Unbounded_IO.Put_Line(F4, Data4); Close(F4); Create(F5,Ada.Text_IO.Out_File,"Valid_sol1.txt"); Unbounded_IO.Put_Line(F5, Data5); Close(F5); Time_And_Date := Clock; Split(Time_And_Date, Year, Month, Day, Ends); Duration:= Ends - Start; Put("Paes_computation_time" & ASCII.HT & ":"); Put(Duration, 8, 8, 0); Put_Line(""); Append (Data3, ASCII.LF & "Exact_Front_computation_time " & ":"); Unbounded_IO.Put(F3, Data3); Ada.Strings.Unbounded.Delete(Data3, 1, Length(Data3)); Put(F3, Duration, 8, 8, 0); Close(F3); end call_exact_front_computation;