300 likes | 375 Views
Day 1, Section 1 Problem Solution C:Program FilesSimscript3modelsREADFILE2. 1 Preamble 2 3 '' Program to Read and Print a Commented Data File - CACI Products Company 4 '' files: READFILE.SRC, ACFT.DAT 5 6 Normally mode is undefined 7
E N D
Day 1, Section 1 Problem SolutionC:\Program Files\Simscript3\models\READFILE2 1 Preamble 2 3 '' Program to Read and Print a Commented Data File - CACI Products Company 4 '' files: READFILE.SRC, ACFT.DAT 5 6 Normally mode is undefined 7 8 End ''Preamble 1 Main 2 3 Call INP.220.READ.AIRCRAFT.DATA 4 5 Print 2 lines thus Press <CR> to end program... 8 9 Read as / using unit 5 10 11 End ''Main End ''Main Ex1-1 —————————— CACI Products Company ———————————————————————————— SimScript II.5 ——————————————
1 Routine INP.220.READ.AIRCRAFT.DATA 2 3 Define .AUTHORIZED.NUMBER as an integer variable 4 5 Define .ROUTINE.NAME, 6 .SHORT.NAME, 7 .DATE, 8 .AIRCRAFT.NAME and 9 .LOCATION 10 as text variables 11 12 '' Open the input unit 13 14 Open unit 10 for input, name = "ACFT.DAT" 15 Use unit 10 for input 16 17 Open unit 11 for output, name = "ACFT.OUT" 18 Use unit 11 for output 19 20 '' Read the file name and date; if not correct, print error message 21 '' and stop 22 23 Read .ROUTINE.NAME, 24 .DATE 25 26 Let .SHORT.NAME = substr.f(.ROUTINE.NAME, 1, 7) 27 Ex1-2 —————————— CACI Products Company ———————————————————————————— SimScript II.5 ——————————————
28 If .SHORT.NAME is not equal to "INP.220" 29 30 Print 2 lines with .SHORT.NAME thus File name does not agree with routine name ******* INP.220 33 34 Trace 35 Stop 36 37 Endif ''.SHORT.NAME is not equal to "INP.220" 38 39 '' Print the name and date to the standard output; skip 2 lines 40 41 Print 1 line with .ROUTINE.NAME, 42 .DATE thus ****************************** ********** 44 45 Skip 2 output lines 46 47 '' Jump over the comments in the data file 48 49 While mode is alpha 50 Do 51 Start new record 52 Loop ''mode is alpha do 53 54 Start new input record 55 Ex1-3 —————————— CACI Products Company ———————————————————————————— SimScript II.5 ——————————————
56 '' As long as there is data in the file, read 3 fields and print them 57 58 While data is not ended 59 Do 60 61 Read .AIRCRAFT.NAME, 62 .AUTHORIZED.NUMBER 63 Read .LOCATION as t * 64 65 Print 1 line with .AIRCRAFT.NAME, 66 .AUTHORIZED.NUMBER and 67 .LOCATION thus ***** ** ********************************* 69 70 Loop ''data is not ended 71 72 '' Close the input unit and return 73 74 Close unit 10 75 Close unit 11 76 77 End ''INP.220 Ex1-4 —————————— CACI Products Company ———————————————————————————— SimScript II.5 ——————————————
This page is intentionally blank Ex1-5 —————————— CACI Products Company ———————————————————————————— SimScript II.5 ——————————————
Day 2, Section 3 Problem SolutionC:\Program Files\Simscript3\models\TELPHN2 1 Preamble 2 3 '' A simple telephone system model - CACI Products Company 4 '' files: TELPHN1.SRC 5 6 Normally mode is undefined 7 8 Processes include 9 GENERATOR 10 11 Every INCOMING.CALL has 12 a CALL.ID 13 14 Define CALL.ID as an integer variable 15 16 Define NUMBER.OF.CALLS, 17 NUMBER.BUSY and 18 LOST.CALLS 19 as integer variables 20 21 Define SIMULATION.LENGTH, 22 TOTAL.TIME 23 as real variables 24 25 26 End ''Preamble Ex3-1 —————————— CACI Products Company ———————————————————————————— SimScript II.5 ——————————————
1 Main 2 3 Print 1 line thus Please enter the length of the simulation in minutes 5 6 Read SIMULATION.LENGTH 7 8 Let TOTAL.TIME = 0.0 9 Let NUMBER.OF.CALLS = 0 10 11 Activate a GENERATOR now 12 13 Start simulation 14 15 Print 2 lines with NUMBER.OF.CALLS, 16 LOST.CALLS, 17 TOTAL.TIME / (NUMBER.OF.CALLS - LOST.CALLS) thus **** phone calls were made and ** were lost due to busy lines The average call lasted ****.** minutes 20 21 Read as / using unit 5 22 23 End ''Main Ex3-2 —————————— CACI Products Company ———————————————————————————— SimScript II.5 ——————————————
1 Process GENERATOR 2 3 Until time.v > (SIMULATION.LENGTH / (24. * 60.0)) 4 Do 5 Add 1 to NUMBER.OF.CALLS 6 Activate a INCOMING.CALL now 7 Let CALL.ID(INCOMING.CALL) = NUMBER.OF.CALLS 8 9 Wait uniform.f (2.0, 6.0, 1) minutes 10 11 Loop ''time.v > SIMULATION.LENGTH 12 13 End ''GENERATOR Ex3-3 —————————— CACI Products Company ———————————————————————————— SimScript II.5 ——————————————
1 Process INCOMING.CALL 2 3 Define .LENGTH.OF.CALL as a real variable 4 5 If NUMBER.BUSY < 2 6 7 Add 1 to NUMBER.BUSY 8 Let .LENGTH.OF.CALL = uniform.f(6.0, 10.0, 2) 9 Add .LENGTH.OF.CALL to TOTAL.TIME 10 Wait .LENGTH.OF.CALL minutes 11 Subtract 1 from NUMBER.BUSY 12 13 Else 14 15 Add 1 to LOST.CALLS 16 17 Endif ''NUMBER.BUSY < 2 18 19 End ''INCOMING.CALL Ex3-4 —————————— CACI Products Company ———————————————————————————— SimScript II.5 ——————————————
Output Data Please enter the length of the simulation in minutes 480 In 480.0 minutes, 118 phone calls were made and 26 were lost due to busy lines The average call lasted 8.06 minutes Ex3-5 —————————— CACI Products Company ———————————————————————————— SimScript II.5 ——————————————
This page is intentionally blank Ex3-6 —————————— CACI Products Company ———————————————————————————— SimScript II.5 ——————————————
Day 3, Section 5 Problem SolutionC:\Program Files\Simscript3\models\EventPort2 1 Preamble 2 3 '' CACI Products Company 4 '' 5 '' The Port model using events - Day 1 Solution 6 '' Source Code: EventPort.SRC 7 8 Normally mode is undefined 9 10 ''Major events are requesting & releasing the dock and the tugs. 11 Event notices include 12 SHIP.GENERATOR, 13 REQUEST.DOCK, 14 REQUEST.TUG, 15 RELEASE.TUG, 16 RELEASE.DOCK and 17 FINAL.REPORT 18 19 Every REQUEST.TUG has an RQT.SHIP.PTR 20 Define RQT.SHIP.PTR as a pointer variable 21 Every RELEASE.TUG has an RLT.SHIP.PTR 22 Define RLT.SHIP.PTR as a pointer variable 23 Every RELEASE.DOCK has an RD.SHIP.PTR 24 Define RD.SHIP.PTR as a pointer variable 25 26 ''SHIPS are the entities that travel through the system Ex5-1 —————————— CACI Products Company ———————————————————————————— SimScript II.5 ——————————————
27 Temporary entities 28 29 Every SHIP has 30 a SHIP.ARRIVAL.TIME, 31 a SHIP.STATUS and 32 a SHIP.UNLOAD.TIME and 33 a SHIP.TUG.BEING.USED 34 belongs to the QUE.DOCK, the EXE.DOCK 35 and the QUE.TUG 36 37 Define SHIP.ARRIVAL.TIME and SHIP.UNLOAD.TIME 38 as real variables 39 Define SHIP.STATUS as an integer variable 40 Define SHIP.TUG.BEING.USED as a pointer variable 41 42 Every TUG has 43 a TUG.STATUS 44 and belongs to the TUG.SET 45 46 Define TUG.STATUS as an integer variable 47 48 ''Service is provided by a HARBOR that contains docks and tugs 49 Permanent entities 50 51 Every HARBOR has a 52 NUMBER.OF.DOCKS and 53 owns a QUE.DOCK, an EXE.DOCK, 54 a TUG.SET, and a QUE.TUG 55 56 Define NUMBER.OF.DOCKS as integer variables 57 Ex5-2 —————————— CACI Products Company ———————————————————————————— SimScript II.5 ——————————————
58 '' Input Global variables 59 60 Define RUN.LENGTH as a real variable 61 62 '' Output Global Variables provide statistics collection 63 Define TOTAL.WAITING.TIME and MAX.WAITING.TIME as real variables 64 Define NO.OF.SHIPS.SERVED as an integer variable 65 66 '' Synonyms provide clarity to the model 67 Define ..AT.HARBOR to mean 1 68 Define ..TO.DOCK to mean 2 69 Define ..AT.DOCK to mean 3 70 Define ..TO.SEA to mean 4 71 Define ..AT.SEA to mean 5 72 Define ..IN.USE to mean 6 73 74 End ''Preamble Ex5-3 —————————— CACI Products Company ———————————————————————————— SimScript II.5 ——————————————
1 Main 2 3 Call READ.DATA ''to set up simulation 4 5 Schedule a FINAL.REPORT in RUN.LENGTH days 6 Schedule a SHIP.GENERATOR now ''to create new ships 7 8 Start simulation 9 10 End ''Main 1 Event SHIP.GENERATOR 2 saving the event notice 3 4 If time.v <= RUN.LENGTH 5 6 Schedule a REQUEST.DOCK now 7 Reschedule this SHIP.GENERATOR in uniform.f(4.0, 18.0, 1) hours 8 9 Endif ''time.v <= RUN.LENGTH 10 11 End ''SHIP.GENERATOR Ex5-4 —————————— CACI Products Company ———————————————————————————— SimScript II.5 ——————————————
1 Routine READ.DATA 2 3 Define .I, .NBR.TUGS and .NBR.DOCKS as integer variables 4 Define .TUG as a pointer variable 5 6 Open unit 10 for input, name = "PORT.DAT" 7 Use unit 10 for input 8 9 Skip 3 fields 10 Read .NBR.TUGS 11 12 Skip 3 fields 13 Read .NBR.DOCKS 14 15 Skip 3 fields 16 Read RUN.LENGTH 17 18 Close unit 10 19 20 ''Create 1 harbor that contains .NBR.DOCKS & .NBR.TUGS 21 Let N.HARBOR = 1 22 Create each HARBOR 23 For .I = 1 to .NBR.TUGS 24 Do 25 Create a TUG called .TUG 26 Let TUG.STATUS(.TUG) = ..AT.HARBOR 27 File .TUG in the TUG.SET(1) 28 Loop 29 Let NUMBER.OF.DOCKS(1) = .NBR.DOCKS 30 31 End ''READ.DATA Ex5-5 —————————— CACI Products Company ———————————————————————————— SimScript II.5 ——————————————
1 Event REQUEST.DOCK 2 3 Define .PROBABILITY as a real variable 4 Define .SHIP as a pointer variable 5 6 ''Create a new ship and set up attributes for unloading time, 7 ''arrival time and status. Arrival time is used to calculate 8 ''the total time in system when the ship leaves the harbor. 9 Create a SHIP called .SHIP 10 11 ''Unloading time differs for each type of ship 12 Let .PROBABILITY = random.f(2) 13 Select case .PROBABILITY 14 Case 0.0 to 0.25 15 Let SHIP.UNLOAD.TIME(.SHIP) = uniform.f(16.0,20.0,3) 16 Case 0.25 to 0.80 17 Let SHIP.UNLOAD.TIME(.SHIP) = uniform.f(21.0, 27.0, 3) 18 Default 19 Let SHIP.UNLOAD.TIME(.SHIP) = uniform.f(32.0, 40.0, 3) 20 Endselect ''.PROBABILITY 21 22 ''Store time ship enters system 23 Let SHIP.ARRIVAL.TIME(.SHIP) = time.v 24 25 ''Set status 26 Let SHIP.STATUS(.SHIP) = ..AT.HARBOR Ex5-6 —————————— CACI Products Company ———————————————————————————— SimScript II.5 ——————————————
27 28 ''Grab dock if available. Then schedule a request for a Tug 29 ''to take SHIP to the dock 30 If N.EXE.DOCK(1) < NUMBER.OF.DOCKS(1) 31 32 File .SHIP in the EXE.DOCK(1) 33 Schedule a REQUEST.TUG giving .SHIP now 34 35 Else 36 37 File .SHIP in the QUE.DOCK(1) 38 39 Endif ''N.EXE.DOCK(1) < NUMBER.OF.DOCKS(1) 40 41 End ''REQUEST.DOCK Ex5-7 —————————— CACI Products Company ———————————————————————————— SimScript II.5 ——————————————
1 Event REQUEST.TUG 2 given .RQT.SHIP.PTR 3 4 Define .RQT.SHIP.PTR, .TUG.TO.USE as pointer variables 5 Define .TRANSPORT.TIME as a real variable 6 7 Call FIND.TUG.AVAILABILITY 8 giving SHIP.STATUS(.RQT.SHIP.PTR) 9 yielding .TUG.TO.USE 10 11 ''Tug is available 12 If .TUG.TO.USE <> 0 13 14 Let SHIP.TUG.BEING.USED(.RQT.SHIP.PTR) = .TUG.TO.USE 15 16 If TUG.STATUS(.TUG.TO.USE) = SHIP.STATUS(.RQT.SHIP.PTR) 17 Let .TRANSPORT.TIME = 1.0 18 Else 19 Let .TRANSPORT.TIME = 1.25 20 Endif 21 22 Let TUG.STATUS(.TUG.TO.USE) = ..IN.USE 23 Ex5-8 —————————— CACI Products Company ———————————————————————————— SimScript II.5 ——————————————
24 ''Change the ship status. If ship has just been created, 25 ''indicate that it will be taken to the dock by the tug. 26 ''If the ship was already at the dock, then it has unloaded 27 ''its cargo and is ready to depart to sea 28 Select case SHIP.STATUS(.RQT.SHIP.PTR) 29 Case ..AT.HARBOR 30 Let SHIP.STATUS(.RQT.SHIP.PTR) = ..TO.DOCK 31 Case ..AT.DOCK 32 Let SHIP.STATUS(.RQT.SHIP.PTR) = ..TO.SEA 33 Schedule a RELEASE.DOCK giving .RQT.SHIP.PTR now 34 Default 35 Print 1 line with time.v and SHIP.STATUS(.RQT.SHIP.PTR) thus *******.*** ERROR in REQUEST.TUG: Invalid ship status *** 37 Stop 38 Endselect 39 40 ''1 hour is needed to move the ship to or from the dock, a quarter of 41 ''an hour is added if the tug is in the wrong place 42 43 Schedule a RELEASE.TUG giving .RQT.SHIP.PTR in .TRANSPORT.TIME hours 44 45 Else ''tug is unavailable so wait in the tug's queue 46 47 File .RQT.SHIP.PTR in the QUE.TUG(1) 48 49 Endif ''N.EXE.TUG(1) < NUMBER.OF.TUGS(1) 50 51 End ''REQUEST.TUG Ex5-9 —————————— CACI Products Company ———————————————————————————— SimScript II.5 ——————————————
1 Event RELEASE.TUG 2 given .RLT.SHIP.PTR 3 4 Define .RLT.SHIP.PTR, 5 .TUG.BEING.USED, 6 and .QUEUED.SHIP.PTR as pointer variables 7 Define .TRANSPORT.TIME, 8 .WAITING.TIME as real variables 9 10 ''Release the tug and let tug take the first queued 11 ''ship to its destination. Note that tug position ignored(!) 12 Let .TUG.BEING.USED = SHIP.TUG.BEING.USED(.RLT.SHIP.PTR) 13 Let SHIP.TUG.BEING.USED(.RLT.SHIP.PTR) = 0 14 15 ''If the ship has just arrived at the dock, start unloading. 16 ''Schedule the end of the unloading activity - when tug needed again. 17 ''If ship heading out from dock, schedule an immediate release of 18 ''the dock. Note that dock could be release earlier(!) 19 Select case SHIP.STATUS(.RLT.SHIP.PTR) 20 Case ..TO.DOCK 21 Let SHIP.STATUS(.RLT.SHIP.PTR) = ..AT.DOCK 22 Let TUG.STATUS(.TUG.BEING.USED) = ..AT.DOCK 23 Schedule a REQUEST.TUG giving .RLT.SHIP.PTR 24 in SHIP.UNLOAD.TIME(.RLT.SHIP.PTR) hours Ex5-10 —————————— CACI Products Company ———————————————————————————— SimScript II.5 ——————————————
25 Case ..TO.SEA 26 Let SHIP.STATUS(.RLT.SHIP.PTR) = ..TO.SEA 27 Let TUG.STATUS(.TUG.BEING.USED) = ..AT.HARBOR 28 ''Collect waiting time statistics and count number of ships served 29 Add 1 to NO.OF.SHIPS.SERVED 30 Let .WAITING.TIME = 31 (time.v - SHIP.ARRIVAL.TIME(.RLT.SHIP.PTR)) * hours.v - 32 SHIP.UNLOAD.TIME(.RLT.SHIP.PTR) 33 Add .WAITING.TIME to TOTAL.WAITING.TIME 34 Let MAX.WAITING.TIME = max.f(MAX.WAITING.TIME,.WAITING.TIME) 35 Destroy the SHIP called .RLT.SHIP.PTR 36 Default 37 Print 1 line with time.v and SHIP.STATUS(.RLT.SHIP.PTR) thus *******.*** ERROR in RELEASE.TUG: Invalid current ship status *** 39 Stop 40 Endselect ''SHIP.STATUS(.RLT.SHIP.PTR) 41 42 If the QUE.TUG(1) is not empty 43 44 Remove the first .QUEUED.SHIP.PTR from the QUE.TUG(1) 45 Let SHIP.TUG.BEING.USED(.QUEUED.SHIP.PTR) = .TUG.BEING.USED 46 47 If TUG.STATUS(.TUG.BEING.USED) = SHIP.STATUS(.QUEUED.SHIP.PTR) 48 Let .TRANSPORT.TIME = 1.0 49 Else 50 Let .TRANSPORT.TIME = 1.25 51 Endif Ex5-11 —————————— CACI Products Company ———————————————————————————— SimScript II.5 ——————————————
52 53 Let TUG.STATUS(.TUG.BEING.USED) = ..IN.USE 54 Select case SHIP.STATUS(.QUEUED.SHIP.PTR) 55 Case ..AT.HARBOR 56 Let SHIP.STATUS(.QUEUED.SHIP.PTR) = ..TO.DOCK 57 Case ..AT.DOCK 58 Let SHIP.STATUS(.QUEUED.SHIP.PTR) = ..TO.SEA 59 Schedule a RELEASE.DOCK giving .QUEUED.SHIP.PTR now 60 Default 61 Print 1 line with time.v and 62 SHIP.STATUS(.QUEUED.SHIP.PTR) thus *******.*** ERROR in RELEASE.TUG: Invalid next ship status *** 64 Stop 65 Endselect ''SHIP.STATUS(.QUEUED.SHIP.PTR) 66 67 ''Send the queued ship on its way 68 Schedule a RELEASE.TUG giving .QUEUED.SHIP.PTR in .TRANSPORT.TIME hours 69 70 Endif 71 72 End ''RELEASE.TUG Ex5-12 —————————— CACI Products Company ———————————————————————————— SimScript II.5 ——————————————
1 Event RELEASE.DOCK 2 Given .RD.SHIP.PTR 3 4 Define .RD.SHIP.PTR and .QUEUED.SHIP.PTR as pointer variables 5 6 ''Release the dock and free up computer memory 7 Remove .RD.SHIP.PTR from the EXE.DOCK(1) 8 9 ''Check the dock queue for ships 10 If the QUE.DOCK(1) is not empty 11 12 Remove the first .QUEUED.SHIP.PTR from the QUE.DOCK(1) 13 File .QUEUED.SHIP.PTR in the EXE.DOCK(1) 14 Let SHIP.STATUS(.QUEUED.SHIP.PTR) = ..AT.HARBOR 15 Schedule a REQUEST.TUG giving .QUEUED.SHIP.PTR now 16 17 Endif 18 19 End ''RELEASE.DOCK Ex5-14 —————————— CACI Products Company ———————————————————————————— SimScript II.5 ——————————————
1 Routine FIND.TUG.AVAILABILITY 2 given .STATUS 3 yielding .TUG.TO.USE 4 5 Define .FIRST.CHOICE, 6 .SECOND.CHOICE, 7 .STATUS as integer variables 8 9 Define .TEST.TUG, 10 .TUG.TO.USE as pointer variables 11 12 If .STATUS = ..AT.HARBOR 13 Let .FIRST.CHOICE = ..AT.HARBOR 14 Let .SECOND.CHOICE = ..AT.DOCK 15 Else 16 Let .FIRST.CHOICE = ..AT.DOCK 17 Let .SECOND.CHOICE = ..AT.HARBOR 18 Endif 19 20 For each .TEST.TUG in the TUG.SET(1) 21 with TUG.STATUS(.TEST.TUG) = .FIRST.CHOICE 22 Find the first case 23 If found 24 Let .TUG.TO.USE = .TEST.TUG 25 Return 26 Otherwise Ex5-15 —————————— CACI Products Company ———————————————————————————— SimScript II.5 ——————————————
27 For each .TEST.TUG in the TUG.SET(1) 28 with TUG.STATUS(.TEST.TUG) = .SECOND.CHOICE 29 Find the first case 30 If found 31 Let .TUG.TO.USE = .TEST.TUG 32 Endif 33 34 End ''FIND.TUG.AVAILABILITY Ex5-16 —————————— CACI Products Company ———————————————————————————— SimScript II.5 ——————————————
1 Event FINAL.REPORT 2 3 Skip 2 output lines 4 5 Print 4 lines with RUN.LENGTH thus Pacific Port Problem (Answer to Student Problem 1) Run length is **** days. 10 Skip 2 output lines 11 12 Print 4 lines with time.v, 13 NO.OF.SHIPS.SERVED, 14 TOTAL.WAITING.TIME/NO.OF.SHIPS.SERVED and 15 MAX.WAITING.TIME thus After ***.** days, *** ships have been unloaded. The average waiting time was **.** hours. The maximum waiting time was **.** hours. 20 21 Skip 2 lines 22 23 Read as / using unit 5 24 25 Stop 26 27 End ''FINAL.REPORT Ex5-17 —————————— CACI Products Company ———————————————————————————— SimScript II.5 ——————————————
Results Pacific Port Problem (Solution to Student Problem 7) Run length is 365 Days. After 365 days, 792 ships have been unloaded. The average waiting time was 4.08 hours The maximum waiting time was 33.00 hours Ex5-18 —————————— CACI Products Company ———————————————————————————— SimScript II.5 ——————————————
This page is intentionally blank Ex3-6 —————————— CACI Products Company ———————————————————————————— SimScript II.5 ——————————————
Day 4, Section 7 Problem SolutionC:\Program Files\Simscript3\models\Messageh Open project messageh to see clock with minute hand —————————— CACI Products Company ———————————————————————————— SimScript II.5 ——————————————