Building Labels Model
Begin a new model by clicking the button on the toolbar. Click OK on the Model Units window, we will use the default units for our model.
If at any time you encounter difficulties while building this model, a fully functional tutorial model can be found at http://www.flexsim.com/tutorials
Step 1: Create the Objects
- Drag objects from your Library Icon Grid onto the 3D View to create the model shown below.
- Rename the objects as shown.
Connect all of the objects as shown:
- Connect Source to Queue.
- Connect Queue to Processor 1, Processor 2, Extra Processor 1 and Extra Processor 2.
- Connect Processor 1, Processor 2, Extra Processor 1 and Extra Processor 2 to Sink.
- Connect Queue to Dispatcher with a centerport connection (S key).
- Connect Dispatcher to Operator1, Operator2 and Operator3 with a standard connection (A key).
Step 2: Setup Global Variables
Here we will create global variables for objects that we will access in our User Event. Alternatively, objects can be accessed by the node command:
treenode Op1 = node("/Operator1", model());
- Add a new Global Variable from the Toolbox (View > Toolbox or click on the Tools button in the main toolbar).
- Create a global variable for each operator, the two extra processors, and the source. Each of them will be of type Tree Node, named as shown:
Step 3: Setup Source and Queue
- Open the Source Properties Window.
- Go to the Labels tab.
- Create a number label called "arrivalTime", leave it set to 0.
- Go to the Source tab.
- For the Inter-arrival time enter getlabel(current, "arrivalTime").
- Click Ok to apply and close the properties window.
- Open the Queue properties window.
- Go to the Flow tab.
- Check Use Transport.
Step 4: Create User Events
We will create three user events. One to fire when the model resets and two to change the "busyness" of the model.
- Add three new User Events from the Toolbox (View > Toolbox or click on the Tools button in the main toolbar).
- Name them "ResetModel", "busytime" and "slowtime".
- With ResetModel selected, check Execute event on reset only. Every time you press the Reset button, this code will be executed.
- Click the code edit button and write in the following code:
setloc(Op1, 5, 0, 0); setloc(Op2, 5, -1, 0); setloc(Op3, 5, -2, 0); setlabel(source, "arrivalTime", 10);
This will set the location of each operator next to the queue (if your queue isn't in the same place as mine [x:2.00, y:0.00, z:0.00], check the location of your own queue and enter appropriate x, y and z values). This user event will also set the label on the source to 10, so the Inter-arrival time will change accordingly.
- With busytime selected, enter 100 for First Event Time and 200 for Repeat Event Time. Every 200 seconds the model will go into busy time, starting at time 100.
Click the code edit button and write in the following code:
setlabel(source, "arrivalTime", 5); openinput(extraProc1); openinput(extraProc2); msg("Busy Time", "It's Busy Time!");
This will set the inter-arrival time to 5, so parts are created twice as fast. The extra processors will open so they can be used during busy time. You will also get a message telling you it is busy time.
- With slowtime selected, enter 0 for First Event Time and 200 for Repeat Event Time. Every 200 seconds the model will go into slow time, starting at time 0.
- Click the code edit button and write in the following code:
closeinput(extraProc1); closeinput(extraProc2); setlabel(source, "arrivalTime", 10);
This will set the inter-arrival time to 10, so parts come slow again. The extra processors will closed during slow time.
- Press OK on the User Events window to close and apply your changes.
- Reset and run your model. Notice that the operators are always reset to the same place and it switches between busy and slow times.
This completes the User Events tutorial. Congratulations!