从两个未连接的节点移动的星搜索笔式绘图仪
我在编程作业上遇到了麻烦,它是一个笔式绘图仪,这里已经有很多关于它的问题。
总结如下:
纸张被理解为放置在一个网格上,x 轴和 y 轴都从 0 到无穷大(理论上)。所有绘图都完全包含在该象限中,并且可以假定适合页面。总是可以假设行不包含在其他行中。笔始终从原点 (0, 0) 开始,但可以在任何地方结束。线由网格上端点的 (x, y) 坐标(整数)指定。笔可以在任意两点之间画一条线,也可以在任意两点之间沿直线移动(不绘制任何东西)。显然,可以在任一方向上绘制一条线。由于我们希望最小化绘制图形的总时间,因此假设笔以恒定速度移动,以便最佳绘图是最小化笔在不绘图时移动的总距离。
所有输入都将位于一个文件中,该文件包含以下形式的一系列行:
x1 y2 和 x2 y2 之间的行
我将其用于我的输入: 0 0 和 2 之间的线路
2 4 1 和 4 之间的
线路 4 4 4 和 4
之间的线路 7 2 6 和 4 之间的线路
4 4 4 和 6 之间的线路 2
6 6 和 4 之间的
线路 4 2 2 和 4 之间的线路 4
和边被存储到数组列表中。我不知道为什么它返回一个 NullPointerException
我几乎完成了,除了下面的 for 循环返回一个异常,我不知道为什么。它的目的是获取图中所有连接边的列表
例外情况是: 线程“main”中的异常 java.lang.NullPointerException 在 Nodes.getConnectedEdges(Nodes.java:55) 这是 for 循环线“for (Edges a :lines”
public ArrayList<Edges> getConnectedEdges(ArrayList<Edges> lines) {
ArrayList<Edges> returnData = new ArrayList<Edges>();
for (Edges a : lines) {
if(a.getFromNode() == this ){ // if this node is the from node of that edge
returnData.add(a);
}
// if this node is the to node of that edge
if(a.getToNode() == this){
returnData.add(a);
}
}
return returnData;
}
流动的问题是如何从原点 (0,0) 到未连接的点 (2,2)?
提前致谢
I'm having trouble with a programming assignment, its a penplotter, there have been quite a few questions about it already here.
Here's a summary:
The paper sheet is understood to be laid out on a grid with both the x-axis and y-axis running from 0 up to infinity (notionally). All drawings are fully contained in this quadrant and can be assumed to fit on the page. Lines can always be assumed not to be contained in other lines. The pen always starts at the origin (0, 0) but can finish anywhere. Lines are specified by the (x, y) coordinates (in integers) of their end points on the grid. The pen can either draw a line between any two points or move (without drawing anything) in a straight line between any two points. As should be obvious, a line can be drawn in either direction. Since we want to minimize the total time to draw a figure, assume the pen moves at constant speed so that an optimal drawing is one that minimizes the total distance moved by the pen whilst not drawing.
All input will be in a file with a sequence of lines of the following form:
Line between x1 y2 and x2 y2
I'm using this for my input:
Line between 0 0 and 2 2
Line between 4 1 and 4 4
Line between 4 4 and 4 7
Line between 2 6 and 4 4
Line between 4 4 and 6 2
Line between 6 6 and 4 4
Line between 2 2 and 4 4
and the edges are being stored into the arraylist. I'm not sure why its returning an NullPointerException
I'm almost done, except the following for loop is returning an exception and I'm not sure why. It aims to get the list of all connected edges in the graph
The exception says:
Exception in thread "main" java.lang.NullPointerException
at Nodes.getConnectedEdges(Nodes.java:55)
which is the for loop line "for (Edges a : lines"
public ArrayList<Edges> getConnectedEdges(ArrayList<Edges> lines) {
ArrayList<Edges> returnData = new ArrayList<Edges>();
for (Edges a : lines) {
if(a.getFromNode() == this ){ // if this node is the from node of that edge
returnData.add(a);
}
// if this node is the to node of that edge
if(a.getToNode() == this){
returnData.add(a);
}
}
return returnData;
}
The on flowing problem would be how to get from say the origin (0,0) to an unconnected point say (2,2)?
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论