0
votes

recently I stumbled upon one of the videos of Benjamin Schumann titled: What are dynamic and action parameters and when should you use them in your AnyLogic model.

I tried to further adjust the functions of dynamic and action based parameters for a problem of mine. Just to give a heads up, I am fairly new to Anylogic (only worked through that one book, and some minor projects and tutorials) and been decent in Java (been a few years since I've been actively working in Java but currentlystarting to get back in [still rusty]). Regarding my actual problem, in the video Mr. Schumann has an agent with three parameters. One static, one dynamic and one action. In addition to that he has a variable (double) all set in his agent. On his main is a button to increment the value of the variable with the help of the parameters and to trace the lines in the console (= giving out a string if a certain threshold of the variable is passed).

I created a similar setting, however I happen to run into a lot of variable errors during time to time while compiling.

Here some example code snippets:

dynamic parameter p_Station of the type String

v_myFahrt < 222 ? "Wiesbaden Hbf" : 
v_myFahrt < 442 ? "Wiesbaden-Biebrich Bahnhof Wiesbaden Ost"    :
v_myFahrt < 663 ? "Wiesbaden-Mainz-Kastel Bahnhof"  :
"Hochheim (Main) Bahnhof"

therefore my variable is called v_myFahrt, a double with the initial value of 0

action parameter p_durchFahrt with the default action:

v_myFahrt = v_myFahrt + 220;

and my Button on the main:

myAgent.p_durchFahrt();
traceln(myAgent.p_Station());

So basically it is a somewhat similar code as in the reference. I tried to than add another instance of the agent with a different set of "code" for the dynamic parameter (different Strings and values) as well as a different "code" for the action parameter (e.g. + 208 instead of + 220). To then wanting to trace the lines in the console with the button again. I tried to add

myAgent1.p_durchFahrt(); traceln(myAgent1.p_Station());

to it. But before I coul even run it, I keep getting the error "v_myFahrt cannot be resolved to a variable" for myAgent1. Inspecting the error it keeps referring to myAgent1 with the newly added code for p_Station and I can't seem to find a way around it.

What am I doing majorly wrong here?

1

1 Answers

0
votes

it looks like you have created v_myFahrt in main, right? (that would explain your symptoms). If yes, you should create it in MyAgent instead.