? 9? Arena ?? ? Customization - PowerPoint PPT Presentation

1 / 34
About This Presentation
Title:

? 9? Arena ?? ? Customization

Description:

9 Arena Customization ( ) ActiveX ... – PowerPoint PPT presentation

Number of Views:186
Avg rating:3.0/5.0
Slides: 35
Provided by: BernardF3
Category:

less

Transcript and Presenter's Notes

Title: ? 9? Arena ?? ? Customization


1
? 9? Arena ?? ? Customization

2
?? ??
  • ? ??? ????? ?? ??? ?? ?? ?? ??(??? ??)
  • ActiveX ???? VBA ? ??? ?? ?? ????? ??
  • ?? ??? ????? ?? ??
  • ??? ?? ?? ?? ?? ??? ??? Excel? ??? ??
  • ?? ?? ?? ?? ??? ??? ??

3
?? 9-1 ??? ?????? ?? ?? ??
  • ? ?? ???? ?? ?? ??? ?? ?? ??
  • model 09-01.txt ASCII ??? ??

4
?? 9-1 ??? ?????? ?? ?? ??
  • Create ?? ??
  • ReadWrite ??
  • (??? ??)

5
?? 9-1 ??? ?????? ?? ?? ??
  • Delay ?? ?? ?? ?? ??
  • ?? ?? ??? ?? ?? ?? Separate ??

6
?? 9-1 ??? ?????? ?? ?? ??
  • File ??? ??

7
VBA in ARENA
  • Visual Basic for Applications(VBA)
  • Arena? ???
  • Arena ?? ?? ??? ?? ?? ?? ??
  • ActiveX ??? ? VBA ??
  • ActiveX ???????? ????? ?????? ?? ?? ??? ? ??? ?.
  • Excel ?? Macro ?? ActiveX ?????? ?? ? ?? ??, ??
    ??, ?? ?? ?? ????? VBA ??
  • ?? ??(Object Model) ??
  • ?????? ?? ?? ?? ????, ??, ? ?
  • ???? ???? ??, ?? ?? ?
  • ??? ???? ??, ?? ??, ? ?? ?

8
VBA in ARENA
  • VBA ????? ??
  • Visual Basic ??? ??
  • Microsoft Office, AutoCAD, Arena ?? ???
  • ?? ??
  • ?????? ????? ??? Sub, Function, Class, If,
    Elseif, Endif, While, Wend, Do, On Error, Select
    Case
  • ??? ? ?? ??, ??? ?, ?? ??, ?? ??, ?? ??
  • ?? ??? ?? Watches, Breakpoint, Step ??
  • ??? ???
  • Visual Basic Editor

9

VBA in ARENA
  • VB Editor

10
VBA in ARENA
  • ??? Arena VBA Events
  • ThisDocument Arena ???? ??? Event ? Access? ? ??
    ??
  • ModelLogic ??? ???? ???? ???? ??
  • 3?? ??? ??
  • ?? ? ??? DocumentOpen, DocumentSave
  • Arena ?? ?? ??? RunBegin, RunBeginSimulation,
    RunEndReplication
  • ??/??? ?? ?? ??? UserFunction, VBA_Block_Fire,
    OnKeyStroke

11
VBA in ARENA
  • ????? ?? VBA ???
  • 1. RunBegin
  • 2. Arena Checks Initiaialize Model
  • 3. RunBeginSimulation
  • 4. RunBeginReplication
  • 5. Arena Runs Replication
  • OnKeyStroke
  • UserFunction ?
  • 6. RunEndReplication
  • 7. RunEndSimulation
  • 8. Arena ????? ??
  • 9. RunEnd

12
VBA in ARENA
  1. ModelLogic_RunBegin ??
  2. VBA ??? ??? ???? ??? ?? ?? ?? ???? ?
  3. ?? ? ??? ?? ??
  4. Arena ? ??? ???? ????? ???
  5. ??? ???
  6. ???? ??? Idle, ?? ??
  7. ModelLogic_RunBeginSimulation ??
  8. ????? ?? ??? 1? ??? VBA ?? ??
  9. Excel, Access, Oracle ? ????? ??? ??
  10. UserForm ?????
  11. Arena ??? ??? ? ????

