fivejunction.java

来自「主要功能:对五条道路的车辆进行控制」· Java 代码 · 共 66 行

JAVA
66
字号
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package fivestarcross;import java.util.ArrayList;/** * * @author Dante */public class FiveJunction {        public float [][] traffic;    public ArrayList<VexNode> traffic_graph=new ArrayList<VexNode>(20);//创建交通图            public FiveJunction(float [][] traffic){        this.traffic =traffic;        newNodeList();    }        public void newNodeList(){        int index;        for(int i=0;i<=4;i++)            for(int j=0;j<=4;j++){                if(i!=j){                    char[] ch={(char) ('A' + i),(char) ('A' + j)};                    String   str   =   new   String(ch);                    VexNode node =new VexNode(i*5+j,str,traffic[i][j]);                    node.firstarc = requestConflict(i,j);                    int si=traffic_graph.size();                    for(index=0;index<si;index++){                        if(traffic_graph.get(index).vextraffic<traffic[i][j])                            break;                    }                                            traffic_graph.add(index,node);                }            }        new ColoringAlgorithm(traffic_graph).DrawColor();    }        public ArrayList<Integer> requestConflict(int A,int B){           ArrayList<Integer> firstarc = new ArrayList<Integer>();//指向第一条边                for(int i=0;i<=4;i++)            for(int j=0;j<=4;j++){                if(A<B){                    if(i>A&&i<=B&&(j>B||j<A)||(i>B||i<A)&&j>=A&&j<B){                        firstarc.add(i*5+j);                    }                }                else{                    if((i>A||i<=B)&&(j>B&&j<A)||(i>B&&i<A)&&(j>=A||j<B)){                    firstarc.add(i*5+j);                    }                }            }        return firstarc;    }}

⌨️ 快捷键说明

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