0
votes

After following the advice given in the answer for this question, I ended up with a model with:

  • An empty population of agents in main

  • A statechart in said agent type that references main (made possible by the previous point)

  • A discrete event flowchart, that references the state of the agents

But after building the model, 3 type and casting errors have appeared, and they are in autogenerated code. I don't understand what functionality is provided by said code.

For context, my model is called "Trenes", and my agent type is "Train". All the errors happen inside the Train java file. The exceptions happen in the following snippets:

first one:

  // User API -----------------------------------------------------
  public Main get_Main() {
    {
      Agent owner = getOwner();
      if ( owner instanceof Main ) return (Main) owner;
    }
    return null;
  }

This one causes Cannot cast from Agent to Main, thanks to the casting (Main) owner. It also causes Incompatible conditional operand types Agent and Main. because of owner instanceof Main.

second one:

  @AnyLogicInternalCodegenAPI
  private void setupReferences_xjal() {
    main = get_Main();
  }

This one calls the method from the first snippet and causes a Type mismatch: cannot convert from org.eclipse.jdt.internal.compiler.batch.Main to trenes.Main. in the line main = get_Main();

I'd be grateful if someone could guide me about what kind of graphical interface configurations could result in these errors, and how could I correct it without undoing my work with the statechart that references main.

Editing to add captures of the structure of my model and the relevant logic:

1
show the flowchart, your statechart (and where both are located) and the code you used in both and where you use it.Felipe
Thanks @Felipe, I already added captures of the model.Cristian Camilo Garcia Barrera

1 Answers

0
votes

You might have messed up some internal coding, this can happen in rare cases.

Try this:

  • Create a completely new class TrainNew
  • embedd it on Main as an agent population
  • bit by bit "move over" your functionality (state charts, functions, variables) from Train to TrainNew
  • delete Train entirely and resolve any final conflicts (by pointing to TrainNew