Issue
Please somebody help, I'm very new to Java and Anylogic!
I'm getting errors in the Condition part of the Event named "Upis_studenta_RI":
Upisna_kvota_RI cannot be resolved or is not a field. Location: Model-1/Main/Upis_studenta_RI - Event
/> potražnja_RI cannot be resolved or is not a field. Location: Model-1/Main/Upis_studenta_RI - Event
Brucoši cannot be resolved or is not a field. Location: Model-1/Main/Upis_studenta_RI - Event
The code in Condition is:
studenti_Rijeka.inState(studenti_Rijeka.Brucoši)<=studenti_Rijeka.Upisna_kvota_RI &&
studenti_Rijeka.potražnja_RI>=studenti_Rijeka.Upisna_kvota_RI
"studenti_Rijeka" is agent in Main, "Brucoši" is State in statechart inside agent studenti_Rijeka, "Upisna_kvota_RI" and "potražnja_RI" are parameters in same agent.
Here is the code (generated in AnyLogic)
@Override
@AnyLogicInternalCodegenAPI
public boolean testConditionOf( EventCondition _e ) {
if ( _e == Upis_studenta_RI) return
studenti_Rijeka.inState(studenti_Rijeka.Brucoši)<=studenti_Rijeka.Upisna_kvota_RI &&
studenti_Rijeka.potražnja_RI>=studenti_Rijeka.Upisna_kvota_RI
;
return super.testConditionOf( _e );
}
And parameter potražnja_RI is coded:
public
double potražnja_RI;
/**
* Returns default value for parameter <code>potražnja_RI</code>.
* <i>This method should not be called by user</i>
*/
@AnyLogicInternalCodegenAPI
public double _potražnja_RI_DefaultValue_xjal() {
final Rijeka self = this;
return
50
;
}
public void set_potražnja_RI( double value ) {
if (value == this.potražnja_RI) {
return;
}
double _oldValue_xjal = this.potražnja_RI;
this.potražnja_RI = value;
onChange_potražnja_RI_xjal( _oldValue_xjal );
onChange();
}
I'm obviously still missing the point how to use some parameter in expressions, and dont know how to properly post a question :-/
How to use parameter xy in agent abc (of type ABC) in event located in Main, if I want to make condition of event: xy<5? AnyLogic will returns error "xy cannot be resolved or is not a field".
Please help!
Solution
When you call inState(Statename)
you should reference the Agent type not the instance of the agent in order to get the statename.
For example
count(customers,c->c.inState(Customer.greenState))
Where Customer
is the agent type (In capital letters)
See this question for a similar problem
I assume your code must then be
studenti_Rijeka.inState(Studenti_Rijeka.Brucoši)
if studenti_Rijeka
is an instance of Studenti_Rijeka
Remember that you cant ask a population if it is in state, a population of agents is just a collection... you need to ask each individual agent in the state
for example
for (Rijeka rijeka:studenti_Rijeka) {
if (riejka.inState(Rijeka.Brucoši)) {
traceln("do something");
}
}
Count all agents that are in certain state
Answered By - Jaco-Ben Vosloo
Answer Checked By - Terry (JavaFixing Volunteer)