具有SUMO返回错误的Traci4J
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了具有SUMO返回错误的Traci4J相关的知识,希望对你有一定的参考价值。
我是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)
对不起,如果您说得太详细,将不胜感激。
答案
如果您想使用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();
以上是关于具有SUMO返回错误的Traci4J的主要内容,如果未能解决你的问题,请参考以下文章