Subject Specific Training: Scripting September 2008.

42
Subject Specific Subject Specific Training: Training: Scripting Scripting September 2008

Transcript of Subject Specific Training: Scripting September 2008.

Page 1: Subject Specific Training: Scripting September 2008.

Subject Specific Training:Subject Specific Training:ScriptingScripting

September 2008

Page 2: Subject Specific Training: Scripting September 2008.

Learning ObjectiveLearning 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.

Page 3: Subject Specific Training: Scripting September 2008.

AgendaAgenda

• Scripting Basics

• Scripts in Supply Chain Guru

• Script Writing

• Testing the Script

• Check on Learning

• Capstone Exercise

Page 4: Subject Specific Training: Scripting September 2008.

MaterialsMaterials

• Supply Chain Guru installed on computer with proper licenses

• Scripting Training Slides

• Script Types Quick Reference Sheet

• Model Object Dictionary (Excel Version)

Page 5: Subject Specific Training: Scripting September 2008.

Scripting BasicsScripting Basics

• Why do you need to script?

• Simulation Engine

• Model Objects

• Model Variables

Page 6: Subject Specific Training: Scripting September 2008.

Why Do We Script?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

Page 7: Subject Specific Training: Scripting September 2008.

SimServerSimServer

• External Simulation Engine

• Reads the Model Configuration File (MCF)

• Simulation results loaded into SCG tables

• Ability to use animation

Page 8: Subject Specific Training: Scripting September 2008.

Scripting Basics: Model Scripting Basics: Model ObjectsObjects

• 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)

Page 9: Subject Specific Training: Scripting September 2008.

Supply Chain Guru ObjectsSupply Chain Guru Objects

Model

Products Customers Sites Lanes Assets Processes BillofMaterials

ProductSource ProductDestination Customer Product See Next Slide Modes AssetUnits Shipments

ShippingRoute

Location

Waypoints

BOMItems

Page 10: Subject Specific Training: Scripting September 2008.

Site ObjectSite Object

Sites

SiteProduct WorkCenter WorkResource WorkProcess Order ShippingItem

ProductSource ProcessLot WorkStep ProcessLot ProcessRouting

ActivityResource

OrderDetail ShippingItemDetail ShippingItemList

Page 11: Subject Specific Training: Scripting September 2008.

Scripting Basics: VariablesScripting 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

Page 12: Subject Specific Training: Scripting September 2008.

Scripting Basics: Script TypesScripting 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

Page 13: Subject Specific Training: Scripting September 2008.

Using Scripts in Supply Chain Using Scripts in Supply Chain GuruGuruTMTM

• Scripts Table

• Global Variables Table

• Debug Level

• Practical Exercise

Page 14: Subject Specific Training: Scripting September 2008.

Using Scripts: Scripts TableUsing Scripts: Scripts Table

• Name• Script• Script Type• Time First• Occurrences• Interval

Page 15: Subject Specific Training: Scripting September 2008.

Scripts Table: Script TypeScripts Table: Script Type

On Simulation EndsOn Receive Order BeginsOn Receive Order EndsOn Receive Shipment BeginsOn Receive Shipment EndsAsset Unit Selection RuleTransportation Costs Basis Rule

Mode Selection RuleProcess Routing RuleQueue Selection RuleSourcing PolicyMake PolicyInventory PolicyOn Simulation Begins

See The Script Types Quick Reference Card for more information

Page 16: Subject Specific Training: Scripting September 2008.

Using Scripts: Global Using Scripts: Global Variables TableVariables Table

• Name• Type• Value• Dimensions • Notes

Page 17: Subject Specific Training: Scripting September 2008.

DebugDebug

• 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.

Page 18: Subject Specific Training: Scripting September 2008.

Setting the Debug LevelSetting 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

Page 19: Subject Specific Training: Scripting September 2008.

Using Scripts: Practical ExerciseUsing 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

Page 20: Subject Specific Training: Scripting September 2008.

Practical Exercise (1)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

Page 21: Subject Specific Training: Scripting September 2008.

Practical Exercise (2)Practical Exercise (2)

3. Tell SimServer how to perform each stepHint: Use “//” to keep SimServer from reading your comments

4. Copy to the Script Table

Page 22: Subject Specific Training: Scripting September 2008.

Practical Exercise (3)Practical Exercise (3)• Set the script to run at day 14

• Run the Simulation• View the Script Log

Page 23: Subject Specific Training: Scripting September 2008.

Practical Exercise (4)Practical Exercise (4)

• View Simulation Outputs

Page 24: Subject Specific Training: Scripting September 2008.

Script WritingScript Writing

• 3 Steps

• Scripting Language

• Common Problems

Page 25: Subject Specific Training: Scripting September 2008.

3 Steps to for Script Writing3 Steps to for Script Writing

1. Determine objective

2. Pseudocode: write down each step in list form

3. Tell the computer what to do

Page 26: Subject Specific Training: Scripting September 2008.

Step 1: Determine Script Step 1: Determine Script ObjectiveObjective

• 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

Page 27: Subject Specific Training: Scripting September 2008.

Step 2: Write down each stepStep 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

Page 28: Subject Specific Training: Scripting September 2008.

Step 3: Tell the computerStep 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?

Page 29: Subject Specific Training: Scripting September 2008.

Tell the Computer: Sequential Tell the Computer: Sequential InstructionsInstructions

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)

Page 30: Subject Specific Training: Scripting September 2008.

Start: Defining VariablesStart: 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”

Page 31: Subject Specific Training: Scripting September 2008.

Start: Setting VariablesStart: 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 = ”

Page 32: Subject Specific Training: Scripting September 2008.

Body: MethodsBody: Methods• Looping Instructions

– For Next• Repeats a block of script a specific number of timesFor index = intialValue To expression

BlockNext

– 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

Page 33: Subject Specific Training: Scripting September 2008.

Body: Methods (2)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

Page 34: Subject Specific Training: Scripting September 2008.

End the ScriptEnd the Script

• CALL– Example:

CALL Debug.Assert(Not ISNull(THESITE))

Ensures that this site is not empty

• Assert

• Write to Script Log

Page 35: Subject Specific Training: Scripting September 2008.

Testing the ScriptTesting 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

Page 36: Subject Specific Training: Scripting September 2008.

Scripting LanguageScripting Language

• Comments //

• Need to add more here

Page 37: Subject Specific Training: Scripting September 2008.

Common Scripting IssuesCommon Scripting Issues

• Need to add more here

Page 38: Subject Specific Training: Scripting September 2008.

Check on LearningCheck 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

Page 39: Subject Specific Training: Scripting September 2008.

Capstone ExerciseCapstone Exercise

Page 40: Subject Specific Training: Scripting September 2008.

Create a ModelCreate 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

Page 41: Subject Specific Training: Scripting September 2008.

Custom Mode Selection ScriptCustom 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.

Page 42: Subject Specific Training: Scripting September 2008.

QuestionsQuestions