Java 过滤正确路径以实现dijkstra算法

Java 过滤正确路径以实现dijkstra算法,java,path,Java,Path,我有一个目标和一个起点,还有一个矩形的障碍列表。我的出发点是0,现在我已经执行了dijkstra的算法,从起点到终点穿越,避开障碍物。我可以穿过矩形的两侧到达目标,但我不能穿过,基本上形成矩形的所有点都是顶点 我的输入文件是这种格式的 1.75 -0.25 -0.5 2.5 -1 1 0.75 1.31 -0.56 0.25 2.32 0.35 0.75 像这样的。。 XYGOAL xmin0 xmax0 ymin0 ymax0 xmin1 xmax1 ymin1 ymax1 ..

我有一个目标和一个起点,还有一个矩形的障碍列表。我的出发点是0,现在我已经执行了dijkstra的算法,从起点到终点穿越,避开障碍物。我可以穿过矩形的两侧到达目标,但我不能穿过,基本上形成矩形的所有点都是顶点

我的输入文件是这种格式的 1.75 -0.25 -0.5 2.5 -1 1 0.75 1.31 -0.56 0.25 2.32 0.35 0.75

像这样的。。 XYGOAL xmin0 xmax0 ymin0 ymax0 xmin1 xmax1 ymin1 ymax1 ... XmaxnYmaxn酒店

第一行是目标 2号线是边界竞技场 第3行、第4行以及之后。。。是障碍物列表,即矩形

帮助:我已经解析了文件并提取了所有的点、矩形和障碍物 我有一个列表,其中存储了从给定点到每个其他点的所有边,并且 还有一个有所有边列表的边列表

有谁能告诉我如何过滤掉边缘障碍并生成正确的路径来实现dijkstra的

import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Graphics;
import java.awt.Point;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
//import DrawingRects;





import javax.swing.JPanel;


public class GlobalNav {

//private static BufferedReader br;
    public static final ArrayList<Float> storeCoordinateList = new ArrayList<Float>();
    public static final ArrayList<Rectangle2D> rectangleList = new ArrayList<Rectangle2D>();
    public static final ArrayList<Float> storeCoordinates = new ArrayList<Float>();
    public static final ArrayList<Point2D> points = new ArrayList<Point2D>();

    public static void main(String[] args) throws IOException {

//ArrayList<Float> storeCoordinateList = new ArrayList<Float>();  
        FileInputStream fstream = new FileInputStream(args[0]);  
// Get the object of DataInputStream  
        DataInputStream in = new DataInputStream(fstream);  
        BufferedReader br = new BufferedReader(new InputStreamReader(in));  
        String strLine;  
//Read File Line By Line  
        while ((strLine = br.readLine()) != null) {  
            String[] nums = strLine.split(" ");
            for (String n : nums){
                try {
                    Float num = Float.parseFloat(n);
                    storeCoordinateList.add(num);
                }
                catch(NumberFormatException e){

                }
            }    
        }


//Close the input stream 
        System.out.println("Co-ordinate List " + storeCoordinateList);
        in.close();  
        System.out.println("Size of Coo " + storeCoordinateList.size());

        System.out.println("GlobalNav.main()4 " + storeCoordinateList.size());
        int x1 = 2, x2 = 3, y1 = 4, y2 = 5;
//int xmin = 2, xmax = 3, ymin = 4, ymax =5;
        System.out.println("GlobalNav.main()" + storeCoordinateList.size());

        int expansion = 210;
        points.add(new Point2D.Float(0, 0));

        while(y2 < storeCoordinateList.size()){
//System.out.println("GlobalNav.main()" + x1);
            float height = (storeCoordinateList.get(y2)) - (storeCoordinateList.get(y1));
            float width = (storeCoordinateList.get(x2)) - (storeCoordinateList.get(x1));
//Rectangle rect = new Rectangle(Math.round(storeCoordinateList.get(x1)), Math.round(storeCoordinateList.get(y1)), Math.round(height), Math.round(width));
            Rectangle2D.Float rect = new Rectangle2D.Float(storeCoordinateList.get(x1), storeCoordinateList.get(y1), height, width);
            rectangleList.add(rect);


            points.add(new Point2D.Float(storeCoordinateList.get(x1), storeCoordinateList.get(y1)));
            points.add(new Point2D.Float(storeCoordinateList.get(x1), storeCoordinateList.get(y2)));
            points.add(new Point2D.Float(storeCoordinateList.get(x2), storeCoordinateList.get(y1)));
            points.add(new Point2D.Float(storeCoordinateList.get(x2), storeCoordinateList.get(y2)));

            x1 += 4;
            x2 += 4;
            y1 += 4;
            y2 += 4;

        }
        points.add(new Point2D.Float(storeCoordinateList.get(0), storeCoordinateList.get(1)));
        System.out.println("List" + rectangleList.toString());

        System.out.println("List" + points.toString());


        filterIntersectionEdges(points);


    }

    private static void filterIntersectionEdges(ArrayList<Point2D> points2) {
// TODO Auto-generated method stub
        ArrayList<Edge> edge = new ArrayList<Edge>();
//edge.add(Point(0, 0));
        ArrayList<ArrayList<Edge>> listOfEdges = new ArrayList<ArrayList<Edge>>();
        for (int i = 0; i < points2.size(); i++) {
            for (int j = i + 1; j < points2.size(); j++) {
                edge.add(new Edge(points2.get(i),points2.get(j)));

                listOfEdges.add(edge);

//              System.out.println("Edges" + edge.toString());
//              System.out.println("List of Edges" + listOfEdges.toString());
            }

        }



        Edge line1 = new Edge();
        int i = 0;
        for (ArrayList<Edge> newEdge : listOfEdges) {
            line1 = newEdge.get(i);




            for (Iterator iterator = newEdge.iterator(); iterator.hasNext();) {
                Edge line2 = (Edge) iterator.next();
//System.out.println(" lIne 2 " + line2);



            }
            i++;


        } 


    }

}


class Edge{

    private Point2D pointA;
    private Point2D pointB;

    public Edge(Point2D pointA, Point2D pointB){
        this.pointA = pointA;
        this.pointB = pointB;
    }

    public String size() {
// TODO Auto-generated method stub

        return null;
    }

    public Edge() {
// TODO Auto-generated constructor stub
    }

    public Point2D getPoint1(){
        return this.pointA;
    }

    public Point2D getPoint2(){
        return this.pointB;
    }

    @Override
    public String toString(){
        return "Point 1:" + pointA.toString() + " Point 2:" + pointB.toString();
    }

}

你能具体说明一下,你遇到了什么问题吗?我想找到一条避开障碍的正确道路,但我不知道该怎么走。