imit_model / AnyLogic / UsersManual(AnyLogic)
.pdf
AnyLogic V User’s Manual
►To remove an additional stop condition
1.Select the condition in the Additional stop conditions list.
2.Click the Remove button.
13.4 Controlling model replications
AnyLogic enables you to control model replications either using AnyLogic experiment’s properties, or programmatically.
13.4.1Writing code to be executed between model replications
AnyLogic enables you to specify arbitrary actions to be performed between model replications. You can write any Java code to be executed before and after each model replication on the Code page of the project’s properties window.
►To write code to be executed between model replications
1.In the Project window, click the project item (the top-most item in the workspace tree).
2.On the Code page of the Properties window, type code to be executed before each model replication in the Before replication section.
3.Type code to be executed after each model replication in the After replication section.
13.4.2API to control replications
You can control simulations and replications programmatically by overriding the method executionControl() of the root object of the model. The mechanism of controlling replications is based on the following feature of the root object:
© 1992-2004 XJ Technologies http://www.xjtek.com |
337 |
AnyLogic V User’s Manual
double fa = result;
param = b; Engine.execute(); double fb = result;
assert(
fa * fb < 0,
“The function sign must be different on the interval ends”
);
while ( b – a > eps ) { param = ( a + b ) / 2; Engine.execute();
if ( result == 0 ) break;
if ( result * fa > 0 ) { fa = result;
a = param;
}
else {
fb = result; b = param;
}
}
}
© 1992-2004 XJ Technologies http://www.xjtek.com |
339 |
Chapter 14. Debugging a model
14. Debugging a model
AnyLogic supports model debugging. This chapter provides information on AnyLogic debugging tools.
•AnyLogic supports on-the-fly checking of types, parameters, and diagram syntax. The errors found during code generation and compilation are displayed in AnyLogic Output window and graphically highlighted in error location windows.
•Using AnyLogic Events window, you can view the event queue of AnyLogic simulation engine to view what is happening at the simulation engine at the lowest level details and to make some changes to the event processing.
•You can debug your model by setting a breakpoint on a model element to stop the model execution when this element becomes active, examine the model state, and perform some actions in response.
•AnyLogic supports runtime error ability. You can throw runtime error and terminate model execution as a reaction to different undesirable occurrences.
•You can trace model execution by writing custom information to AnyLogic log windows on different occurrences.
•AnyLogic detects errors in Java code written by the user and logical errors of model execution (simulation errors). If such an error occurs, AnyLogic stops the model and notifies you with error message.
•You can debug Java code using a third-party debugger by running the model within the debugger using command line execution feature or by attaching the debugger to the currently running model.
14.1Checking model syntax
AnyLogic supports on-the-fly checking of types, parameters, and diagram syntax. The errors found during code generation and compilation are displayed in AnyLogic Output window (see Figure 156). For each error, the Output window displays description and location.
340 |
© 1992-2004 XJ Technologies http://www.xjtek.com |
AnyLogic V User’s Manual
Figure 156. Output window
► To show/hide the Output window
1.Click the Output
toolbar button, or Choose View|Output from the main menu, or Press Alt+2.
You can open an error. Depending on the error, opening it may result in displaying different windows If, for example, it is a graphical error, the corresponding diagram is opened with invalid shapes highlighted.
►To open an error
1.Double-click the error in the Output window.
It is not always possible to give an exact error location in AnyLogic windows. For example, if you are trying to use an identifier Java cannot resolve, it could be an undeclared variable, or a parameter, or anything else. In such cases, AnyLogic displays a .java file and positions the cursor at the error location. This file is opened read-only and it is up to you to track down the real error location in AnyLogic.
►To copy error messages on the Clipboard
1.Select the error messages you want to copy.
© 1992-2004 XJ Technologies http://www.xjtek.com |
341 |
AnyLogic V User’s Manual
•Some scheduled events may be deleted, and the new events may be scheduled in the AnyLogic Engine event queue.
14.2.1.1 Engine events
AnyLogic engine events are events that occur at runtime. Please do not confuse them with static/dynamic events that are a part of AnyLogic modeling language. There are several types of engine events:
•current – events that can be executed at the time now
•chosen – one of the enabled events that is chosen to be executed next
•enabled – other current events (those that potentially could be executed next)
•scheduled – events scheduled at some particular known time in the future
•pending – events that may occur in the future, but the time is not known
Engine events reside in the engine event queue. Any event present in the engine event queue may be associated with:
•An active timer
•A transition triggered on a timeout expiry
•A thread executing a delay() statement
In addition, current events may be associated with something that has just happened as a result of other event execution:
•A transition being triggered by a port, immediately, or by a static, signal or change event
•A thread successfully exiting its waitEvent() or waitForMessage() statement
14.2.1.2 Time step
If there are no current events, AnyLogic makes a time step to the nearest event (or events) in the queue, i.e., advances its clock. During a time step a change event may occur. The discrete part of AnyLogic engine does not know when a change event associated with a transition occurs: it depends on the equation set being solved numerically by a continuous part of the
© 1992-2004 XJ Technologies http://www.xjtek.com |
343 |
|
|
|
|
AnyLogic V User’s Manual |
|
|
Events scheduled |
H |
|
B |
D |
to occur at the |
G |
|
same time |
|
|||
A |
C |
E |
F |
I |
Past Now Future |
|
|
|
time |
Time step: the clock is advanced to A and B - the head of the event queue. Active algebraic-differential equations are being solved. The event queue remains unchanged.
|
Chosen |
|
H |
|
B |
event |
|
G |
|
D |
|
|
||
Current events |
C |
E |
F |
I |
A |
||||
Past Now |
Future |
|
|
time |
Event step: B is chosen and occurs. No time elapses. Model state changes. A, E and G are deleted from the event queue. J and K are scheduled.
D |
|
H |
K |
C |
J |
F |
I |
Past Now Future |
|
|
time |
Time step: the clock is advanced to C and D. Active algebraic-differential equations are being solved. Suddenly change event Q is detected.
|
D |
|
H |
K |
Q |
C |
J |
F |
I |
Past Now |
Future |
|
|
time |
Event step: Q is chosen and occurs. No time elapses. Model state changes. C and K are deleted from the event queue. L is scheduled.
|
|
L |
|
|
|
H |
|
D |
J |
F |
I |
Past Now Future |
|
|
time |
Time step: the clock is advanced to D …
Figure 157. AnyLogic event queue (pending events not shown)
© 1992-2004 XJ Technologies http://www.xjtek.com |
345 |

toolbar button, or Choose
for the chosen event,
for enabled events, no flag for other events.