我试图获得移动到特定点所需的预期时间。这是我正在使用的代码:
long getTimeToReachGivenPoint(Point point) {
System.out.println("Point: " + point);
List<Point> path = getRoadModel().getShortestPathTo(this, point);
System.out.println("Path: " + path);
System.out.println("Path length: " + path.size());
Measure<Double,Length> distance = getRoadModel().getDistanceOfPath(path);
long time = (long) (distance.getValue()/AgvAgent.SPEED);
return time;
}
当我运行时,我得到以下输出:
point: (8.0,36.0)
Path: [(12.0,28.22222222222222), (12.0,32.0), (12.0,36.0), (8.0,36.0)]
Path length: 4
以下例外:
Exception in thread "Thread-0" java.lang.IllegalArgumentException: Can not get connection length from a non-existing connection.
at com.google.common.base.Preconditions.checkArgument(Preconditions.java:135)
at com.github.rinde.rinsim.geom.AbstractGraph.connectionLength(AbstractGraph.java:48)
at com.github.rinde.rinsim.core.model.road.GraphRoadModelSnapshot.getDistanceOfPath(GraphRoadModelSnapshot.java:83)
at com.github.rinde.rinsim.core.model.road.DynamicGraphRoadModelImpl.getDistanceOfPath(DynamicGraphRoadModelImpl.java:226)
at project.agents.AgvAgent.getTimeToReachGivenPoint(AgvAgent.java:162)
at project.agents.AgvScheduler.calculateExpectedPickUpTime(AgvScheduler.java:116)
at project.agents.AgvScheduler.getReservationProposal(AgvScheduler.java:43)
at project.agents.AgvAgent.getReservationProposal(AgvAgent.java:147)
at project.smartMessage.ExplorationAntComputationalBehaviour.compute(ExplorationAntComputationalBehaviour.java:41)
at project.smartMessage.ExplorationAntComputationalBehaviour.run(ExplorationAntComputationalBehaviour.java:75)
at project.smartMessage.AntAgent.run(AntAgent.java:64)
at project.agents.AgvAgent.tickImpl(AgvAgent.java:205)
at com.github.rinde.rinsim.core.model.pdp.Vehicle.tick(Vehicle.java:55)
at com.github.rinde.rinsim.core.model.time.TimeModel.tickImpl(TimeModel.java:139)
at com.github.rinde.rinsim.core.model.time.SimulatedTimeModel.doStart(SimulatedTimeModel.java:32)
at com.github.rinde.rinsim.core.model.time.TimeModel.start(TimeModel.java:94)
at com.github.rinde.rinsim.ui.SimulationViewer$5.run(SimulationViewer.java:401)
根据我的理解,似乎getShortestPath()方法返回的路径上的点之间没有连接?
答案 0 :(得分:0)
getShortestPathTo(RoadUser, Point)
方法要求路径中的所有点都是图中的节点。 RoadUser
返回的路径可能包含一个位置,如果GraphRoadModel.getConnection(RoadUser)
不在节点上,则该位置不是图中的节点。目前没有内置的方法来检测它并解决它。
您可以使用RoadUser
方法检测到这种情况,如果Connection.to()
位于连接上,那么您可以使用getShortestPathTo(RoadUser, Point)
作为Optional<? extends Connection<?>> conn = ((GraphRoadModel)getRoadModel()).getConnection(this);
Point from;
double dist = 0;
if( conn.isPresent() ){
dist += Point.distance(getRoadModel().getPosition(this),conn.to());
from = conn.to();
} else {
from = getRoadModel().getPosition(this);
}
List<Point> path = getRoadModel().getShortestPathTo(from, point);
Measure<Double,Length> distance = getRoadModel().getDistanceOfPath(path);
// total distance is the sum of distance and dist
的起点呼叫。例如:
var obj = jQuery.parseJSON(data);
$(".success_container").html(obj);
console.log(obj);
var popup = '<div class="modal fade" id="notes-modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;"><div class="modal-dialog"><div class="notes-modal-container"><button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button><h1></h1><h3>Recipe Flavours</h3><br>' + obj + '</div></div></div>';
$('#test1').html(popup);
alert(popup)