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