Download presentation
Presentation is loading. Please wait.
Published byDayna Adams Modified over 9 years ago
1
Subject Specific Training: Scripting September 2008
2
Learning Objective Upon completing this training, the learner will be able to identify the components of a script; explain the process for writing a script including its application in Supply Chain Guru; and develop a simple script, test the script and review results.
3
Agenda Scripting Basics Scripts in Supply Chain Guru Script Writing Testing the Script Check on Learning Capstone Exercise
4
Materials Supply Chain Guru installed on computer with proper licenses Scripting Training Slides Script Types Quick Reference Sheet Model Object Dictionary (Excel Version)
5
Scripting Basics Why do you need to script? Simulation Engine Model Objects Model Variables
6
Why Do We Script? Create more detailed models –Real world behavior does not fit in any of the “pre-defined” behaviors Add realistic scenarios Perform detailed risk analysis
7
SimServer External Simulation Engine Reads the Model Configuration File (MCF) Simulation results loaded into SCG tables Ability to use animation
8
Scripting Basics: Model Objects Can be viewed as an independent little machine with a distinct role The actions or “operators” on the objects are closely associated with the object The data structures tend to carry their own operators around with them (or at least "inherit" them from a similar object or "class") Characteristics (its attributes, fields or properties) Behaviors (the things it can do, or methods, operations or features)
9
Supply Chain Guru Objects Model Products ProductSourceProductDestination Customers Customer Product Sites See Next Slide Lanes Modes Assets AssetUnits ShippingRoute Waypoints Location Shipments ProcessesBillofMaterials BOMItems
10
Site Object Sites SiteProduct ProductSource WorkCenter ProcessLot WorkResourceWorkProcess WorkStep ActivityResource ProcessLotProcessRouting Order OrderDetail ShippingItem ShippingItemDetailShippingItemList
11
Scripting Basics: Variables Definition: a value that can change, depending on conditions or on information passed to the program Variable Scopes –Model Variables Permanent –Cannot be created in script –Sites, Customers, Products Dynamic –Change during the simulation Exist in Collections –Group of objects that should be kept together –Global Variables Cannot be declared in script Use the global variables table to declare variables –Local Variables Pertain only to the executing script –Context Variables Contains variables and objects that depend upon the context of the script
12
Scripting Basics: Script Types Mode Selection Rule Process Routing Rule Queue Selection Rule Sourcing Policy Make Policy Inventory Policy On Simulation Begins/ Ends On Receive Order Begins/ Ends On Receive Shipment Begins/ Ends Asset Unit Selection Rule Transportation Costs Basis Rule
13
Using Scripts in Supply Chain Guru TM Scripts Table Global Variables Table Debug Level Practical Exercise
14
Using Scripts: Scripts Table Name Script Script Type Time First Occurrences Interval
15
Scripts Table: Script Type On Simulation Ends On Receive Order Begins On Receive Order Ends On Receive Shipment Begins On Receive Shipment Ends Asset Unit Selection Rule Transportation Costs Basis Rule Mode Selection Rule Process Routing Rule Queue Selection Rule Sourcing Policy Make Policy Inventory Policy On Simulation Begins See The Script Types Quick Reference Card for more information
16
Using Scripts: Global Variables Table Name Type Value Dimensions Notes
17
Debug The Debug statement is the most detailed debugging command available. During the simulation run, when a Debug statement is encountered, the model will stop execution and begin to run in a line- by-line serial execution mode, displaying the specific model code being executed at each line.
18
Setting the Debug Level The model must be set at an equal or higher debug level than what is called in script Accessible in Model Options, Simulation Tab
19
Using Scripts: Practical Exercise Copy a script which will permanently close a site –Determine the steps to close the site –Tell SimServer what to do –Run the Simulation and view the results
20
Practical Exercise (1) 1. Open the Model: TrainingExercise1_BaseModel_SiteClosedScript 2. In Word or Notepad, write the steps needed to close DC_2 after the second week of the simulation
21
Practical Exercise (2) 3. Tell SimServer how to perform each step Hint: Use “//” to keep SimServer from reading your comments 4. Copy to the Script Table
22
Practical Exercise (3) Set the script to run at day 14 Run the Simulation View the Script Log
23
Practical Exercise (4) View Simulation Outputs
24
Script Writing 3 Steps Scripting Language Common Problems
25
3 Steps to for Script Writing 1.Determine objective 2.Pseudocode: write down each step in list form 3.Tell the computer what to do
26
Step 1: Determine Script Objective What are you trying to do? –Mode Selection vs. Price Adjustments –Risk Analysis –Refer to the Script Type Quick Reference –What is the context variable? Map back to Model Object –Model Object Dictionary –Scripting Quick Reference Chart
27
Step 2: Write down each step Use notepad or Microsoft Word List each and every event from start to end Use simple language, write as you speak Recognize if you will need to loop, make a decision, or use a counter during the script execution
28
Step 3: Tell the computer Tools –Scripts Table –Model Object Dictionary –Model Object Quick Reference Guide –Script Log What to do? When to do it? When to Stop? How Often?
29
Tell the Computer: Sequential Instructions 1.Define variables to solve the objective (Start) 2.Devise a method to create a solution (Body) 3.Determine how to put the solution back into the model (End)
30
Start: Defining Variables Declare A Variable/ Name the Variable –Name Space Can contain only alphanumeric and the underscore character Must begin with a letter NOT case sensitive Do not use reserved words –All language keywords –All model collections –True and False Context namespace –Contains variables and objects that depend upon the context of the script Examples: nDate, nDemand, nSite Data Types –Integer –Real –Boolean –String –Date –Object “Declare Variable As Data Type”
31
Start: Setting Variables Set your variable to an initial value or expression –Must match the data type that you declared it to be –Can use Operators (+, -, /, *) –Model Object Use Model Object Dictionary “Set Variable = ”
32
Body: Methods Looping Instructions –For Next Repeats a block of script a specific number of times For index = intialValue To expression Block Next –For Each … Next –While Wend –Do Until Decision Statements –If …Then –If … Then, Else –If … Then, Elseif, Else, End If Other Statements –Break: Exits the immediately –Continue: Jumps to the next loop iteration bypassing any further block statements –Return: Goes back to the start of the loop
33
Body: Methods (2) Built In Functions –Math, String, Date, Debug –Specify namesake prefix and enclose arguments in parentheses –Examples: SET Cost = Math.Min(Global.MinCost, Local.ActualCost) The cost will be the smaller cost of the Global and Local variables SET Elapsed = Date.DateDiff(Global.Now(), Model.StartTime, “s”) Determines the elapsed time between the start of the model run and the current time in seconds
34
End the Script CALL –Example: CALL Debug.Assert(Not ISNull(THESITE)) Ensures that this site is not empty Assert Write to Script Log
35
Testing the Script Script Log –Run Simulation –Open Notepad –Open the Script log Location- In Model Folder Debug statements help determine script correctness –Debugging a Script Syntax Errors –Misspelling or omitting a command Run time Errors –Script runs into unexpected error (such as declaring a name an integer) Logic Errors –Typically prevent script and/ or Sim Server from running –Outputs do not make sense
36
Scripting Language Comments // Need to add more here
37
Common Scripting Issues Need to add more here
38
Check on Learning Identify components of a script Explain process for writing a script Apply a script to SCG Develop and test a script Review results Explain reasons for scripting State when you need a script Define model objects and variables Identify key tables for scripting Select the debug level for a model Plan how to write a script Define key script writing terms Apply steps to write a script Practice writing a script Open the Scripts table Write a script Run a simulation which calls a script Perform a DEBUG on a script Identify simulation outputs and locations of logs
39
Capstone Exercise
40
Create a Model Save model as: Training_Script_A 1 Product 3 CZ, 1 MFG Weekly demand of 10 by each CZ Each CZ can be sourced from each MFG LTL Truckload Policy 1 Asset Types: –Truck_A: Preferred asset, only available on Mondays –Truck_B: More expensive, runs everyday
41
Custom Mode Selection Script 1.Write a custom Mode Selection Script which will ship via Truck_A on Mondays, and via Truck_B at all other times. 2.Run the simulation. 3.Review outputs and analyze model.
42
Questions
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.