Traci4J с ошибкой возврата SUMO

Я новичок в SUMO и Traci4J, однако мне интересно научиться использовать эти инструменты. Я столкнулся с проблемой при запуске практически чего-либо на Traci4J. При выполнении nextSimStep() для объекта SumoTraciConnection я встречаюсь с ошибкой

it.polito.appeal.traci.TraCIException$UnexpectedData: Неожиданный идентификатор команды/состояния: ожидалось 164, получено 2

Я не могу найти причину этого, я пробовал это на 2 машинах с чистой установкой последней версии SUMO, последней версии Traci4J и Java SE 1.7.

Основной метод

    public static void main(String[] args) {
    SumoTraciConnection sumo;

    sumo = new SumoTraciConnection(URL_TO_SUMOCFG, (int) System.nanoTime());
    sumo.addOption("start", "1");
    try {
        sumo.runServer(true);
        sumo.nextSimStep();
        sumo.close();
    }catch(IOException | InterruptedException e) {
        e.printStackTrace();
    }
}

Файл hello.sumocfg

<input>
    <net-file value="hello.net.xml"/>
    <route-files value="hello.rou.xml"/>
</input>

<time>
    <begin value="0"/>
    <end value="10000"/>
</time>

<gui_only>
    <gui-settings-file value="hello.settings.xml"/>
</gui_only>

Файл hello.net.xml

<?xml version="1.0" encoding="UTF-8"?>
-->

<location netOffset="250.00,0.00" convBoundary="0.00,-71.61,501.00,0.00" origBoundary="-250.00,0.00,251.00,0.00" projParameter="!"/>

<edge id=":2_0" function="internal">
    <lane id=":2_0_0" index="0" speed="13.90" length="0.10" shape="500.00,-1.65 500.00,-1.65"/>
</edge>

<edge id="1to2" from="1" to="2" priority="-1">
    <lane id="1to2_0" index="0" speed="13.90" length="500.00" shape="0.00,-1.65 500.00,-1.65"/>
</edge>
<edge id="gneE0" from="gneJ0" to="gneJ1" priority="1">
    <lane id="gneE0_0" index="0" speed="13.89" length="153.61" shape="227.09,-64.38 380.45,-73.25"/>
</edge>
<edge id="out" from="2" to="3" priority="-1">
    <lane id="out_0" index="0" speed="13.90" length="1.00" shape="500.00,-1.65 501.00,-1.65"/>
</edge>

<junction id="1" type="dead_end" x="0.00" y="0.00" incLanes="" intLanes="" shape="0.00,-0.05 0.00,-3.25"/>
<junction id="2" type="priority" x="500.00" y="0.00" incLanes="1to2_0" intLanes=":2_0_0" shape="500.00,-0.05 500.00,-3.25 500.00,-0.05">
    <request index="0" response="0" foes="0" cont="0"/>
</junction>
<junction id="3" type="dead_end" x="501.00" y="0.00" incLanes="out_0" intLanes="" shape="501.00,-3.25 501.00,-0.05"/>
<junction id="gneJ0" type="dead_end" x="227.19" y="-62.74" incLanes="" intLanes="" shape="227.18,-62.79 227.00,-65.98"/>
<junction id="gneJ1" type="dead_end" x="380.54" y="-71.61" incLanes="gneE0_0" intLanes="" shape="380.35,-74.85 380.54,-71.66"/>

<connection from="1to2" to="out" fromLane="0" toLane="0" via=":2_0_0" dir="s" state="M"/>

<connection from=":2_0" to="out" fromLane="0" toLane="0" dir="s" state="M"/>

Файл hello.rou.xml

    <?xml version="1.0" encoding="UTF-8"?>

<!-- generated on 14/02/2018 21:20:37 by Netedit Version 0.31.0
<?xml version="1.0" encoding="UTF-8"?>

<configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/netconvertConfiguration.xsd">

    <input>
        <sumo-net-file value="hello.net.xml"/>
    </input>

    <output>
        <output-file value="hello.net.xml"/>
    </output>

    <processing>
        <no-turnarounds value="true"/>
        <offset.disable-normalization value="true"/>
        <lefthand value="false"/>
        <junctions.corner-detail value="0"/>
        <rectangular-lane-cut value="false"/>
        <walkingareas value="false"/>
    </processing>

    <visualisation>
        <registry-viewport value="true"/>
    </visualisation>

</configuration>
-->

