0

I read other questions similar to mine, but I still cannot figure out what to do regarding my model. Let me explain. I have two breeds.

breed [distributers distributer]
breed [suppliers supplier]
distributers-own [dproductASales]
suppliers-own [sproductASales]

I need to assign the distributer's variable to the supplier, but it has an error.

to sales-decision
set sproductASales dproductASales

How can I do that? Thanks

Naha
  • 15
  • 4

2 Answers2

1

What do you want the context to be for sales-decision? Since you say set sProductASales you have chosen supplier context. OK, so you will ask a supplier to set this variable to ... what? You cannot say dproductASales because that is neither a global variable nor a supplier attribute. If you want to refer to the dproductASales of a distributor, then you must us of and specify which one of them (even if there is only one). For example:

breed [distributers distributer]
breed [suppliers supplier]
distributers-own [dproductASales]
suppliers-own [sproductASales]

to sales-decision  ;supplier procedure
  set sproductASales [dproductASales] of one-of distributers
end

to test
  ca
  create-distributers 2 [
    set dproductASales one-of [2 4]
  ]
  create-suppliers 10 [
    sales-decision
  ]
end
Alan
  • 9,410
  • 15
  • 20
  • Thanks. Actually, "dproductASales" is the same for all the distributers. Every year they have a value for it to analyze their sales, and they want to inform suppliers about it. Suppliers need to know this number and use it in some computations. It has an initial value of 6 million. Every year, it is updated. Do you mean I should define it global? But it is just for distributers – Naha Jan 29 '17 at 23:55
  • 1
    You want a class variable, but NetLogo does not have that concept. So you must decide how you want to handle that. The most common practice in NetLogo programming would be to use a global variable. If you (understandably) dislike using global variables, we can discuss alternatives. But at the stage you are at I would say yes, use a global variable instead. – Alan Jan 30 '17 at 00:23
0

another option, if you don't want to use globals (which seems to me the way to go if the value doesn't vary by distributor), would be to have a patch-owned variable like "PdAs" and:

ask patches with [count distributors-here > 0] 
   [
    ask one-of distributors-here 
        [set PdAs dproductASales]
   ]   
    ask suppliers 
    [
     set sproductASales PdAs
    ]

Agents have access to patch variables, so your suppliers can query it directly just as if it were a global variable but you have the option of making it spatially explicit if you go this route (say if in the future you want the ability to have different distributor product sales values and to have suppliers access their local value).

Jesse001
  • 924
  • 1
  • 13
  • 37
  • Thanks. Let me first ask a question about your statement "which seems to me the way to go if the value doesn't vary by distributor". I defined dproductASales global, and then in a procedure they are multiplied by a number and get updated. Since they are global, I could have "set sproductASales dproductASales". I assume sproductASales to get updated too, isn't it correct? – Naha Feb 01 '17 at 17:26
  • if you use globals, then yes you can query it directly with any agent and set your agent value to it at any point. It seemed to me that you may not want to use globals, then that's where my answer comes in to play. The benefit of not using a global is that you can vary the value in a spatially explicit way. If you don't need that ability, then it's additional unnecessary complexity. "everything should be as simple as possible, but not simpler"~Einstein – Jesse001 Feb 02 '17 at 18:17
  • More to your question (I may have missed the point), if sproductASales gets updated: it depends on when you do the multiplier. If you apply the multiplier to dproductASales, then set sproductASales dproductASales yes it will be updated to the same value across the board. If you want it to vary with supplier you'll want to apply the multiplier after set. If you wanted to update your question with your current code we can help you get where you're going. – Jesse001 Feb 02 '17 at 18:20