kns43b
kns43b

Reputation: 1

Moving AnyLogic agents according to database table

My model has a collection of trucks, where the Source block provides each truck with a unique ID. I also have a database containing information on the vehicles' movements.

Movement Information

No column has unique values, but together the trip_start_date and vehicle_id should be a unique set. I'm trying to structure a moveTo block such that when a date in the trip_start_time column is reached during the model runtime, then the agent with that vehicle_id as a parameter will move to the lat/long in a certain amount of time.

Structure of latitude argument (longitude and trip time are similar)

However, I'm getting an "empty database value result." I'm wondering if this is because it's expecting every model date to have an entry? I considered making a function that's called when a date in the database is encountered, but I was told that the moveTo block should be able to handle this activity. Help in resolving this issue would be greatly appreciated!

Upvotes: 0

Views: 215

Answers (1)

Jaco-Ben Vosloo
Jaco-Ben Vosloo

Reputation: 3975

The way you are trying to use the MoveTo block is not correct. It is hard to explain here but I think you need to go through a few tutorials inside help to get a better fundamental understanding.

However, below is a reproducible example of the behavior I think you want to implement, but using agent-based approach instead of a process-centric or discrete event approach.

I have an agent called Vehicle with a ID called vehicle ID.

There is a Dynamic event has all the parameters found in the DB

enter image description here

Then at the start of the model, we generate all the moveTo events found in the Database using the code below.


List<Tuple> rows = selectFrom(db_table)
    .where(db_table.vehicle_id.eq(vehicleID))
    .list();

for (Tuple row : rows) {
    //What is the start time of the movement
    double timeToTripBegin = dateToTime(row.get( db_table.trip_begin_time ));
    //Lets create a new movement event to trigger the movement int he future
    create_MoveToLocation(timeToTripBegin, 
        row.get( db_table.latitude ), 
        row.get( db_table.longitude ), 
        row.get( db_table.trip_duration_h ));
}

This event will then execute the move to when the time arrives

Upvotes: 0

Related Questions