MicroSaint Sharp – Introduction

Graphical Development Environment

Student version of software available.

User can manually rearrange windows, pin them or remove them. To reset windows to their default layout use View/Layout/Reset ScreenLayout. View/Windows lists the various windows that are available which are also listed in a Left-Boarder menu called Sections. The windows available are:

Output – window containing trace file

Watches

Search and Replace

Tree View – List of objects in model

Palette

Properties

Event Queue

Task Network

Animator

Line Debugger

Task Network:

Build network of Tasks – right click select task

Link tasks – drag from output of one task to next task

Shows symbolic animation during simulation run, displays values of any variable within a “Comment”

Add Task:

Note values of attributes within Properties Window

Timing Tab

Select this tag and the Task Duration specified by a Distribution with up to 3 possible parameters: Data Shaping e.g. Normal, Mean, Standard Deviation

Main Tab

Displays Code windows: Logical conditions are defined through C# program code. Define local variables, assign values specify any algorithms required to achieve the desired behaviour. Assign system variables with return statement e.g. return true; return 6;

!!Code is case sensitive!!

To add a comment to any code use: //comment

Pre-Condition called Release Condition

Code window return “boolean” e.g. return Clock <480;

Assume you declared a global variable Busy as Boolean

return Busy;


Start Condition called Beginning Effect

In code window write for example:

Busy = true;

End Condition called Ending Effect

In code window write for example:

Busy = false;

This would control the flow of one Entity at a time through the task.

Launch Tab

Code window controls the Animation objects linked to this event. (more alter)

Queue Tab

Select the Queue Tab and the type of queue:

FIFO First in first out

FILO First in last out

Sorted Ordered or sorted queue

None No queue

Insert code into the Queue Priority code window and return a value. By default return zero. Return a non-zero value to ensure the the entity is placed in the queue sorted in order; highest at the front.

Tree View:

Task Network

Variables

Functions

Snapshots

Scenario Events

Entities Attributes

Charts

Watches

Execution Settings

Animator

OptQuest

Declare Global Variables:

Select Variables from the Tree View – Add Variable (right click)

Provide a name NumTellerFree

Provide a type Integer

Provide an initial value 3

Attributes i.e. variables can be attached to Entities

Select Entity Attributes from the Tree View – Add Entity Attribute (right click)

Provide a name WaitingTime

Provide a type Real – floating point

Provide an initial value 0.0

To access these variables use for example: Entity.WaitingTime;

Types of variable

Integer

FloatingPoint (double)

Boolean

String

Entity Pointer that accesses a specific entity in the model. Consider the following code placed in a task window:

Declare a Global variable MyEntity type Entity

Write: If Entity.Tag = 100 {MyEnity = Entity};

Inspect the value of MyEntity.Tag in another part of the model by using a Snapshot at the end of the simulation.

Array (of any type)

Arbitary (more later)

Object (more later)

Local Variuables

These can be declared within any code window. For example a variable to control a loop execution could be declared and used:

for (int Count=1; Count<11; Count++) //using C# syntax

{. . .}

Making a Network

Add another task and link together – Drag from the exit diamond of first task to second task. If there is more than one route there are 3 types of logic available to control the flow from one task to another:

Path Tab

This displays the decision windows into which code is written for each path or route

Probabilistic:

When more than one route indicated the probability for each route is given by returning a value between 0 & 1 e.g.

Route 1: return 0.4;

Route 2: return 0.6;

This would send 40% of the entities via route 1 and 60% via route 2 on a random basis.

Tactical:

The route that returns the higher value is selected e.g.: return expression;

Multiple:

Default selection. Route is taken if returned value not zero. This may mean that 2 or more routes are followed hence the entity must slit into 2 or more identical entities one for each path. It is possible to recombine these cloned entities back into one. Why would one want to do this? What happens to the entity values of each clone that may change. Manual doesn’t tell us!! I await a response from Micro Analysis And Design (MAAD).

Functions:

Functions can also be declared and used anywhere in the model. Select the Function Icon from the Tree View and declare the name and write the code returning the value at the end. An example would be a function:

