'#include "test.idx" '#console #prompt 'ナウシカネットワークシュミレータ '作成 平成16年10月23日 ひでき 'beta 平成16年10月28日 ひでき 指定数生成機能追加 'beta 平成16年10月30日 ひでき 2点間リンク距離 '初期設定 dim nord[20,20] as integer ' ノードのリンク配列 最大ノード 1〜20。[n,m]の値1=リンク、0=なし、n→m dim nord_n as integer ' 存在するノードの数 dim link_n as integer ' 存在するリンクの数の合計 dim link_colum_n[20],link_law_n[20] as integer ' ノードの持つリンクの数を示す。 dim i,j,k as integer ' 制御用変数 dim sel_proc as string '処理の選択 dim n_of_link,temp_rand as single 'ノードにいくつリンクを発生させるか? dim link_to as integer '乱数によりリンク先の候補を決める。 dim repeat_n as integer ' R-オプション時の反復回数 dim debug_f as integer 'デバッグ情報を表示するかいなか? debug_f=0 ' 1= 印刷する 0=印刷しない dim nord_size as integer nord_size=20 'ノード配列の大きさを変えた場合変更すること '初期設定 可視化部分 dim x,y,z as single dim n,dummy as integer dim nord_p[20,2] as integer dim pi,pi_n as single pi=3.1415926535897932 ' 初期設定 2ノード間の最小リンク マトリックス生成 dim nord_link_d[20,20] dim flag_s, old_flag_s,path_mini,temp_path as integer dim sel_cont as string ' 初期設定 ファイル読み込み dim nord_label[20] as string dim x_label as string dim file_label as string 'メイン Randomize initialize_nord() sum_link() do cls 1 locate 0,0 print "ノードの合計 = ";nord_n;", リンクの合計 = ";link_n print "(読込=F、初期化=S、次ノード生成=Enter、指定数ノード生成=R、リンク表=P、可視化=V、最短パス=L" print "終了=E)" input "選択してください。";sel_proc select case sel_proc case "E" exit do case "P" sum_link() nord_print() case "S" initialize_nord() sum_link() nord_print() case "V" visual(nord_n) case "R" input "いくつノードを生成しますか?";repeat_n for k=1 to repeat_n add_nord() sum_link() visual(nord_n+repeat_n-k) next ' nord_print() case "L" nord_path() input dummy ' 待ち case "F" file_load() case else add_nord() sum_link() ' nord_print() visual(nord_n) end select loop until (sel_proc="E") ' サブルーチン ノード配列の初期化 sub initialize_nord() print "初期設定..." for i=1 to nord_size step 1 for j=1 to nord_size step 1 nord[i,j]=0 next link_law_n[i]=0 link_colum_n[i]=0 next nord_n=1 nord[1,1]=1 link_n=1 link_law_n[1]=1 link_colum_n[1]=1 input "1ノードあたりのリンクの数" , n_of_link end sub 'ノードを付け加える sub add_nord() nord_n=nord_n+1 nord[nord_n,nord_n]=1 link_n=link_n+1 link_law_n[nord_n]=link_law_n[1]+1 link_colum_n[nord_n]=link_colum_n[nord_n]+1 add_link() end sub 'リンクを発生させる sub add_link() ' 新しく加わったnord[nord_n,?]にリンクを指定数(n_of_lin)加える i=n_of_link 'while i >0 for i=1 to n_of_link do j=1 do temp_rand=rand()/32767 loop until (0j then if nord[i,j]=1 then line (nord_p[i,1],nord_p[i,2])-(nord_p[j,1],nord_p[j,2]) end if end if next next locate 0,0 input dummy ' 待ち end sub ' 全マトリックスのノード間距離を求める。 sub nord_path() for i=1 to nord_n for j=1 to nord_n nord_link_d[i,j]=nord[i,j] next next nord_l_print() do 'input "E/other";sel_cont 'if sel_cont="E" then ' exit do 'end if flag_s=0 old_flag_s=0 for i=1+1 to nord_n for j=1 to i-1 if nord_link_d[i,j]=0 then flag_s=flag_s+1 path_mini=9999 for k=1 to nord_n if nord_link_d[i,k]>0 and nord_link_d[j,k]>0 then temp_path=nord_link_d[i,k]+nord_link_d[j,k] if path_mini>temp_path then path_mini=temp_path end if end if if nord_link_d[k,i]>0 and nord_link_d[k,j]>0 then temp_path=nord_link_d[k,i]+nord_link_d[k,j] if path_mini>temp_path then path_mini=temp_path end if end if if nord_link_d[i,k]>0 and nord_link_d[k,j]>0 then temp_path=nord_link_d[i,k]+nord_link_d[k,j] if path_mini>temp_path then path_mini=temp_path end if end if if nord_link_d[k,i]>0 and nord_link_d[j,k]>0 then temp_path=nord_link_d[k,i]+nord_link_d[j,k] if path_mini>temp_path then path_mini=temp_path end if end if next if path_mini<9999 then nord_link_d[i,j]=path_mini end if nord_l_print() end if next next if flag_s=0 or flag_s=old_flag_s then exit do else old_flag_s=flag_s end if loop end sub 'nord_link_dを印刷 sub nord_l_print() locate 0,4 print print "ノード配列の印刷" for i=1 to nord_n for j=1 to nord_n print nord_link_d[i,j];" "; next print next end sub ' ファイルの読み込み csvファイル sub file_load() nord_n=19 input "ファイル名は?";file_label file_label="C:\Documents and Settings\秀樹\My Documents\"+file_label Open file_label for input as #1 do for i=1 to nord_n for j=1 to nord_n input #1, x print x;","; nord[i,j]=x next print "" next input dummy ' 待ち input #1, dummy Loop Until Eof(1) close #1 'ラベルを読み込む場合 'Open "C:\Documents and Settings\秀樹\My Documents\natutica041127-label.csv" for input as #1 'do ' for i=1 to nord_n ' input #1, x_label ' print x_label;","; ' nord_label[i]=x_label ' next 'input dummy ' 待ち 'input #1, dummy 'Loop Until Eof(1) 'close #1 end sub