Search code examples
javaomnet++veinstraffic-simulation

SUMO and OMNeT++ working together with Java


I am currently working on my Bachelor thesis and my purpose is to create a VANET simulator having the traffic simulator, SUMO, and the network simulator, OMNeT++, working together.

I know there is already one project called Veins that is doing this.

But the problem is that I don't know other languages except for PHP or Java and I think it would take more time for me to try to understand Veins, rather than doing it in Java.

I have seen that, in the case of Java, there is a library called traci4j, which aims to be the substitute to TraCI in Java language.

I think, the first big step to accomplish would be to be able to run SUMO and OMNeT++ from Java. Once I achieve this, then I would proceed to work on the data exchange between both programs.

However, I was making some trials, all of them unsuccessful, to run SUMO-gui from my simple program:

public static void main(String[] args) throws IOException, InterruptedException {

    String configFile = "test/resources/sumo_maps/Test2/Test2.sumo.cfg";
    SumoTraciConnection trial = new SumoTraciConnection(configFile,-1);
    trial.runServer(true);

}

But I keep receive the following. I have tried to follow this with the debug mode but it was a really tedious work and in the end I couldn't get anything.

ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console.
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 9, Size: 7
    at java.util.ArrayList.rangeCheckForAdd(Unknown Source)
    at java.util.ArrayList.add(Unknown Source)
    at it.polito.appeal.traci.SumoTraciConnection.runSUMO(SumoTraciConnection.java:477)
    at it.polito.appeal.traci.SumoTraciConnection.runServer(SumoTraciConnection.java:267)
    at trial.TrialConnection.main(TrialConnection.java:32)

I would really appreciate if you could tell me what is scaping from my thoughts. Any other comment regarding my idea and way of planning my thesis would be also appreciated.

BTW, I am using SUMO 0.25, OMNeT++ 4.6 and Eclipse Mars.2 Release (4.5.2)

Thanks in advance for your attention

EDIT:

I manage to find the origin of the Exception, you can find it as an Answer. However, I keep receiving the error:

ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console.

Anyway, this doesn't seem to affect the running of the program, since I run it succesfully. However, if I don't press the Run button, it doesn't work!


Solution

  • I have discovered the origin of the IndexOutOfBoundsException, it seems that when SumoTraciConnection calls to runServer(int remotePort, boolean withGui), if WithGui is set to true, then it skips the addition of 2 items to the list:

    if (randomSeed != -1) {
        args.add(7, "--seed");
        args.add(8, Integer.toString(randomSeed));
    }
    
    // this avoids validation of the input xml files; if SUMO_HOME is not set correctly,
    // sumo will try to download the schema files from the web and may wait 30 seconds at startup
    // for the connection to time out.
    args.add(9, "--xml-validation");
    args.add(10, "never");