⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 shortcut.java

📁 JAVA+MO(for JAVA)开发的基于遗传算法的最短路径源代码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
    {
        int num = pointID.length; //num为网络图中点的个数
        this.pNum = num;
        this.originPointID = new int[num];
        this.originPointID = pointID;

        //   curbestroad=new HashArray(pNum);
        tabooTable = new boolean[pNum];
        pointCoord=new com.esri.mo2.cs.geom.Point[pNum];
        outerTabooTable = new boolean[pNum];
        initOuterTabooTable();
        //POP_SIZE=100;
        sortIndex=new int[POP_SIZE];
        population = new individual[POP_SIZE];
    }

    /**
     *  设置点与线的邻接关系
     * @param adjacencyTable  点线的邻接表
     */
    public void setAdjacencyTable(boolean[][] adjacencyTable)
    {
        this.adjacencyTable = new boolean[pNum][lNum];
        this.adjacencyTable = adjacencyTable;
    }

    /**
     * 设置点集的坐标
     * @param pCoord  点集的坐标
     */
    public void setPointCoord(com.esri.mo2.cs.geom.Point pCoord[])
    {
        int n=pCoord.length;
        pointCoord=new com.esri.mo2.cs.geom.Point[n];
        pointCoord=pCoord;
    }

    /**
     *  根据点和相邻线集,得到某点的相邻的点,并做相应的等级分类
     * @param pointindex  初始的一个点的在点集中的索引号
     * @param line  线的集合
     * @return  某一个点相邻接的的NODE节点在初始点集中的的索引号,用数组列表保存
     */
    private AdjArray getAdjNode(int pointindex,LineBean line[])
    {
        AdjArray pointArray = new AdjArray();
        int n = line.length;
        if(n>0)
        {
                double x1 = pointCoord[pointindex].x;
                double y1 = pointCoord[pointindex].y;
                int firstNum = 0;
                int secondNum = 0;
                int thirdNum = 0;

                judgeDirection(pointCoord[pointindex], pointCoord[endPointIndex]);
                if (directionTag == 1) { //第一象限为主集
                    int startPointInd, endPointInd;
                    for (int i = 0; i < n; i++) {
                        startPointInd = line[i].startIndex;
                        endPointInd = line[i].endIndex;
                        if(startPointInd==this.endPointIndex ||endPointInd==this.endPointIndex)
                        {
                            pointArray.hasEndPoint=true;
                            pointArray.AllNum=1;
                            return pointArray;
                        }
                        if (tabooTable[startPointInd]) {
                            double x2=pointCoord[startPointInd].x;
                            double y2=pointCoord[startPointInd].y;
                            if (x1<=x2 && y1>=y2) //第一象限集合
                            {
                                pointArray.FirstCollection[firstNum] = startPointInd;
                                firstNum++;
                            }
                            else if((x1<x2 && y1<y2) || (x1>x2 && y1>y2)) //第二、四象限集合
                            {
                                pointArray.SecondCollection[secondNum] = startPointInd;
                                secondNum++;
                            }
                            else //第三象限集合
                            {
                                pointArray.ThirdCollection[thirdNum] = startPointInd;
                                thirdNum++;
                            }
                        }
                        if (tabooTable[endPointInd]) {
                            double x2=pointCoord[endPointInd].x;
                            double y2=pointCoord[endPointInd].y;
                            if (x1<=x2 && y1>=y2) //第一象限集合
                            {
                                pointArray.FirstCollection[firstNum] = endPointInd;
                                firstNum++;
                            }
                            else if((x1<x2 && y1<y2) || (x1>x2 && y1>y2)) //第二、四象限集合
                            {
                                pointArray.SecondCollection[secondNum] = endPointInd;
                                if(endPointInd==this.endPointIndex)
                                secondNum++;
                            }
                            else //第三象限集合
                            {
                                pointArray.ThirdCollection[thirdNum] = endPointInd;
                                if(endPointInd==this.endPointIndex)
                                thirdNum++;
                            }
                        }
                    }
                    pointArray.AllNum = firstNum+secondNum+thirdNum;
                }
                else if (directionTag == 2) { //第二象限为主集
                    int startPointInd, endPointInd;
                    for (int i = 0; i < n; i++) {
                        startPointInd = line[i].startIndex;
                        endPointInd = line[i].endIndex;
                        if(startPointInd==this.endPointIndex ||endPointInd==this.endPointIndex)
                        {
                            pointArray.hasEndPoint=true;
                            pointArray.AllNum=1;
                            return pointArray;
                        }
                        if (tabooTable[startPointInd]) {
                            double x2 = pointCoord[startPointInd].x;
                            double y2 = pointCoord[startPointInd].y;
                            if (x1 <= x2 && y1 <= y2) { //第二象限集合
                                pointArray.FirstCollection[firstNum] = startPointInd;
                                firstNum++;
                            } else if ((x1 < x2 && y1 > y2) || (x1 > x2 && y1 > y2)) { //第一、三象限集合
                                pointArray.SecondCollection[secondNum] = startPointInd;
                                secondNum++;
                            } else { //第四象限集合
                                pointArray.ThirdCollection[thirdNum] = startPointInd;
                                thirdNum++;
                            }
                        }
                        if (tabooTable[endPointInd]) {
                            double x2 = pointCoord[endPointInd].x;
                            double y2 = pointCoord[endPointInd].y;
                            if (x1 <= x2 && y1 <= y2) { //第二象限集合
                                pointArray.FirstCollection[firstNum] = endPointInd;
                                firstNum++;
                            } else if ((x1 < x2 && y1 > y2) || (x1 > x2 && y1 > y2)) { //第一、三象限集合
                                pointArray.SecondCollection[secondNum] = endPointInd;
                                secondNum++;
                            } else { //第四象限集合
                                pointArray.ThirdCollection[thirdNum] = endPointInd;
                                thirdNum++;
                            }
                        }
                    }
                }
                else if (directionTag == 3) { //第三象限为主集
                    int startPointInd, endPointInd;
                    for (int i = 0; i < n; i++) {
                        startPointInd = line[i].startIndex;
                        endPointInd = line[i].endIndex;
                        if(startPointInd==this.endPointIndex ||endPointInd==this.endPointIndex)
                        {
                            pointArray.hasEndPoint=true;
                            pointArray.AllNum=1;
                            return pointArray;
                        }
                        if (tabooTable[startPointInd]) {

                            double x2 = pointCoord[startPointInd].x;
                            double y2 = pointCoord[startPointInd].y;
                            if (x1 >= x2 && y1 <= y2)
                            { //第三象限集合
                                pointArray.FirstCollection[firstNum] = startPointInd;
                                firstNum++;
                            }
                            else if ((x1 < x2 && y1 < y2) || (x1 > x2 && y1 > y2))
                            { //第二、四象限集合
                                pointArray.SecondCollection[secondNum] = startPointInd;
                                secondNum++;
                            }
                            else
                            { //第一象限集合
                                pointArray.ThirdCollection[thirdNum] = startPointInd;
                                thirdNum++;
                            }
                        }
                        if (tabooTable[endPointInd])
                        {
                            double x2 = pointCoord[endPointInd].x;
                            double y2 = pointCoord[endPointInd].y;
                            if (x1 >= x2 && y1 <= y2)
                            { //第三象限集合
                                pointArray.FirstCollection[firstNum] = endPointInd;
                                firstNum++;
                            } else if ((x1 < x2 && y1 < y2) || (x1 > x2 && y1 > y2)) { //第二、四象限集合
                                pointArray.SecondCollection[secondNum] = endPointInd;
                                secondNum++;
                            } else { //第一象限集合
                                pointArray.ThirdCollection[thirdNum] = endPointInd;
                                thirdNum++;
                            }
                        }
                    }
                }
                else if (directionTag == 4) { //第四象限为主集
                    int startPointInd, endPointInd;
                    for (int i = 0; i < n; i++)
                    {
                        startPointInd = line[i].startIndex;
                        endPointInd = line[i].endIndex;
                        if(startPointInd==this.endPointIndex ||endPointInd==this.endPointIndex)
                        {
                            pointArray.hasEndPoint=true;
                            pointArray.AllNum=1;
                            return pointArray;
                        }
                        if (tabooTable[startPointInd])
                        {
                            double x2 = pointCoord[startPointInd].x;
                            double y2 = pointCoord[startPointInd].y;
                            if (x1 >= x2 && y1 >= y2)
                            { //第四象限集合
                                pointArray.FirstCollection[firstNum] = startPointInd;
                                firstNum++;
                            }
                            else if ((x1 < x2 && y1 > y2) || (x1 > x2 && y1 < y2))
                            { //第一、三象限集合
                                pointArray.SecondCollection[secondNum] = startPointInd;
                                secondNum++;
                            }
                            else
                            { //第二象限集合
                                pointArray.ThirdCollection[thirdNum] = startPointInd;
                                thirdNum++;
                            }
                        }
                        if (tabooTable[endPointInd])
                        {
                            double x2 = pointCoord[endPointInd].x;
                            double y2 = pointCoord[endPointInd].y;
                            if (x1 >= x2 && y1 >= y2)
                            { //第四象限集合
                                pointArray.FirstCollection[firstNum] = endPointInd;
                                firstNum++;
                            }
                            else if ((x1 < x2 && y1 > y2) || (x1 > x2 && y1 < y2))
                            { //第一、三象限集合
                                pointArray.SecondCollection[secondNum] = endPointInd;
                                secondNum++;
                            }
                            else
                            { //第二象限集合
                                pointArray.ThirdCollection[thirdNum] = endPointInd;
                                thirdNum++;
                            }
                        }
                    }
                }
                pointArray.FirstNum=firstNum;
                pointArray.SecondNum=secondNum;
                pointArray.ThirdNum=thirdNum;
                pointArray.AllNum=firstNum+secondNum+thirdNum;
        }
        else  //n<=0   没有相邻点
        {
            pointArray.AllNum = 0;
        }
        return pointArray;
    }
    /**
     *  二次遗传操作中,根据点和相邻线集,得到某点的所有相邻的点,不划分等级分类,所有的相邻点集只保存在AdjArray的FirstCollection中
     * @param pointindex  初始的一个点的在点集中的索引号
     * @param line  线的集合
     * @return  某一个点相邻接的的NODE节点在初始点集中的的索引号,用数组列表保存
     */
    private AdjArray getAdjNodeInGaTwo(int pointindex,LineBean line[])
    {
        tabooTable[pointindex]=false;
        AdjArray pointArray = new AdjArray();
        int n = line.length;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -