Iwan Vitryawan
Iwan Vitryawan

Reputation: 31

NetLogo: Using agents-own

I have NetLogo model of retails like this

retails-own [
  volum
  diskon
  ]

I want to assign value of volum and diskon to two different retails and so far I can only assign it with random number like this

ask retails
  [
   set diskon random 5
   set volum random 20
  ]

How to assign a specific value to different retails? And how can I call up the value of volum and diskon from an agent. So far i can't call it, see below. Thank you

to create-shortest-path
    let i 0
    let tempar dijkstra (item 0 retailhouse) (item 1 retailhouse)

    let final_route item 0 tempar
    let total_distance item 1 tempar

    set buat total_distance

    if buat < 20
    [ 
      ask retails
      [ if diskon < 5   
        [set volum volum * (1 + diskon / 100) ] ;;THIS PART, how can I call volum value from a specific agent
      ]
    ]
end

Upvotes: 1

Views: 83

Answers (1)

JenB
JenB

Reputation: 17678

If you have only a small number of these, you can manually assign a value. For example ask turtle 0 [ set diskon 25 ]. If you have many values, then you should consider using the file importing functions (look in the Models Library, code section for an example).

Similarly you can recall the value from a particular agent by having with ... [ diskon ] of turtle 0.

Note that this is relying on who numbers which is generally a very bad thing to do because they are automatically assigned in the order that turtles (agents) are created, so the code will break if you later create more agents earlier in the code. It's okay if you have just a few agents and that will never change, but you may want to add another variable to label the different agents.

Upvotes: 2

Related Questions