PageRenderTime 4ms CodeModel.GetById 1ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/test/language/gc/aux_agent_gc2.e

http://github.com/tybor/Liberty
Specman e | 110 lines | 75 code | 14 blank | 21 comment | 7 complexity | 0653c8982b7c03789d92ccac4e6d1194 MD5 | raw file
  1-- This file is part of SmartEiffel The GNU Eiffel Compiler Tools and Libraries.
  2-- See the Copyright notice at the end of this file.
  3--
  4class AUX_AGENT_GC2
  5
  6create {ANY}
  7   make
  8
  9feature {ANY}
 10   alea: AUX_AGENT_GC4
 11
 12   discharged: AUX_AGENT_GC5
 13
 14   is_main: BOOLEAN
 15
 16   staff: INTEGER
 17
 18   triage, examination, treatment, transfers: AUX_AGENT_GC6
 19
 20   make (staf, seed: INTEGER; main: BOOLEAN)
 21      do
 22         alea.set_seed(seed)
 23         staff := staf
 24         is_main := main
 25      end
 26
 27   triage_examination
 28      do
 29         transfers.clear
 30         treatment.for_each(agent discharge_one_patient(?))
 31         examination.for_each(agent treat_or_transfert_one_patient(?))
 32         triage.for_each(agent triage_one_patient(?))
 33         if alea.test(0.7) then
 34            new_arrival(create {AUX_AGENT_GC3})
 35         end
 36      end
 37
 38   new_arrival (p: AUX_AGENT_GC3)
 39      do
 40         p.enter_hospital
 41         if staff <= 0 then
 42            triage.add(p)
 43         else
 44            staff := staff - 1
 45            examination.add(p)
 46            p.wait(3)
 47         end
 48      end
 49
 50   discharge_one_patient (p: AUX_AGENT_GC3)
 51      do
 52         p.next_time
 53         if p.finished then
 54            staff := staff + 1
 55            treatment.remove(p)
 56            discharged.add(p)
 57         end
 58      end
 59
 60   treat_or_transfert_one_patient (p: AUX_AGENT_GC3)
 61      do
 62         p.next_time
 63         if p.finished then
 64            examination.remove(p)
 65            if alea.test(0.1) or else is_main then
 66               treatment.add(p)
 67               p.wait(10)
 68            else
 69               staff := staff + 1
 70               transfers.add(p)
 71            end
 72         end
 73      end
 74
 75   triage_one_patient (p: AUX_AGENT_GC3)
 76      do
 77         if staff <= 0 then
 78            p.incr_hospital_time
 79         else
 80            staff := staff - 1
 81            triage.remove(p)
 82            examination.add(p)
 83            p.wait(3)
 84         end
 85      end
 86
 87   accumulate_totals: AUX_AGENT_GC5
 88      do
 89         Result := discharged + triage.accumulate_totals + examination.accumulate_totals + treatment.accumulate_totals
 90      end
 91
 92end -- class AUX_AGENT_GC2
 93--
 94-- ------------------------------------------------------------------------------------------------------------------------------
 95-- Copyright notice below. Please read.
 96--
 97-- SmartEiffel is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License,
 98-- as published by the Free Software Foundation; either version 2, or (at your option) any later version.
 99-- SmartEiffel is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY; without even the implied warranty
100-- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have
101-- received a copy of the GNU General Public License along with SmartEiffel; see the file COPYING. If not, write to the Free
102-- Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
103--
104-- Copyright(C) 1994-2002: INRIA - LORIA (INRIA Lorraine) - ESIAL U.H.P.       - University of Nancy 1 - FRANCE
105-- Copyright(C) 2003-2006: INRIA - LORIA (INRIA Lorraine) - I.U.T. Charlemagne - University of Nancy 2 - FRANCE
106--
107-- Authors: Dominique COLNET, Philippe RIBET, Cyril ADRIAN, Vincent CROIZIER, Frederic MERIZEN
108--
109-- http://SmartEiffel.loria.fr - SmartEiffel@loria.fr
110-- ------------------------------------------------------------------------------------------------------------------------------