Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pragma Ada_2022;
- with queues_generic.priority;
- with Ada.Text_IO;
- with Ada.Integer_Text_IO;
- procedure Simulation with Spark_mode is
- NumQueues : CONSTANT Positive := 4;
- subtype QueueNumber is Positive range 1..NumQueues;
- type CustomerRecord is RECORD
- ArrivalTime: Positive;
- NumItems: Positive;
- end RECORD;
- package MarketQueues is NEW Queues_Generic (Element => CustomerRecord);
- USE MarketQueues;
- type SingleQueue (Capacity: Positive) is record
- Size: Natural;
- List: Queue (Capacity);
- end record with Dynamic_Predicate => Size <= Capacity;
- LimitSizeQueue: constant := 20;
- type Market is ARRAY(1..NumQueues) OF SingleQueue (20);
- Queues: Market;
- type Eventtype is (Arrival, Departure);
- type Event (T: Eventtype := Arrival) is record
- case T is
- when Arrival =>
- Arrivaltime: Positive;
- NBitems: Positive;
- when Departure =>
- DepartureTime: Positive;
- Nb: QueueNumber;
- end case;
- end record;
- subtype Arrivaltype is Event (Arrival);
- subtype Departuretype is Event (Departure);
- function KeyOf (E: Event) return Positive is
- ((if E.T = Arrival then E.ArrivalTime else E.DepartureTime));
- package EventQueues is NEW Queues_generic (Element => Event);
- package EventQueuesPriority is NEW EventQueues.Priority (Positive);
- use EventQueuesPriority;
- subtype EventQueue is EventQueuesPriority.Queue;
- EventList: EventQueue (Capacity => 4);
- use Ada.Text_IO;
- InputFile : Ada.Text_IO.File_type;
- function MostAvailableQueue return QueueNumber
- with Global => Queues is
- SmallestQueue: Natural := Queues(1).Size;
- begin
- for A of Queues (2..Queues'Last) when A.Size < SmallestQueue loop
- SmallestQueue := A.Size;
- end loop;
- return SmallestQueue;
- end MostAvailableQueue;
- E: Event;
- procedure AddArrival
- with Exceptional_Cases => (Data_Error => True),
- Global => (Input => InputFile, Output => E) is
- Last: Positive;
- Line: constant String := Get_line (InputFile);
- use Ada.Integer_text_io;
- begin
- Get (Line, E.Arrivaltime, Last);
- Get(Line(Last+1..Line'Last), E.NBitems, Last);
- Enqueue (EventList, E);
- exception when others =>
- Put_line ("Line ill formated: """ & Line & "");
- raise;
- end AddArrival;
- procedure ProcessArrival (ArrivalTime: IN Positive; NumItems: IN Positive)
- with Global => (In_Out => Queues) is
- begin
- pragma Unimplemented_Unit;
- null;
- end ProcessArrival;
- procedure ProcessDeparture(DepartureTime: IN Positive; Q: IN OUT MarketQueues.Queue)
- is
- begin
- pragma Unimplemented_Unit;
- null;
- end ProcessDeparture;
- begin
- begin
- Open (Inputfile, In_File, "data");
- exception when others =>
- Put_line ("No ""data"" file, closing.");
- raise;
- end;
- declare
- Last: Positive;
- Line: constant String := Get_line (InputFile);
- begin
- Get(Line, E.Arrivaltime, Last);
- Get(Line(Last+1..Line'Last), E.NBitems, Last);
- Enqueue (EventList, E);
- exception when others =>
- Put_line ("Line ill formated: """ & Line & "");
- raise;
- end;
- return;
- exception when others =>
- return;
- end Simulation;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement