We have been shortlisted! We are delighted to be nominated for 5 Tech for Good awards for our work with South African charity Shout It Now. Read more here.
Visual Logic Tutorial
This example explains how to build Visual Logic code. It gives detailed instructions about how to input and edit Visual Logic.
The example is a process where a standard facility is supplemented by a back up facility at busy times.
Create a simple simulation like this:
and change the processing time at Work Center 2 to 11 minutes.
Work Center 3 is very expensive and so needs to be highly utilized so Work Center 2 will be supplemented with additional help but we will only use this when it would be useful to do so.
Copy Work Center 2 and its Storage Bin (drag a box around the bin and the Work Center, then drag the box while holding down the control key on the keyboard).
We are going to send work to Work Center 4 from Work Center 1 when there is not much work waiting at the important Work Center (3) but only if Work Center 2 is getting a behind with its work (there is a queue of work at it).
Specifically, if there are less than 3 items waiting for Work Center 3, and there is a queue at Work Center 2, then we will send work to Work Center 4 instead of 2.
Go to the Data & Rules tab and enter the detail dialog for Labels.
Add a label and call it “Route to take” - we are going to use “Label Routing out” of Work Center 1.
In the Label dialog click NEW to create a new label and type in its name
Click OK several times to get back to the main screen.
Click on Work Center 1 and change its routing out to “Label” and set the required label to “Route to take” in the DETAIL button.
Now we have to add the Visual Logic code to set the Label to either: 1 (go to the first destination in the above list) or 2 (go to the second destination in the above list).
Click the On Work Complete button (you may need to click on the more button).
Now we have a blank window into where we can enter Visual Logic. This Visual Logic will be obeyed whenever a Work Item finishes its work at Work Center 1.
As the window says, click the RIGHT mouse button (in the window) to start adding Visual Logic.
The first thing to do is set the Label to the default value (1 = go to Queue for Work Center 2).
Choose SET… from the menu when you click RIGHT. The SET VALUE dialog appears. You can set Labels, Global data (variables) and other changeable data here.
Double click the left hand side box.
The formula editor appears. Select the OBJECT check box
We want to set ROUTE TO TAKE - so double click it and then click OK.
Now click the double click right hand side of the SET dialog.
We are now back in the formula editor but this time we want a value.
Type a 1 into the box and click OK.
Click OK in the SET DIALOG too.
If you run the simulation with just this Visual Logic code it will behave as it did without Work center 4 because the label will always be 1 (= go to destination 1).
Click the right mouse button again (in the Visual Logic code window) and add an IF line. The Conditional Block Editor will appear. (The Conditional Block Editor is also used to While and UNTIL blocks).
When you click either of the formula boxes you will see the formula editor again.You want a line that looks like this:
IF Queue for Work Center 3.Count Contents <3
So, click the top box and use the formula editor to select OBJECT, QUEUE FOR WORK CENTER 3, COUNT CONTENTS. You need to click APPLY and OK to bring your selection back to the conditional block editor.
Use the formula editor to put a 3 in the bottom box and choose IS LESS THAN for the type of condition.
All Visual Logic lines that can have child lines automatically insert a dummy line when they have no children.
If you click RIGHT when a line is highlighted new lines are inserted at the same level in the hierarchy.
If you wanted to add a line at the same level as the SET and the IF lines (to be obeyed after the IF block) you would highlight (click on) the IF line first, then RIGHT click.
Add another IF inside the block for the first IF and then add another SET so you have some code like this:
IF Queue for Work Center 3.Count Contents <3 IF Queue for Work Center 2.Count Contents >3 SET Route To Take = 2
Running the simulation like this will increase the utilization of Work Center 3.
So far we have only looked at SET and IF lines. Loop lines are important because they let you perform operations a specific number of multiple times. Loops require a Global Data Item to be used to count to number of times the loop is performed. Create a Global Data Item in the Information Store - make sure the item you create can contain NUMBERS.
In the On Reset Logic enter the loop code (accessed through Tools→Visual Logic Events → On Reset):
LOOP 1 >>> My Counter >>> 5 Add Work To Queue Main Work Item Type, Queue for Work Center 3
This loop is used to add 5 Work Items to the queue for Work Center 5 when the simulation is reset.
What type of line is “Add Work Item to Queue”?
This is a “Command”. Commands are not part of the structure of Visual Logic. They are specific to the requirements of Simul8. There are many commands - explore the menus and see section Visual Logic Commands in this guide.
You can also explore the commands available from within the Command Editor. The Command Editor lets you easily enter parameters for each command. This can be accessed by clicking RIGHT and selecting the Command menu structure.
As you change the command or click on parameters the text automatically changes to prompt you for the type of information required.