13
VBA in ARENA
  • ModelLogic_RunBeginReplication ??
  • ? ???? ??? ?? ??
  • RunBeginSimulation?? ??? ? ?? ?? ??
  • Arena ????? ??
  • VBA ?? ??? ??
  • ModelLogic_UserFunction Arena ?? UF ???? , ???
    ?? ? ???? ?? ??
  • ModelLogic_VBA_Block_Fire ??? VBA ??(Blocks
    ??)? ??? ? ??, ? ??? ??? ?? ? ??? ?? ?? ??
  • ModelLogic_OnKeyStroke ????? ?? ???? ?? ?? ???
    ??, ? 1 ?? ??? ?? ????? ???? ? ?????
  • ModelLogic_OnClearStatistics ???? ??? ??
    ??(????? ??? ?? ??? ??) ??, ???? ??? ???? ???? ??
    ?? VBA ?? ??

14
VBA in ARENA
  • ModelLogic_RunEndReplication ??
  • ???? ??? ?? ??
  • ????? ????? ??, ?? ?? ?? ?? ??
  • ??? ???? ???? ???? ??
  • ModelLogic_RunEndSimulation ??
  • ????? ??? ??
  • ?? ? ??? ?? ?? ???, ?? ?? ? ??? ??
  • ??, ???? ??, DB ? ??? ??, ?? ??, ?? ??? ????? ?
    ??
  • ????? ??
  • ModelLogic_RunEnd ??
  • ?? ? ??? ?? ???? ?? VBA ??? ??
  • ? ?? ?? ??? ?? ? ?????

15
VBA in ARENA
  • Arena? ?? ??
  • ??(Objects) ?? ?? ??/?? ?? ??
  • ????(Property)
  • ???(Method)
  • Collections of Objects
  • ?? ??
  • ?? ??? ?? Arena ?? ?? ??? ? ?? ?? ?? ??, ???,
    ?, ???, ??, ????? ??, named Views
  • SIMAN ?? ????? ??? ??? ?? ?? ?? ?? ?, ?? ??,
    ???? ??, ?? ?? ?
  • ?? ?? ?? Arena ??? ???? ?? ?? ??????, ?? ??,
    ?? ?? ?

16
VBA in ARENA
  • ?? ? ? 10 ?? ???? ?? ??? ??? ?? ?? ?????
  • Dim oModel As Arena.Model
  • Dim i As Integer
  • Dim nX As Long
  • Add the status variables to this Arena model
  • Set oModel ThisDocument.Model
  • nX 0 Start at x position 0
  • For i1 To 10
  • Add a status variable to the model window
  • oModel.StatusVariables.Create nX, 0, _
  • nX 400, 150, WIP( i ), .,
    False, _
  • RGV(0,0,255), RGV(0,255,255),
    RGV(0,0,0), Arial
  • Move over 500 world units for next position
  • nX nX 500
  • Next i

17
VBA in ARENA
  • SIMAN ?? ? ???? ????? ???? ??? ? ?????
  • Dim oSIMAN As Arena.SIMAN
  • Dim nVarIndex As Long
  • Dim sNewValue As String
  • Prompt for a new value
  • sNewValue InputBox(Enter the new average cycle
    time)
  • Assign their answer to the Mean Cycle Time
    variable
  • Set oSIMAN ThisDocument.Model.SIMAN
  • nVarIndex oSIMAN.SymbolNumber(Mean Cycle
    Time)
  • oSIMAN.VariableArrayValue(nVarIndex) sNewValue

???? ?? ???? ???? ??
InputBox? ??? ????? ???? ????
18
Model 9-2 ???? ?? ?? ??
  • ?? ?? ??? ???? ??????? ??
  • Random Interarrival-time process
  • Arrival time from a file

19
Model 9-2 ???? ?? ?? ??
  • ?? ?? ??

20
Model 9-2 ???? ?? ?? ??
  • Create ??? Max Arrivals? ?? ??
  • Random Process Craete ??? Max Arrivals ? 0 ??
    ?? Create ??? Max Arrivals ? 1 ?? ?? ??
  • Random Process Craete ??? Max Arrivals ? infinite
    ?? ?? Create ??? Max Arrivals ? 0 ?? ?? ??
    ??
  • Create ?? model 5-2? ?? Max Arrivals 0

21
Model 9-2 ???? ?? ?? ??
  • Properties ????? ??? ?? Tag ??/??
  • Object.nnn ? Create from random process or Create
    from file

22
Model 9-2 ???? ?? ?? ??
  • VBA ??? ? ??
  • Visual Basic Editor ? ?? ? ??? ?? ? ??
  • ?? ?? ?? ? ??
  • ???? ??? ?? ?? ?? frmArrivalTypeSelection

optFromRandomProcess
optFromFile
cmdOK
23
Model 9-2 ???? ?? ?? ??
  • ? ????? ? ?? ??? ??

24
Model 9-2 ???? ?? ?? ??
  • ?? ?? ? ?? ??
  • Create ??? ???? ?? Create and Direct Arrivals ??
    ??? ??.
  • Create ??? Max Arrivals ?? ?? ????.
  • ?? ??? ?? Top-level? ?? ????? ?? ????.
  • ??? ?? ?? ???? ??? ????.
  • ??? ?? ?? ???.
  • ?? ?? ?? ??

Dim nArrivalsSubmodelIndex As Long Dim
oArrivalsModel As Arena.Model With
ThisDocument.Model.Submodels
nArrivalsSubmodelIndex _
.Find(smFindName, "Create and Direct Arrivals")
Set oArrivalsModel _
.Item(nArrivalsSubmodelIndex).Model End
With oArrivalsModel.Show
25
Model 9-2 ???? ?? ?? ??
  • Create ?? ?? ??

Dim nCreateRandomProcessIndex As Long Dim
oCreateRandomProcessModule As Arena.Module Dim
nCreateFileIndex As Long Dim oCreateFileModule As
Arena.Module ' Find the two Create
modules nCreateRandomProcessIndex _
oArrivalsModel.Modules.Find(smFindTag, _
"Create from random process") If
nCreateRandomProcessIndex 0 Then MsgBox
"No module with tag 'Create from random
process'" frmArrivalTypeSelection.Hide
Exit Sub End If Set oCreateRandomProcessModul
e _ oArrivalsModel.Modules(nCreateRandom
ProcessIndex) nCreateFileIndex _
oArrivalsModel.Modules.Find(smFindTag, "Create
from file") If nCreateFileIndex 0 Then
MsgBox "No module with tag 'Create from file'"
frmArrivalTypeSelection.Hide Exit
Sub End If Set oCreateFileModule
oArrivalsModel.Modules(nCreateFileIndex)
26
Model 9-2 ???? ?? ?? ??
  • Tag? ??? Create ??? Max Arrivals ? ??
  • Top level ?? ??

' Set the Max Arrivals fields If
optFromRandomProcess.value True Then
oCreateRandomProcessModule.Data("Max Batches")
"Infinite" oCreateFileModule.Data("Max
Batches") "0" Else
oCreateRandomProcessModule.Data("Max Batches")
"0" oCreateFileModule.Data("Max Batches")
"1" End If
Dim oModel As Arena.Model Dim nAnimViewIndex
As Long ' Return to the top-level model and show
the Animation named view Set oModel
ThisDocument.Model oModel.Show nAnimViewIndex
oModel.NamedViews.Find(smFindName,
"Animation") If nAnimViewIndex gt 0 Then _
oModel.ActiveView.ZoomView oModel.NamedViews(nAnim
ViewIndex)
27
Model 9-2 ???? ?? ?? ??
  • ?? ???? ??
  • ??? ?? ? ??

Dim nSoundFileIndex As Long ' Play the sound
file nSoundFileIndex _
oModel.Embeddeds.Find(smFindTag, "Mission
Possible") If nSoundFileIndex gt 0 Then _
oModel.Embeddeds.Item(nSoundFileIndex).Do
' Hide the UserForm to allow the run to begin
frmArrivalTypeSelection.Hide Exit Sub
28
Model 9-3 ?? ??? ??? ???? ?? ???
  • ?? ??
  • ?? ?? ?? ? ?? ????, ????, ?????? ???? ?? ??? ??
  • ??????? ??? ???? ?? ??? ???
  • ?? ?? ?? ???
  • ??? ???? ??? ???.
  • ?? ?? ??

Option Explicit ' Global variables Dim oSIMAN As
Arena.SIMAN, nArrivalTimeAttrIndex As Long Dim
nNextRow As Long, nColumnA As Long, nColumnB As
Long, nColumnC As Long ' Global Excel
variables Dim oExcelApp As Excel.Application,
oWorkbook As Excel.Workbook, _ oWorksheet As
Excel.Worksheet
29
Model 9-3 ?? ??? ??? ???? ?? ???
  • ?? ?? ????? ?? ??/?? ? MicroSoft Excel 9.0
    Object Library ??
  • RunBeginSimulation ??

Private Sub ModelLogic_RunBeginSimulation() '
Set the global SIMAN variable Set oSIMAN
ThisDocument.Model.SIMAN ' Set global
variable to store Arrival Time attribute index
nArrivalTimeAttrIndex oSIMAN.SymbolNumber("Arri
val Time") ' Start Excel and create a
new spreadsheet Set oExcelApp
CreateObject("Excel.Application")
oExcelApp.Visible True oExcelApp.SheetsInNew
Workbook 1 Set oWorkbook
oExcelApp.Workbooks.Add Set oWorksheet
oWorkbook.ActiveSheet (??? ??)
30
Model 9-3 ?? ??? ??? ???? ?? ???
With oWorksheet .Name "Call
Data" .Rows(1).Select
oExcelApp.Selection.Font.Bold True
oExcelApp.Selection.Font.Color RGB(255, 0, 0)
.Rows(2).Select oExcelApp.Selection.
Font.Bold True oExcelApp.Selection.Font.
Color RGB(0, 0, 255) End With End Sub
  • RunBeginReplication ??

Private Sub ModelLogic_RunBeginReplication()
Dim nReplicationNum As Long, i As Integer '
Set variables for the columns to which data is to
be written nReplicationNum
oSIMAN.RunCurrentReplication nColumnA (4
(nReplicationNum - 1)) 1 nColumnB
nColumnA 1 nColumnC nColumnA 2
31
Model 9-3 ?? ??? ??? ???? ?? ???

' Write header row for this day's call data and
' set nNextRow to 3 to start writing data in
third row With oWorksheet .Activate
.Cells(1, nColumnA).value "Day "
nReplicationNum .Cells(2, nColumnA).value
"Start Time" .Cells(2, nColumnB).value
"End Time" .Cells(2, nColumnC).value
"Duration" For i 0 To 2
.Columns(nColumnA i).Select
oExcelApp.Selection.Columns.AutoFit
oExcelApp.Selection.NumberFormat "0.00"
Next i End With nNextRow 3 End Sub
32
Model 9-3 ?? ??? ??? ???? ?? ???
  • ? ?? ??? ??
  • ?? ??
  • VBA ??

Private Sub VBA_Block_1_Fire() ' Retrieve
create time and current time from SIMAN object
data Dim dCreateTime As Double, dCurrentTime
As Double dCreateTime oSIMAN.EntityAttribute
(oSIMAN.ActiveEntity, _
nArrivalTimeAttrIndex) dCurrentTime
oSIMAN.RunCurrentTime ' Write the values
to the spreadsheet With oWorksheet
.Cells(nNextRow, nColumnA).value dCreateTime
.Cells(nNextRow, nColumnB).value
dCurrentTime .Cells(nNextRow,
nColumnC).value dCurrentTime - dCreateTime
End With ' Increment the row variable
nNextRow nNextRow 1 End Sub
33
Model 9-3 ?? ??? ??? ???? ?? ???
  • ?? ?? ? ?? ?? ???
  • ?? ?? ?? RunEndReplication

Private Sub ModelLogic_RunEndReplication() '
Chart today's sales call data on a separate chart
sheet oWorkbook.Sheets("Call Data").Select
oWorksheet.Range(oWorksheet.Cells(3, nColumnC),
_ oWorksheet.Cells(nNextRow,
nColumnC)).Select oExcelApp.Charts.Add
' Format the chart With oExcelApp.ActiveChar
t .ChartType xlLineMarkers
.SetSourceData SourceoWorksheet.Range(oWorksheet
.Cells(3, _ nColumnC),
oWorksheet.Cells(nNextRow, nColumnC)), _
PlotByxlColumns .SeriesCollection(1).
XValues "" .Location WherexlLocationAs
NewSheet, _ Name"Day "
oSIMAN.RunCurrentReplication " Sales Calls"
.HasTitle True ' Title and Y
axis .HasAxis(xlValue) True
34
Model 9-3 ?? ??? ??? ???? ?? ???
  • .HasAxis(xlValue) True
  • .HasAxis(xlCategory) False ' No X axis
    or Legend
  • .HasLegend False
  • .ChartTitle.Characters.Text "Sales Call
    Times"
  • .Axes(xlValue).MaximumScale 60
  • .Axes(xlValue).HasTitle True
  • .Axes(xlValue).AxisTitle.Characters.Text
    "minutes"
  • End With
  • End Sub
  • ?? ?? ?? RunEndSimulation

Private Sub ModelLogic_RunEndSimulation() '
Save the spreadsheet and close Excel
oExcelApp.DisplayAlerts False '
Don't prompt to overwrite oWorkbook.SaveAs
ThisDocument.Model.Path "Model 09-03.xls" End
Sub
Write a Comment
User Comments (0)
About PowerShow.com