"cannot be resolved or is not a field" Anylogic 事件条件错误

"cannot be resolved or is not a field" error in Anylogic event condition

请有人帮忙,我是 Java 和 Anylogic 的新手!

我在名为“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

条件中的代码是:

studenti_Rijeka.inState(studenti_Rijeka.Brucoši)<=studenti_Rijeka.Upisna_kvota_RI &&
studenti_Rijeka.potražnja_RI>=studenti_Rijeka.Upisna_kvota_RI

"studenti_Rijeka" 是 Main 中的代理,"Brucoši" 是代理 studenti_Rijeka 内状态图中的状态, “Upisna_kvota_RI”和“potražnja_RI”是同一个代理中的参数。

这是代码(在 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 );
  }

并且参数potražnja_RI编码为:

     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();
  }

我显然仍然遗漏了如何在表达式中使用某些参数的要点,并且不知道如何正确 post 一个问题 :-/

如果我想使事件的条件为:xy<5,如何在位于 Main 的事件中的代理 abc(ABC 类型)中使用参数 xy? AnyLogic 将 returns 错误“xy 无法解析或不是字段”。

请帮忙!

当您调用 inState(Statename) 时,您应该引用代理类型而不是代理实例以获取状态名称。

例如 count(customers,c->c.inState(Customer.greenState))

其中Customer为代理类型(大写字母)

类似问题见此问题

我假设你的代码必须是

studenti_Rijeka.inState(Studenti_Rijeka.Brucoši)

如果 studenti_RijekaStudenti_Rijeka

的实例

请记住,您不能询问人口是否处于状态,代理人口只是一个集合...您需要询问该州中的每个个体代理

例如

for (Rijeka rijeka:studenti_Rijeka) {
   if (riejka.inState(Rijeka.Brucoši)) {
      traceln("do something");
   }
}