Psim3 Simulation Model - PowerPoint PPT Presentation

1 / 9
About This Presentation
Title:

Psim3 Simulation Model

Description:

Declare pointer variables to the various objects in the model. For example: ... trout = new waitq('Trout Chan'); tr = new waitq('TR Chan'); (C) J. M. Garrido. 7 ... – PowerPoint PPT presentation

Number of Views:143
Avg rating:3.0/5.0
Slides: 10
Provided by: ITS2
Category:

less

Transcript and Presenter's Notes

Title: Psim3 Simulation Model


1
Psim3 Simulation Model
  • Declare constants and variables of the model. For
    example
  • double simperiod // simulation period
  • Declare forward class definitions
  • class controller // declaration of class
  • Declare pointer variables to the various objects
    in the model. For example
  • gate gate_obj // ptr var to gate object
  • waitq cg // ptr var to channel object
  • simulation run // simulation engine

2
Psim3 Simulation Model
  • Class specification for all objects in the model
  • // Process definitions
  • // model class
  • class Train public process
  • public
  • Train(char name) // constructor
  • void Main_body () // main body of process

3
Psim3 Simulation Model
  • Class implementations
  • TrainTrain (char name) process (name)
  • cout ltlt t_name ltlt " created " ltlt endl
  • void TrainMain_body()
  • double mean_enter 45.5 // average
    inter-arrival period of trains
  • double mean_exit 20.75 // average
    inter-departure period of trains
  • double y 12.5 // latest delay for
    controller to signal gate
  • z 11.25 // time taken to
    open/close gate

4
Class Implementations (2)
  • se_obj new sensor_e("Entry sensor",
    mean_enter)
  • sl_obj new sensor_l("Exit sensor",
    mean_exit)
  • cont_obj new controller("Controller", y)
  • gate_obj new gate("Gate", z, y)
  • monit_obj new monitor("Monitor")
  • //
  • se_obj-gtpstart()
  • sl_obj-gtpstart()
  • cont_obj-gtpstart()
  • gate_obj-gtpstart()
  • monit_obj-gtpstart()
  • //
  • run-gtstart_sim(simperiod) // start
    simulation

5
Class Implementations (3)
  • //
  • cout ltlt endl
  • cout ltlt "---------------------------------------
    --" ltlt endl
  • cout ltlt "Total trains that arrived " ltlt
    trains_arr ltlt endl
  • cout ltlt "Average system reaction time "
  • ltlt avg_reaction / float(trains_arr) ltlt
    endl
  • cout ltlt "Average system response time "
  • ltlt avg_response / float(trains_arr) ltlt
    endl
  • cout ltlt "Worst reaction time " ltlt
    worst_reaction ltlt endl
  • cout ltlt "Worst response time " ltlt
    worst_response ltlt endl
  • cout ltlt "Number of deadlines missed in closing
    Gate "
  • ltlt close_deadline ltlt endl
  • cout ltlt "Number deadlines missed, Controller
    comm with Gate "
  • ltlt deadline_g ltlt endl

6
Psim3 Model -- Function main
  • int main ()
  • run new simulation("Simple Gate-Train
    Model")
  • simperiod 2200.25
  • close_arrival 1750.10 // no more train
    arrivals
  • //
  • // Channel objects creation and initialization
  • //
  • cg new waitq("CG Channel")
  • og new waitq("OG Channel")
  • gok new waitq("GOK Channel")
  • cont_cg new waitq("CCG Chan")
  • cont_og new waitq("COG Chan")
  • trin new waitq("Trin Chan")
  • trout new waitq("Trout Chan")
  • tr new waitq("TR Chan")

7
Psim3 Model -- Function main
  • // Process initialization
  • //
  • Train mtrain // declaration of the
    reference variable for
  • // the object of the simulation model
  • //
  • mtrain new Train("Train simulation") //
    Create train object
  • mtrain-gtpstart() //
    start its thread
  • run-gtend_sim()
  • return(0)

8
Main Body
  • void controllerMain_body()
  • double wait_t
  • //
  • while (get_clock() lt simperiod)
  • get_sclose() // get signal from monitor
    to close
  • // and send close signal to gate
  • get_sopen() // get signal from monitor
    to open
  • // and send open signal to gate
  • // end while
  • terminate()
  • // end Main_body

9
Using delay()
  • void controlleralarm_cl()
  • close_deadline // deadline missed
  • cout ltlt "Alarm, Gate has not completely
    closed at" ltlt get_clock() ltlt endl
  • delay(1.15) // some delay before
    comm
  • // end alarm_cl
Write a Comment
User Comments (0)
About PowerShow.com