AverageCost (Cost, MaxNum);

to sum the elements from 1 to MaxNum of an Array Cost to calculate the average cost of a process.

double TotalCost = 0.0;

int N=1;

for (N=1; N<MaxNum; N++);

{TotalCost = TotalCost + Cost[N];}

return TotalCost/MaxNum;

Both variables Cost and MaxNum are local to the function but global variables would need to be declared to call the function e.g. MyAverageCost, MyCost:

MyAverageCost = AverageCost(MyCost,100);

There are a number of built-in functions e.g Clock returns the time as a floating point values.

Analysis of Simulation run:

Task Network:

Display of number of Entities waiting in queues and number in Tasks during a simulation run. Note that if more than one Entity is accepted by the Task this is achieved by the Task object spawning instances of the object. The Task variables can be read, but not assigned, through the use of the code:

Task.ItemsInQueue full list of Task variables displayed when the period is typed

Task variables of a different Task than the one in which the code is located:

Model.FindTask(“2”).ItemsInQueue where 2 is the ID of the Task

Comments:

Display the values of any given variable on the screen but disappear from the screen at the end of the simulation. A useful technique is to insert a Message into a SnapShot (see below) at the “EndOfRun” of the simulation that causes a pause allowing data to be inspected. The code would be:

Model.Message(“pause”);

SnapShots:

SnapShots of any variable can be taken at any time or at any event and displayed after the simulation has finished. Right click on SnapShot icon in tree View to create a new SnapShot (see example page 10). Summative data that is to be calculated at the end of the simulation can be displayed using a SnapShot and setting the Trigger Type to be EndOfRun and defining an expression for example:

Average = Total/Number;

This Snapshot can be viewed after the simulation ends - right click the SnapShot icon in the Tree View and select ”Show Results Data”.

SnapShots of queue data and Task data are automatically collected and can be displayed at the end of the simulation. Automatic collection of data has to be enabled from within the Execution window. Any SnapShot data can be exported to Excel.


Charts:

Visual data collection can be provided through Charts. To display a chart select the Icon from the Tree View. A data series has to be specified which must be a global variable. The chart should appear during the simulation and update dynamically.

Output Window:

A complete record of all events is displayed in the Output Window as a “trace file” which can be saved – right click in the window. The system automatically records data sequentially about queues, tasks and resources and can be copied into a spreadsheet or a data file. At any place in the code data or text can be written to the Output Window with the command:

Model.PrintOutput (variable);

Note: only one item per line is possible. Data files are saved either as text files (txt) or in XML format.

Animation:

Moves graphic objects or icons around the screen controlled by the code placed in the Launch Effect window e.g. location specified by coordinates, selection of graphic, colour etc. More discussion about animator later. The Animator can be used to display labels, plots, graphs and images on the screen at the same time which makes analysis easier.

Senarios:

Starting the simulation running with particular parameters set can be achieved through the use of the Execution window, an image of one is show below. Parameters can be changed at any time during the simulation through the use of a scenario; e.g. change the customer inter arrival time (IAT) during the lunch period. To open a Senario select the icon in the Tree View.


Output of Program code:

The details of the model can be viewed as an HTML file and saved with the menu Utilities/View Model as HTML. The Task Network can be printed with the menu File/Print Network.

Generating a stream of entities (not obvious):

Use is made of the fact that Entities can split between two or more tasks. Hence take one route to the next task and one route back on itself. This creates what is referred to as a “Spinner Task”. The logic for the paths or routes is multiple paths indicated as “M”. Thus the Entity splits one going on and one going back. In the Decision code for the Path to Task 2 the Entity can be given a unique reference with the code:

Entity.Tag = Entity.Tag + 1;

return true;

In the Decision code for the loop back we can control the run time of the simulation with the simple code:

return Clock < 500;

Navigation:

In navigating between windows it is helpful to make use of the 4 arrows at the top right of the window that moves on to the next window from within the same set of windows e.g. between the tasks or between the list of Variables.

Some useful features of Micro Saint

To reset the model after making a change save the file and select the “check for errors” before making a simulation “run”. There is not a specific Reset Button so use the Save icon instead.

Comments added to the model are a useful way of keeping records of the design. Comments can also show numerical values of global variables during the program execution.

Variables declared within a code window are local to that code window only. Thus a variable declared in the Beginning Effect can not be accessed in the Ending Effect.

Data for both queues and Tasks are collected by the system automatically. Note that the Number of Queue hits is usually less than the Number of Task hits because some Entities do not have to wait in a queue.

There is no reset icon in Micro Saint so it is recommended that you save the file after making changes and check the syntax before running a simulation.

Mathematical division – C# is a strongly typed language so care must be taken when carryout arithmetic with variables of different type as shown in the following examples:

Integer division results in an integer

A real divided by an integer leads to a real

An integer divided by a real leads to a real

If the wrong type is used in such assignments an error will be caused. Use can be made of “Casting” one type as another for example if integers I = 12 & J = 10 then:

I/J = 1 integer arithmetic

(double)I/J =1.2 casting I as real variable of type double

Other type conversions are possible with the methods:

Model.Convert.ToSring ( )

Model.Convert.ToInt16 ( )

Model.Convert.ToInt32 ( )

Model.Convert.ToSingle( )

Model.Convert.ToDouble( )

Developing Models

Use has to be made of the basic programming facilities C# within Micro Saint to model any objects that are not built-in or to compute special logical constraints.

Queues

To calculate how long an entity has been waiting in a queue and the total waiting time for all entities use global variables and Entity Attributes or variables. Each Entity has a unique Tag value (integer). Suggest that use is made of variables StartTime, WaitTime TotalWaitTime and the Clock global variable to compute the time spent in a queue and the total time of all Entities have spent waiting with code written in the windows: Queue Entering Effect and Queue Departing Effect.

Resources

Resources can easily be modelled by an integer variable that sets the number of resources that can be decremented or incremented as resources are used and then made available again. For example consider Tellers in a bank.

Declare a global variable Tellers and its initial value can be set either within the declaration window or within the Execution Window. The availability of Tellers can then be controlled by code:

Beginning Effect

Tellers = Tellers – 1;

Ending Effect

Tellers = Tellers + 1;

If attributes are needed to be attached to each Teller then the use of arrays are very useful. For example declare Teller as an array with dimension 5 of integer. This has indices 0..4 so that we can set Teller[I] = 1 when it is free and set it to zero when busy. Hence we can sum the array to find the number of free Tellers at any time. To keep track of other properties of the Teller we can declare another array say TellerName with the same dimension but of String type to store the name of the Teller. Similarly we can use TellerWork of type FloatingPoint to store the time worked by each Teller. We would need to calculate the time spent on each transaction and add it to the TellerWork. There would need to be code written to check if a Teller is free, before a transaction starts, in the Release Condition. We can calculate the ID of a Teller who is free in the Beginning Effect code and store a reference to that Teller in an Entity Attribute.

Release Condition:

FreeTellers = Tellers[1]+Tellers[2]+Tellers[3]+Tellers[4];

return FreeTellers >0;

Beginning Effect: //this only executes if there is at least one Teller free

int I = 1; //declare local variable and its initial value

while (Tellers[I] == 0) {I++;}

Entity.TellerID = I; //declare a Entity Attribute TellerID to store the Teller’s ID

Tellers[I] = 0;

Ending Effect:

int I = Entity.TellerID; //this variable is required to avoid mixing up the Tellers

Tellers[I] = 1;

TellerWork[I] = TellerWork[I] + Entity.Duration;

Utilisation

The utilization can be defined as the percentage of time an object or resource is in use. Having recorded the time that a person is busy or a resource is in use we can calculate the utilisation at the end of the simulation:

Queues

The time spent in a queue is the difference between time entering & leaving for each entity. We are interested in the average time spent in a queue and the maximum time spent by an entity in the queue. Hence we need to declare Entity Attributes StartTime and WaitTime and Global Variables TotalWaitTime and the total number of entities passed through the system TotalNum and MaxTime. The time weighted average is given by: