views:

54

answers:

1

Hello,

Currently I am working on a Netlogo program where I need to use nodes and links for vehicle routing problem. (links are called streets in the program)

Here I have some practical problems of how to input variable linkspeed in a table with another node. Constants like 200 etc are fine. Online I found some examples where variables are used, but I do not know why I keep getting the following error: Expected a constant. (or why netlogo expects a constant)

Here is the relevant piece of code:

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

I hope somebody knows what is going on...

Kind regards,

Chantal

+1  A: 

The problem is most likely not putting a variable in a table, but putting a variable in a list (which you're then putting in a table).

Change the line below:

     table:put netw (who) [ i 2 ]

to:

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

This - (list i 2) - allows you to generate a list with variables in it, you can't do it the other way - [i 2].

Hope this helps.

hds