Simulation begin

	proces class auto(speed, load, time_in, time_out);
	real speed, load, time_in, time_out;
	begin

		procedure transport(distance);
			hold( distance/speed);
		procedure waiting(queue);
			ref (head) queue ;
			inspect queue do
				if empty then into(this head) else wait(this head);
		procedure departure (queue);
			ref (head) queue ;
			begin out; activate queue.first end;

	while true do
		begin
			waiting(source_queue);
			if sand > 0 	then
				begin
					sand := sand- load; full := full+l;
					hold(time_in);
				end
						else passivate;
			departure (source_queue); transport (ac);
			into(tr_queue);
			inspect pred do
				if this link qua process.evtime > time +cd/speed then
					reactivate this process after this link;
				else transport(cd)
			otherwise transport(cd);
			out; transport(db);
			waiting(target_queue);
			hold(time_out); full:=full-l;
			if sand <= 0 and full=0 then activate main;
			departure(target_queue); transport(ba);
		end
end auto;

ref (head) source_queue, target_queue; tr_queue;
real sand, ac, cd, db, ba;
integer full;

source_queue:- new head;  target_queue:- new head;
tr_queue:- new head;
sand:- inreal;
ac:- inreal;  cd:- inreal;  db:- inreal;  ba:- inreal;

while not lastitem do
	activate new auto( inreal; inreal; inreal; inreal) at time;

passivate;

outtext("transport ends in time: "); outfix(time,5,10);
outimage;

end  program