imit_model / AnyLogic / UsersManual(AnyLogic)
.pdf
AnyLogic V User’s Manual
Time – relative or absolute occurrence time for scheduled events, no value for other events.
Info – inspect string for the event. E.g., if this is a message acting as a dynamic event, this field displays the string returned by the method toString() of the message.
At the event steps of the simulation, there exist current events – those that can be executed at the time now. Among the current events, there is one chosen to be executed next and others are considered as enabled (potentially could be executed next). You can control manually the choice among the current events:
►To change the chosen event
1.Right-click the enabled event and choose Set chosen from the popup menu.
Among the non-current events (those that cannot be executed at the time now) there may be events scheduled at some particular time known in the future, and others that do not know their times (for example, a transition waiting for a change event or a port). The latter ones are called pending, and are not shown in the Events window by default, although you can view them if you wish:
►To show/hide pending events
1.Right-click the events window and choose Hide Pending Events from the popup menu.
The occurrence times of the scheduled events may be displayed either as relative to “now” or as absolute values.
►To display the occurrence times in relative/absolute values
1.Right-click the events window and choose Show Absolute Time from the popup menu. The occurrence time of a scheduled event may be modified.
►To change the occurrence time of a scheduled event
1.Right-click the scheduled event and choose Modify from the popup menu. The Modify Event Scheduling dialog box opens.
© 1992-2004 XJ Technologies http://www.xjtek.com |
347 |
AnyLogic V User’s Manual
►To open the Edit Breakpoints dialog box
1.Choose Model|Edit Breakpoints from the main menu, or Click Alt+F9.
The Edit Breakpoints dialog box is displayed.
►To enable/disable a breakpoint
1.Select/clear the checkbox to the left of the breakpoint.
►To remove a breakpoint
1.Select the breakpoint.
2.Click Remove button.
►To remove all breakpoints
1.Click Remove All button.
►To open the location of a breakpoint
1.Select the breakpoint.
2.Click Open button.
14.4 Logging a model
14.4.1Log window
You can output textual information for a model (global log) or for an individual active object during the model execution in AnyLogic log windows, see Figure 160. You can use it in debugging purposes to trace model execution by writing specific text to the log on different occurrences. The log is displayed as a read-only text, which can be copied onto the Clipboard. The log window of an active object appears in the Properties window when you
© 1992-2004 XJ Technologies http://www.xjtek.com |
349 |
AnyLogic V User’s Manual
14.4.2Writing to logs
Each active object has a log. This is the variable log of type PrintWriter defined in the class ActiveObject. You write to log in the same way as you write to, e.g., System.out. Usually, you use the methods print() and println().
In addition, a model has the so-called global log. This is the variable log of the same type PrintWriter defined as a static member variable of the class Engine. You can access the global log as Engine.log, or simply call the methods trace() and traceln() of the class
ActiveObject. The method trace() calls Engine.log.print(), and the method traceln() calls Engine.log.println().
The global log is convenient for output of information across several model replications, because it is not reset in between replications. It can also be used as a debugging tool, for example, to find out what is the order in which the model executes actions of different objects.
You work with logs using the following API (for more information, please consult AnyLogic Class Reference):
Related member variables and methods of ActiveObject java.io.PrintWriter log – log of the active object.
static void trace( java.lang.String value ) – prints a string to the global log.
static void traceln( java.lang.String value ) – prints a string with a line delimiter to the global log.
Related member variables of Engine
java.io.PrintWriter log – the global model log.
14.5 Runtime errors
Various errors may occur during the model execution. Runtime errors can be of two types:
• Java exceptions
© 1992-2004 XJ Technologies http://www.xjtek.com |
351 |
AnyLogic V User’s Manual
14.5.3Simulation errors
Simulation errors are logical errors of model execution. For example, if a statechart is unable to exit a branch because all exiting transitions are closed, it is a simulation error. Simulation errors are detected by AnyLogic rather than by Java runtime environment. If a simulation error occurs, AnyLogic stops the model and notifies the user with an error message.
14.6 Debugging Java code
AnyLogic does not have a built-in Java code debugger. However, you can debug Java code using a third-party debugger. The user is free to run a model within the debugger using command line execution feature (see section 18.1, “Running a model from the command line”) or to attach the debugger to the currently running model. Using the debugger control, you can trace the code, set breakpoints, output debug information, and so on.
The source code of AnyLogic Engine is not included in the distribution set. You are able to debug your own Java code, and not the engine code.
© 1992-2004 XJ Technologies http://www.xjtek.com |
353 |
Chapter 15. Creating a model with dynamically changing structure
15. Creating a model with dynamically changing structure
AnyLogic is the only visual tool that supports creation of truly dynamic models – the ones with dynamically evolving structure and component interconnection.
AnyLogic supports:
•Dynamic creation and removing of encapsulated objects. It is described in subsection 15.1, “Manual creation and destruction of encapsulated objects”. Moreover, dynamic creation and removing elements of a vector of replicated objects is enabled. See section 2.2, “Accessing and modifying a replicated object at runtime” for details.
•Dynamic changing of interface elements connections. It is described in subsection 15.2, “Dynamically changing connections”.
15.1Manual creation and destruction of encapsulated objects
There are several situations when you may need to take care of the creation of encapsulated objects and tell AnyLogic not to do it automatically:
•The object has a limited lifetime and should be created and destroyed dynamically as the model evolves.
•The object has several constructors and it is not known in advance which one should be called.
•The actual class of the object is not known in advance.
To create an encapsulated object manually, it is sufficient to write the code equivalent to the one generated by AnyLogic. The algorithm of writing the code is the following:
1.Prepare the place where you will store the reference to the encapsulated object. This can be a member variable of the corresponding type, an array, a vector, etc. In case
354 |
© 1992-2004 XJ Technologies http://www.xjtek.com |
AnyLogic V User’s Manual
the encapsulated object is present on the structure diagram, but its property Auto create is not set, the member variable for the reference is generated by AnyLogic, but the encapsulated object is not created. Thus you can create the encapsulated object manually and store the reference in the member variable generated by AnyLogic.
2.When you wish to create an encapsulated object, construct an instance of the corresponding class using operator new and store the reference in the prepared place. Then call the method setup_myObject1() generated by AnyLogic or call the equivalent code. Do not forget to call register(). This method registers the object in AnyLogic simulation engine.
3.If you are creating an encapsulated object during the model initialization, pass false in the parameter autoRun of the method setup_myObject1(). If you are doing this during the model execution, pass true – this makes the encapsulated object automatically start all its activities. For your convenience AnyLogic generates the overloaded method setup_myObject1() that sets the parameter autoRun to true.
4.When you wish to destroy the encapsulated object, call the method dispose_myObject1() or call the equivalent code. Do not forget to call unregister() – this deletes the reference to the object from AnyLogic simulation
engine. Make sure nobody in the model refers to the object and the object itself does not refer to anybody. Note that the object will be deleted by the garbage collector with a certain delay.
In case an encapsulated object is created and destroyed dynamically, its animation appears and disappears synchronously with the object.
15.1.1Writing code executed on object creation and destruction
AnyLogic enables you to write code to be executed on various stages of active object creation and destruction. Thus, you can specify arbitrary actions to be performed on object creation and destruction.
15.1.1.1 Writing code executed on object creation
You can define code to be executed on various stages of active object creation. You can:
© 1992-2004 XJ Technologies http://www.xjtek.com |
355 |

is displayed in the status line. Thus you can trace model execution, detect some undesired activities or events in your model and perform some actions in response to the occurrences.
toolbar button, or Choose