eclipse-sumo / sumo

Eclipse SUMO is an open source, highly portable, microscopic and continuous traffic simulation package designed to handle large networks. It allows for intermodal simulation including pedestrians and comes with a large set of tools for scenario creation.
https://eclipse.dev/sumo
Eclipse Public License 2.0
2.55k stars 1.43k forks source link

Error of reading byte in findRoute function #5515

Closed YenKang closed 5 years ago

YenKang commented 5 years ago

Error of reading byte in findRoute function

Dear @behrisch, @mkrumnow , @namdre

I faced a failure in findRoute after I re-writed your version of java_library.

The findRoute function involved several files including Main.java, Simulation.java, SumoCommand.java and CommandProcessor.java and I did some repairment on those files.

However, The sumo-gui shut down and the console in eclipse showed the messages

java.lang.IllegalStateException: Error reading byte, invalid list position specified for reading: 706 at de.uniluebeck.itm.tcpip.Storage.readByte(Storage.java:141) at de.uniluebeck.itm.tcpip.Storage.readString(Storage.java:502) at de.uniluebeck.itm.tcpip.Storage.readStringASCII(Storage.java:462) at de.tudresden.sumo.util.CommandProcessor.readStage(CommandProcessor.java:881) at de.tudresden.sumo.util.CommandProcessor.do_job_get(CommandProcessor.java:783) at it.polito.appeal.traci.SumoTraciConnection.do_job_get(SumoTraciConnection.java:366) at Main.main(Main.java:94)

1.Main.java

System.out.println("---------------findRoute-----------------");
String fromEdge = "307244665#2";
String toEdge = "496332196#1";
String vType = "routeByDistance";
double depart = 40.0;
int routingMode = 0;
SumoStage stage = (SumoStage) conn.do_job_get(Simulation.findRoute(fromEdge, toEdge, vType, depart, routingMode));
System.out.println(stage.edges);

2.SumoCommand.java

else if ((Integer) input1 == Constants.CMD_GET_SIM_VARIABLE && (Integer) input2 == Constants.FIND_ROUTE) {
    cmd.content().writeInt(5);
    cmd.content().writeUnsignedByte(Constants.TYPE_STRING);
    cmd.content().writeStringASCII((String) array[0]);
    cmd.content().writeUnsignedByte(Constants.TYPE_STRING);
    cmd.content().writeStringASCII((String) array[1]);
    cmd.content().writeUnsignedByte(Constants.TYPE_STRING);
    cmd.content().writeStringASCII((String) array[2]);
    cmd.content().writeUnsignedByte(Constants.TYPE_DOUBLE);
    cmd.content().writeDouble((double) array[3]);
    cmd.content().writeUnsignedByte(Constants.TYPE_INTEGER);
    cmd.content().writeInt((Integer) array[4]);

}

The above adding codes were inserted in the constructor "public SumoCommand(Object input1, Object input2, Object input3, Object[] array, Object response, Object output_type)"

3.map_from_flow.rou.xml

<vType id="routeByDistance" maxSpeed="1"/>

4.CommandProcessor.java

    public static SumoStage readStage(Storage content){
        SumoStage result = new SumoStage();
        content.readInt(); // Component (13)

        content.readUnsignedByte();
        result.type = content.readInt();

        content.readUnsignedByte();
        result.vType = content.readStringASCII();
        content.readUnsignedByte();
        result.line = content.readStringASCII();
        content.readUnsignedByte();
        result.destStop = content.readStringASCII();
        content.readUnsignedByte();

        int size = content.readInt(); // number of edges
        for(int i=0; i<size; i++){
            result.edges.add(content.readStringASCII());
        }

        content.readUnsignedByte();
        result.travelTime = content.readDouble();
        content.readUnsignedByte();
        result.cost = content.readDouble();
        content.readUnsignedByte();
        result.length = content.readDouble();
        content.readUnsignedByte();
        result.intended = content.readStringASCII();
        content.readUnsignedByte();
        result.depart = content.readDouble();
        content.readUnsignedByte();
        result.departPos = content.readDouble();
        content.readUnsignedByte();
        result.arrivalPos = content.readDouble();
        content.readUnsignedByte();
        result.description = content.readStringASCII();
        return result;
    }

Finally, I think there is a tricky problem in Traci/Simulation/findRoute. findRoute

The response format did not meet the the data in SumoStage because the number of component in readStage is 13 and the number of response number of component in the above picture is 5.

Therefore, I was stuck on this issue.

Sincerely,

Kang Yen

namdre commented 5 years ago

I'm not sure what you are trying to accomplish. The function Simulation.findRoute is working as expected in our own TraaS test (https://github.com/eclipse/sumo/blob/master/tools/contributed/traas/examples/APITest.sh)

YenKang commented 5 years ago

Dear @namdre , I was thankful for your fast reply yesterday, and my original goal is to accomplish this line

SumoStage stage = (SumoStage) conn.do_job_get(Simulation.findRoute(fromEdge, toEdge, vType, depart, routingMode));

However, the error occured

java.lang.IllegalStateException: Error reading byte, invalid list position specified for reading: 221 at de.uniluebeck.itm.tcpip.Storage.readByte(Storage.java:141) at de.uniluebeck.itm.tcpip.Storage.readString(Storage.java:502) at de.uniluebeck.itm.tcpip.Storage.readStringASCII(Storage.java:462) at de.tudresden.sumo.util.CommandProcessor.readStage(CommandProcessor.java:881) at de.tudresden.sumo.util.CommandProcessor.do_job_get(CommandProcessor.java:783) at it.polito.appeal.traci.SumoTraciConnection.do_job_get(SumoTraciConnection.java:366) at Main.main(Main.java:93) main-2

After checking the APITest.sh, I started to git clone the newest version of SUMO and complied APITest.java by elicpse and runed this line

SumoStage stage = (SumoStage)conn.do_job_get(Simulation.findRoute("gneE0", "gneE2", "car", 0, 0));

The similar error happened again

Error reading byte, invalid list position specified for reading: 90

APItest

Futhermore,

when I changed the pair of fromEdge and toEdge, the number in invalid list position specified for reading would changed.

Finally,

My sepcific problem is how to fix Error reading byte and "invalid list position" problem.

ps. The [folder] includes all my files(https://github.com/YenKang/Smart-Logistics-Plan/tree/master/eclipse%20workspace/java_library/java_library).

Ich danke Ihnen!

Kang Yen

namdre commented 5 years ago

I would guess that the difference between your result and mine is due to a difference in the sumo version being called. APITest accepts the path to the sumo binary as the first command line argument. Please check what happens if you explicitly set the path to a sumo binary of version 1.2.0 or later.

YenKang commented 5 years ago

Dear @namdre , After I downloaded the newest version of sumo (Version 1.2.0), configured the bin/sumo environment path and executed my previous codes of findRoute function,

the findRoute function can work!!!

4

5

Really Really thank for your useful and clear guide to my question!

Sincerely, Kang Yen

namdre commented 5 years ago

Yay!