Skip to content

Instantly share code, notes, and snippets.

@pukpr
Created December 12, 2023 15:51
Show Gist options
  • Save pukpr/32cc4adbaf256a287541034f3a402007 to your computer and use it in GitHub Desktop.
Save pukpr/32cc4adbaf256a287541034f3a402007 to your computer and use it in GitHub Desktop.
with GNAT.Expect; use GNAT.Expect;
with GNAT.Os_Lib; use GNAT.OS_Lib;
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Exceptions;
with Ada.Integer_Text_IO;
with Ada.Long_Float_Text_IO;
with Ada.Command_Line;
procedure eexp is
Command : constant String := ".\enso_opt.exe r";
Pd : Process_Descriptor;
Args : Argument_List_Access;
Result : Expect_Match;
Count : Integer := 0;
Trigger : Long_Float;
function Get_First_Arg_As_Float return Long_Float is
Value : Long_Float := 0.75;
begin
-- Check if at least one argument is provided
if Ada.Command_Line.Argument_Count >= 1 then
Value := Long_Float'Value (Ada.Command_Line.Argument(1));
else
Put_Line("No arguments provided, default=" & Value'Img);
end if;
return Value;
end Get_First_Arg_As_Float;
begin
Trigger := Get_First_Arg_As_Float;
Args := Argument_String_To_List (Command);
Non_Blocking_Spawn
(Pd,
Command => Args (Args'First).all,
Args => Args (Args'First + 1 .. Args'Last),
Buffer_Size => 0);
loop
-- Read a line from the subprocess
Expect (Pd, Result, ".+\n", Timeout => 1000_000);
-- Exit loop if subprocess is terminated or an error occurs
exit when Result = Expect_Timeout;
declare
Line : String := Expect_Out (Pd);
N, L : Integer;
F : Long_Float;
begin
-- Put(Line);
if Line'Length > 6 and then Line(1..7) = "Status:" then
count := Count + 1;
L := 8;
Ada.Integer_Text_IO.get(Line(L+1..Line'Last), N, L);
Ada.Integer_Text_IO.get(Line(L+1..Line'Last), N, L);
Ada.Long_Float_Text_IO.get(Line(L+1..Line'Last), F, L);
if F > Trigger then
-- Send 'q' to subprocess
Put(Line);
Send (Pd, "q");
--delay 20.0;
--exit;
else
if Count mod 100 = 0 then
Put(Line);
end if;
Send (Pd, "4");
end if;
end if;
end;
end loop;
Send (Pd, "x");
--Close (Pd);
exception
when E: others =>
Put( Ada.Exceptions.Exception_Information(E));
end eexp;
@pukpr
Copy link
Author

pukpr commented Dec 12, 2023

1900-2000 fit 30 trials, trigger of cc=0.75

image

f9=0 cc=0.72
image

f9=1 cc=0.75
image

f9=1 cc=0.75 trials=15
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment