Java 带有SUMO返回错误的Traci4J

Java 带有SUMO返回错误的Traci4J,java,python,xml,simulation,sumo,Java,Python,Xml,Simulation,Sumo,我对相扑和Traci4J都是新手,但是,我对学习如何使用这些工具感兴趣。我在Traci4J上运行任何东西时都遇到了问题。对SumotraceConnection对象执行nextSimStep()时,我遇到了错误 it.polito.appeal.traci.tracieException$UnexpectedData:意外命令/状态ID:预期164,获得2 我找不到发生这种情况的任何原因,我已经在两台机器上尝试过了,它们都干净地安装了最新版本的SUMO、最新版本的Traci4J和JavaSE1.

我对相扑和Traci4J都是新手,但是,我对学习如何使用这些工具感兴趣。我在Traci4J上运行任何东西时都遇到了问题。对SumotraceConnection对象执行nextSimStep()时,我遇到了错误

it.polito.appeal.traci.tracieException$UnexpectedData:意外命令/状态ID:预期164,获得2

我找不到发生这种情况的任何原因,我已经在两台机器上尝试过了,它们都干净地安装了最新版本的SUMO、最新版本的Traci4J和JavaSE1.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>
<?xml version="1.0" encoding="UTF-8"?>
    <?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)


很抱歉,如果这是冗长的,任何帮助都将不胜感激

我在使用Traci4J时遇到同样的问题

如果你想使用Traas,我可以给你一些提示。 您可以在此处找到WebService类: traas/src/main/java/de/tudresden/ws/WebService.java 这是一个可执行的java文件。然后您将得到一个正在运行的服务器。如果您创建一个web服务客户机,您可以连接到traas服务器,并使用sumo进行模拟。顺便说一下,我仍然怀疑TRAS的API小于Python和C++的API; 这里是一个小演示,假设您已经导入了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[]{});
    }
}
web服务客户端:

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();
    }
  }
}

此外,sumo gui确实正确启动并加载了.sumocfg文件,但在nextSimStep()阶段总是失败。此外,我还尝试了Traci4J中包含的示例,但是,只要使用nextSimStep()方法,就会出现相同的错误。欢迎使用StackOverflow。寻求调试帮助的问题(“为什么这段代码不起作用?”)必须包括所需的行为、特定的问题或错误以及在问题本身中重现它所需的最短代码。没有明确问题陈述的问题对其他读者没有用处。请参阅:。此外,这是一个问答网站-请回答。Traci4J被认为已弃用,请使用TraaS(它应该已经是您的相扑下载的一部分)@Michael我似乎找不到任何方法来启动TraaS(尽管我在sumo/bin目录中找到了可执行的Jar文件)。你知道有什么指南可以帮助像我这样的初学者吗?关于如何启动TraaS还有什么其他的建议吗?你试过这些例子了吗?
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();
    }
  }
}