2010-06-08 52 views
0

目前我正在使用Netlogo程序,我需要使用節點和鏈接來解決車輛路徑問題。 (鏈接被稱爲程序中的街道)將變量放在表中時出錯,只允許常量?

這裏我有一些如何在另一個節點中輸入變量linkspeed的實際問題。像200等常數是好的。網上我發現了一些例子,其中使用變量,但我不知道爲什麼我不斷收到以下錯誤:

Expected a constant.

(或原因的NetLogo需要一個常數)

下面是相關的代碼:

extensions [table] 
streets-own [linkspeed linktoll] 
nodes-own [netw] 

;; In another piece of code linkspeed is assigned successfully to the links 

to cheapcalc 

    ;; start conditions set costs very high 300000 

    ;; state 3 unsearched state 2 searching state 1 searched (for later purposes) 

    ask nodes [ 

    set i 0 set j count nodes set netw table:make 


    while [i < j][ 


    table:put netw (i) [3000000 3] set i (i + 1)]] 


    set i 0 let k 0 

    ask node 35  ;; here i use node 35 as an example. 

        ;; node 35 is connected to node 34, 36, 20 and 50 

    [table:put netw (35) [0 1] ;; node need to search costs to travel to itself 

            ;; putting constants is ok. 

    while [i < j] 

     [ask my-links 

      [ask both-ends 

       [if (who != 35) [set color blue  

;;    set temp ([linkspeed] of street 35 who) ;; here my real goal is to put this in stat of i. but i is easier than linkspeed. 

       table:put netw (who) [ i 2 ] 

       ]    

      ] ] 


     set i (i + 1)] ] ;; next node for later, no it is just repetition of the same. 


end 

我希望有人知道是怎麼回事......

回答

1

的問題是最有可能不把表中的一個變量,而把一個變量列表(然後你把它放在桌子上)。

更改線以下:

 table:put netw (who) [ i 2 ] 

到:

 table:put netw (who) (list i 2) 

這 - (名單I 2) - 允許您生成與它的變量列表,你不能這樣做另一種方式 - [我2]。

希望這會有所幫助。

相關問題