<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    johnsdilon

    SINK

     

      1 /**
      2  * @file FindSINK.java
      3  * 
    @author zhanqingfeng
      4  * @date 2007-09-02
      5  * @description 尋找SINK
      6  *     SINK:
      7  *         由一些頂點和有向邊組成的一個圖,如果兩個頂點x,y之間有一條路連通,則稱x到y是連通的。
      8  *         對于所有頂點集合的一個子集,如果任意兩點之間是連通的,則稱為一個“強連通子集”。
      9  *         一個強連通子集,如果沒有任何指向其他頂點的邊(各個頂點有且只有一個輸出方向),則稱為一個“SINK”。
     10  
    */

     
    11 
     
    12 package src;
     
    13 
     
    14 import java.util.ArrayList;
     
    15 import java.util.LinkedList;
     
    16 
     
    17 public class FindSINK {
     
    18     
     
    19     /** 數據 */
     
    20     private final int[][] nodeArr = {
     
    21             12 }
     
    22             26 }
     
    23             61 }
     
    24             35 },
     
    25             54 }
     
    26             41 }
     
    27             78 },
     
    28             87 },
     
    29             86 }
     
    30     }
    ;
     
    31     
     
    32     /** 所有出現的點集 */
     
    33     private ArrayList allNodeS = new ArrayList();
     
    34     
     
    35     /** 待匹配的線集
     36      * waitLineS.* 為 LinkedList
     37      
    */

     
    38     private ArrayList waitLineS = new ArrayList();
     
    39     
     
    40     /** 匹配成功的環集
     41      * okLapS.* 為 ArrayList
     42      
    */

     
    43     private ArrayList okLapS = new ArrayList();
     
    44     
     
    45     /** 壞點集(不可能形成SINK的點集) */
     
    46     private ArrayList badNodeS = new ArrayList();
     
    47     
     
    48     /** 讀取邊數據 */
     
    49     private void readLine(int lineHead, int lineTail){
     
    50         
     
    51         // 獲取首點
     52         Integer headInteger = new Integer(lineHead);
     
    53         // 獲取尾點
     54         Integer tailInteger = new Integer(lineTail);
     
    55 
     
    56         // 若首點是第一次出現
     57         if (false == allNodeS.contains(headInteger)){
     
    58             // 添加首點至點集中
     59             allNodeS.add(headInteger);
     
    60         }

     
    61         // 若尾點是第一次出現
     62         if (false == allNodeS.contains(tailInteger)){
     
    63             // 添加尾點至點集中
     64             allNodeS.add(tailInteger);
     
    65         }
            
     
    66         // 若首點、尾點均為第一次出現
     67         if ( (false == allNodeS.contains(headInteger))
     
    68                 && (false == allNodeS.contains(tailInteger)) ){
     
    69             // 構造一個新的線
     70             LinkedList waitLineNew = new LinkedList();
     
    71             waitLineNew.add(headInteger);
     
    72             waitLineNew.add(tailInteger);
     
    73             // 添加該新線至線集中
     74             this.waitLineS.add(waitLineNew);        
     
    75             return;            
     
    76         }
                    
     
    77         // 若壞點集包含首點,或者尾點
     78         if ( (badNodeS.contains(headInteger)) 
     
    79                 || (badNodeS.contains(tailInteger)) ){
     
    80             return;
     
    81             
     
    82             // 若壞點集不包含首點,及尾點
     83         }

     
    84         else{
     
    85             // 遍歷環集中的環
     86             // 若環集中的環同時存在首點及尾點,或者存在首點,作相應處理
     87             for (int i=0; i<okLapS.size(); i++){
     
    88                 ArrayList okLap = (ArrayList)okLapS.get(i);
     
    89                  // 若環中已經存在首點,及尾點
     90                  if ( (okLap.contains(headInteger)) && (okLap.contains(tailInteger)) ){
     
    91                      // 若環中已經存在該邊
     92                      if (okLap.indexOf(headInteger) == okLap.indexOf(tailInteger)-1){
     
    93                          return;
     
    94                          
     
    95                          // 若環中不存在該邊
     96                      }

     
    97                      else{
     
    98                          // 置環中的點為壞點
     99                          badNodeS.addAll(okLap);
    100                          // 從環中刪除該環
    101                          okLapS.remove(i);
    102                          return;
    103                      }

    104                      
    105                      // 若環中不同時包含首點,及尾點
    106                  }

    107                  else{
    108                      // 若環中存在首點
    109                      if (true == okLap.contains(headInteger)){
    110                          // 置環中的點為壞點
    111                          badNodeS.addAll(okLap);
    112                          // 從環集中刪除該環
    113                          okLapS.remove(i);
    114                          return;
    115                          
    116                          // 若環中不存在首點
    117                      }

    118                      else{
    119                          continue;
    120                      }

    121                  }

    122             }

    123             // 遍歷線集中的線
    124             // 若線集中的線同時存在首點及尾點,或者存在二者之一,作相應處理
    125             for (int i=0; i<waitLineS.size(); i++){
    126                 LinkedList waitLine = (LinkedList)waitLineS.get(i);
    127                 // 若線中已經存在這兩點
    128                 if ( (waitLine.contains(headInteger)) && (waitLine.contains(tailInteger)) ){
    129                     // 若在線中,tailInteger 是 headInteger 的后續
    130                     if (waitLine.indexOf(headInteger)<waitLine.indexOf(tailInteger)){
    131                         // 若線中已經存在該邊
    132                         if (waitLine.indexOf(headInteger) == waitLine.indexOf(tailInteger)-1){
    133                             return;
    134                             
    135                             // 若線中不存在該邊
    136                         }

    137                         else{
    138                             // 置線中 tailInteger 及其前續點為壞點,同時從線中刪除這些點
    139                             badNodeS.addAll(waitLine.subList(0, waitLine.indexOf(tailInteger)+1));
    140                             waitLine.removeAll(waitLine.subList(0, waitLine.indexOf(tailInteger)+1));
    141                             return;
    142                         }

    143                         
    144                         // 若在線中, tailInteger 不是 headInteger 的后續
    145                     }

    146                     else{
    147                         // 若線的末結點是 headInteger
    148                         if (headInteger.equals(waitLine.getLast())){
    149                             // 置線中 tailInteger 的前續點為壞點
    150                             badNodeS.addAll(waitLine.subList(0, waitLine.indexOf(tailInteger)));
    151                             // 取出線中尾點(包含)至首點(包含)的線上的點,構成一個成功匹配的環
    152                             ArrayList okLapNew = new ArrayList();
    153                             okLapNew.addAll(waitLine.subList
    154                                                     (waitLine.indexOf(tailInteger), 
    155                                                             waitLine.size()));
    156                             // 添加該環至環集中
    157                             okLapS.add(okLapNew);
    158                             // 從線集中刪除該線
    159                             waitLineS.remove(i);
    160                             return;
    161                             
    162                             // 若線的末結點不是 headInteger
    163                         }

    164                         else{
    165                             // 置線中 headInteger 及其前續點為壞點,同時從該線中刪除這些點
    166                             badNodeS.addAll(waitLine.subList(0, waitLine.indexOf(headInteger)+1));
    167                             waitLine.removeAll(waitLine.subList(0, waitLine.indexOf(headInteger)+1));
    168                             return;
    169                         }

    170                     }

    171                     
    172                     // 若線中不同時包含首點,及尾點
    173                 }

    174                 else{
    175                     // 若線中存在首點
    176                     if (waitLine.contains(headInteger)){
    177                         // 若首點等于該線的末結點
    178                         if (headInteger.equals(waitLine.getLast())){
    179                             waitLine.addLast(tailInteger);
    180                             return;
    181                             
    182                             // 若首點不等于該線的末結點
    183                         }

    184                         else{
    185                             // 置線中 headInteger 及其前續點為壞點,同時從該線中刪除這些點
    186                             badNodeS.add(waitLine.subList(0, waitLine.indexOf(headInteger)+1));
    187                             waitLine.removeAll(waitLine.subList(0, waitLine.indexOf(headInteger)+1));
    188                             return;                            
    189                         }

    190                         
    191                         // 若線中存在尾點
    192                     }

    193                     else if (waitLine.contains(tailInteger)){
    194                         // 若尾點等于該線的首結點
    195                         if (tailInteger.equals(waitLine.getFirst())){
    196                             waitLine.addFirst(headInteger);
    197                             return;
    198                             
    199                             // 若尾點不等于該線的首結點
    200                         }

    201                         else{
    202                             // 取出線中尾點及其后續的點,構成一個待匹配的線
    203                             LinkedList waitLineNew = new LinkedList();
    204                             waitLineNew.addAll(waitLine.subList
    205                                                             (waitLine.indexOf(tailInteger),
    206                                                                     waitLine.size()));
    207                             // 將首點插入該新線的開始
    208                             waitLineNew.addFirst(headInteger);
    209                             // 將該新線添加至線集中
    210                             waitLineS.add(waitLineNew);
    211                             return;
    212                         }

    213                         
    214                         // 若線中不存在首點,及尾點
    215                     }

    216                     else{
    217                         continue;
    218                     }

    219                 }

    220             }

    221             // 若線集、壞點集、環集均不包含首點及尾點,或者二者之一
    222             // 構造一個新的線
    223             LinkedList waitLineNew = new LinkedList();
    224             waitLineNew.add(headInteger);
    225             waitLineNew.add(tailInteger);
    226             // 添加該新線至線集中
    227             this.waitLineS.add(waitLineNew);        
    228             return;
    229         }

    230     }

    231 
    232     /** 讀取所有的邊數據 */
    233     private void readAllLine(int[][] arr){
    234         for (int i=0; i<arr.length; i++){
    235             this.readLine(arr[i][0], arr[i][1]);
    236         }

    237     }

    238     
    239     /** 輸出所有的邊數據 */
    240     private void showLine(int[][] arr){
    241         System.out.println("All the lines input:");
    242         for (int i=0; i<arr.length; i++){
    243             System.out.println(arr[i][0+ " , " + arr[i][1]);
    244         }

    245     }

    246     
    247     /** 輸出所有的SINK  */
    248     private void showLap(){
    249         System.out.println();
    250         System.out.println("All the SINK:");
    251         for (int i=0; i<okLapS.size(); i++){
    252             ArrayList okLapOut = (ArrayList)okLapS.get(i);
    253             for (int j=0; j<okLapOut.size(); j++){
    254                 System.out.print(okLapOut.get(j).toString());
    255                 if (okLapOut.size()-1 > j){
    256                     System.out.print(" , ");
    257                 }

    258             }

    259             System.out.println();
    260         }

    261     }

    262     
    263     /**
    264      * 構造函數
    265      * 讀取并輸出所有邊數據,并輸出所有的SINK
    266      
    */

    267     public FindSINK(){
    268         this.readAllLine(nodeArr);
    269         this.showLine(nodeArr);
    270         this.showLap();
    271     }

    272     
    273     /*
    274      * 主函數
    275      
    */

    276     public static void main(String[] args){
    277         FindSINK obj = new FindSINK();
    278     }

    279     
    280 }

    281 
    282 

    posted on 2007-12-22 22:20 johnsdilon 閱讀(136) 評論(0)  編輯  收藏 所屬分類: java


    只有注冊用戶登錄后才能發表評論。


    網站導航:
     

    導航

    留言簿

    文章分類

    最新評論

    主站蜘蛛池模板: 色噜噜狠狠色综合免费视频| 亚洲欧洲久久精品| 亚洲精品无码久久千人斩| 亚洲精品无码久久久久去q| 久久久久亚洲AV无码观看| 2019亚洲午夜无码天堂| 老司机午夜精品视频在线观看免费 | 女性自慰aⅴ片高清免费| 哒哒哒免费视频观看在线www | 亚洲精品久久久www| 亚洲AV无码一区东京热| 亚洲国产视频一区| 国产精品亚洲小说专区| 日批视频网址免费观看| 在线观看H网址免费入口| 国产精品免费视频网站| 亚洲精品亚洲人成在线观看| 亚洲福利电影在线观看| 国产精品亚洲一区二区三区| 免费久久人人爽人人爽av | 先锋影音资源片午夜在线观看视频免费播放| 2022年亚洲午夜一区二区福利 | 又粗又硬免费毛片| 亚洲AV日韩AV永久无码免下载| 精品亚洲成在人线AV无码| 中美日韩在线网免费毛片视频| 中文字幕免费视频| 青青青国产色视频在线观看国产亚洲欧洲国产综合 | 永久免费AV无码网站在线观看| 亚洲精品国产品国语在线| 激情综合亚洲色婷婷五月APP| a级毛片免费观看在线| 国产又大又粗又长免费视频| 亚洲人成人无码网www国产| 亚洲欧洲国产精品久久| 岛国岛国免费V片在线观看| 毛片a级毛片免费观看免下载| 亚洲精品乱码久久久久久自慰| 亚洲人成人网站18禁| 久久爰www免费人成| 又粗又黄又猛又爽大片免费 |