Yashar Ahmadov
Yashar Ahmadov

Reputation: 1636

AnyLogic - how to avoid fillSchedule error when the schedule is empty?

I have a simulation model that contains several schedules for moving the trucks between origin and destination stations. The inputs are created automatically by a Python script and in some cases, one or two of the schedules can be empty - meaning that I don't want the trucks move in those directions. An example is given below:

enter image description here

In such cases, the model throws the following error:

enter image description here

Is there a more elegant way of suppressing this error? (i.e. except giving a dummy row as input with all zeros)

Upvotes: 1

Views: 69

Answers (1)

Jaco-Ben Vosloo
Jaco-Ben Vosloo

Reputation: 3930

The problem here is that since the scehdules are dragged onto the canvas they get created automatically when the Main agent gets created and you have no control over them... you can't do try() catch() and you also can't prevent them from being created if their tables are empty... or just let them be created with a blank value...

You have two options:

Option 1: So you need to create the schedules programmatically - using the trick described in this article - you can get to the code used to create the schedules.


 public Schedule<Integer> schedule = new Schedule<Integer>(
    this, true, SUNDAY, 7L * TIME_UNIT_DAY, TIME_UNIT_DAY, null, 0, _schedule_Starts_xjal(), null, _schedule_Values_xjal(), false, null, true, true );
  

and then the schedule gets populated using


if (schedule.isInitialized()) {
        new TableElementDatabaseBuilder(this).setSqlQuery("SELECT time, unit FROM truck_sc_ip").fillSchedule(
          schedule,
          Integer.class,
          true,
          true,
          604800000L,
          false,
          false,
          3600000L
          );
    }

You also need to create two variables for each schedule...

Object[] _schedule_Values_xjal() and Object[]_schedule_Starts_xjal()

There might be some other parts of the logic that gets created that I missed here but this should be sufficient.

Option 2: The alternative is that you simply read in the entries into the DB and create your own Java class that you use as a schedule (my personal preference)

Upvotes: 1

Related Questions