anylogic

How to set pedestrians population and pedestrian speed from the data available in database table(pid and speed)?


I am trying to run a simple model, from targetA to targetB, where I need to set the population of pedestrians and their speed dynamically. I thought of using the data from database table, which have 15 records in the form of pid = "P1" and speed = 1.6 .... so on.

But I am not able to link the data with pedestrians. How do I do that with anylogic?

So I was trying to add and run this block of code in the onExit of pedSource:

List<Object[]> rows = executeQuery("SELECT * FROM table");
if (getIndex() < rows.size()) {
    Object[] row = rows.get(getIndex());
    double speed = (Double) row[1];
    ped.comfortableSpeed = speed;
}

Solution

  • Well, its in your logic, the if-statement is wrong:

    getIndex() gives you the index of the agent in which you call this code, like main. Try it with a traceln(getIndex() and you will see it is always 1.

    Use ped.getIndex() and learn to use the magic light bulb https://benjamin-schumann.com/blog/magic-lightbulb