gpt4 book ai didi

java - Traci4J 与 SUMO 返回错误

转载 作者:行者123 更新时间:2023-12-02 11:34:38 33 4
gpt4 key购买 nike

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

it.polito.appeal.traci.TraCIException$UnexpectedData:意外的命令/状态 ID:预期 164,得到 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)

很抱歉,如果这很冗长,我们将不胜感激任何帮助

最佳答案

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

如果你想使用 Traas,我可以给你一些提示。您可以在这里找到 WebService 类:traas/src/main/java/de/tudresden/ws/WebService.java这是一个可执行的java文件。然后你将获得一个正在运行的服务器。如果您创建一个 Web 服务客户端,您可以连接 traas 服务器并使用 sumo 进行模拟。顺便说一句,我仍然有些怀疑 traas 的 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();
}
}
}

关于java - Traci4J 与 SUMO 返回错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49041071/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com