<net version="0.27" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/net_file.xsd">

    <location netOffset="250.00,0.00" convBoundary="0.00,-71.61,501.00,0.00" origBoundary="-250.00,0.00,251.00,0.00" projParameter="!"/>

    <edge id=":2_0" function="internal">
        <lane id=":2_0_0" index="0" speed="13.90" length="0.10" shape="500.00,-1.65 500.00,-1.65"/>
    </edge>

    <edge id="1to2" from="1" to="2" priority="-1">
        <lane id="1to2_0" index="0" speed="13.90" length="500.00" shape="0.00,-1.65 500.00,-1.65"/>
    </edge>
    <edge id="gneE0" from="gneJ0" to="gneJ1" priority="1">
        <lane id="gneE0_0" index="0" speed="13.89" length="153.61" shape="227.09,-64.38 380.45,-73.25"/>
    </edge>
    <edge id="out" from="2" to="3" priority="-1">
        <lane id="out_0" index="0" speed="13.90" length="1.00" shape="500.00,-1.65 501.00,-1.65"/>
    </edge>

    <junction id="1" type="dead_end" x="0.00" y="0.00" incLanes="" intLanes="" shape="0.00,-0.05 0.00,-3.25"/>
    <junction id="2" type="priority" x="500.00" y="0.00" incLanes="1to2_0" intLanes=":2_0_0" shape="500.00,-0.05 500.00,-3.25 500.00,-0.05">
        <request index="0" response="0" foes="0" cont="0"/>
    </junction>
    <junction id="3" type="dead_end" x="501.00" y="0.00" incLanes="out_0" intLanes="" shape="501.00,-3.25 501.00,-0.05"/>
    <junction id="gneJ0" type="dead_end" x="227.19" y="-62.74" incLanes="" intLanes="" shape="227.18,-62.79 227.00,-65.98"/>
    <junction id="gneJ1" type="dead_end" x="380.54" y="-71.61" incLanes="gneE0_0" intLanes="" shape="380.35,-74.85 380.54,-71.66"/>

    <connection from="1to2" to="out" fromLane="0" toLane="0" via=":2_0_0" dir="s" state="M"/>

    <connection from=":2_0" to="out" fromLane="0" toLane="0" dir="s" state="M"/>

</net>

Трассировка сообщений об ошибках

it.polito.appeal.traci.TraCIException$UnexpectedData: Unexpected command/status ID: expected 164, got 2
at it.polito.appeal.traci.Utils.checkStatusResponse(Utils.java:57)
at it.polito.appeal.traci.ChangeStateQuery.pickResponses(ChangeStateQuery.java:83)
at it.polito.appeal.traci.MultiQuery.run(MultiQuery.java:108)
at it.polito.appeal.traci.SumoTraciConnection.nextSimStep(SumoTraciConnection.java:623)
at it.polito.appeal.traci.test.TraCITest.getFirstVehicle(TraCITest.java:337)
at it.polito.appeal.traci.test.TraCITest.testChangeTarget(TraCITest.java:577)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

Извините, если это многословно, любая помощь будет очень признательна


person SocialGamification    schedule 01.03.2018    source источник
comment
Кроме того, sumo-gui действительно запускается и правильно загружает файл .sumocfg, но всегда дает сбой на этапе nextSimStep(). Кроме того, я пробовал примеры, включенные в Traci4J, однако всякий раз, когда используется метод nextSimStep(), возникает та же ошибка.   -  person SocialGamification    schedule 01.03.2018
comment
Добро пожаловать в StackOverflow. Вопросы по отладке (почему этот код не работает?) должны включать желаемое поведение, конкретную проблему или ошибку и кратчайший код, необходимый для их воспроизведения в вопросе. сам. Вопросы без четкого формулирования проблемы бесполезны для других читателей. См. раздел Как создать минимальный, полный и проверяемый пример. Кроме того, это сайт вопросов и ответов - пожалуйста, задайте вопрос, который может быть ответил.   -  person NightOwl888    schedule 01.03.2018
comment
Traci4J считается устаревшим, используйте TraaS (который уже должен быть частью вашей загрузки сумо)   -  person Michael    schedule 01.03.2018
comment
@Michael Майкл, похоже, я не могу найти способ запустить TraaS (хотя я нашел исполняемый файл Jar в каталоге sumo/bin). Знаете ли вы какое-нибудь руководство, которое поможет таким новичкам, как я? Любые другие советы о том, как запустить TraaS?   -  person SocialGamification    schedule 02.03.2018
comment
Пробовали ли вы примеры traas.sourceforge.net/cms/index.php ?id=examples-1 ?   -  person Michael    schedule 06.03.2018
comment
@Michael, у меня есть, но я не уверен, как выполнить любой из этих примеров. В папке SUMO есть исполняемый файл TraaS, но он не запускается при двойном щелчке (по крайней мере, не с графическим интерфейсом). Любая помощь приветствуется.   -  person SocialGamification    schedule 07.03.2018
comment
Вам нужно использовать его в пути к классам при запуске приложения. Думаю, как и в случае с TraCI4J.   -  person Michael    schedule 14.03.2018


Ответы (1)


Я встречаю тот же вопрос при использовании Traci4J.

Если вы хотите использовать Traas, я могу дать вам несколько советов. Вы можете найти класс WebService здесь: traas/src/main/java/de/tudresden/ws/WebService.java Это исполняемый файл Java. После этого вы получите работающий сервер. Если вы создаете клиент веб-службы, вы можете подключиться к серверу traas и выполнить симуляцию с сумо. Кстати, у меня все еще есть некоторые сомнения, что API traas меньше, чем API для Python и C++; Вот небольшая демонстрация, предполагающая, что вы уже импортировали файл traas.jar;

public class MyWebService {
    public static void main(String[] args) {
        Config.config_file = "resources/map.sumo.cfg";
        de.tudresden.ws.WebService.main(new String[]{});
    }
}

Клиент веб-сервиса:

public class HelloWorldClient {
  public static TraasWSLocator locator;
  public static ServiceImpl service;

  static {
    try {
      locator = new TraasWSLocator();
      service = locator.getServiceImplPort();
    }
    catch (Exception e){
      e.printStackTrace();
    }
  }

  public static void main(String[] argv) throws RemoteException{
    service.setSumoBinary("sumo-gui");
    service.start("username");
    while (service.simulation_getMinExpectedNumber()>0){
        service.doTimestep();
    }
  }
}
person recluse    schedule 21.12.2019