im trying to create a model with two agent sets. a retailer and a customer set. customer agents need to access to the price of the closest member of the retailer set and compare its price with their own preference price and make a purchase if the offered price by the retailer is lower than the preferred price. i tried to define the variable price-here for customers so i can transfer the value of price of the closest retailer to the customer and make the comparison.i wonder what syntax i should used to make this transfer? i have created a simple model here so i can get the hang of the process.
breed [ retailers retailer]
breed [ customers customer]
directed-link-breed [info-links info-link]
directed-link-breed [purchase-links purchase-link]
retailers-own [
price
inventory
]
customers-own [
price-here
prefered-price
]
to setup
create-retailers 10 [ setxy random-pxcor random-pycor
set color blue
set price random 10
set inventory 10
]
create-customers 20 [ setxy random-pxcor random-pycor
set color red
set prefered-price random 7 ]
end
to go
foreach sort customers [x -> ask x[
create-info-link-from min-one-of retailers [ distance myself ]
]]
end
This is not tested so may have syntax errors. I think you want to check the price of only the closest retailer and then buy if the price is low enough. You don't need to create a link just to get information, you just need to specify the agent with the information you want and use of. So you can do something like this:
to go
ask customers
[ let closest min-one-of retailers [ distance myself ]
let closest-price [price] of closest
if closest-price <= preferred-price
[ ...
I constructed it as separate lines so you can see what is going on. (1) Identify the closest retailer and assign that turtle to the variable named 'closest'. (2) Get the price from that retailer. (3) Do the comparison and then take action.
You can do it in one line. That would look like:
to go
ask customers
[ if closest-price <= [price] of min-one-of retailers [ distance myself ]
[ ...
Related
I am trying to model an community that engages in shifting cultivation. For that I want each household to change the patch every year. Each household can have a different crop area, depending on time and number of people working. I want them to be able to choose a patch that has the amount of forest patch need to open their crop. For example, one household has a crop area of 3, so the new location needs to be a forest patch with two other forest patch neighbors. Any idea how can I specify that?
Thanks
Here is a possible solution:
patches-own [ patch-type ]
breed [ households household ]
to setup
clear-all
ask patches [ set patch-type one-of ["forest" "rock" "sand"] ]
let forest-neighbors-needed 2
create-households 100 [
let candidate-locations patches with [
not any? households-here and
patch-type = "forest" and
count neighbors with [ patch-type = "forest" ] >= forest-neighbors-needed
]
ifelse any? candidate-locations [
move-to one-of candidate-locations
] [
error "No suitable location found!"
]
]
end
This method is not the most efficient, because it rebuilds the set of possible location for each household it creates, but if your model is not two big, it shouldn't make much of a difference.
Note that you don't give us a lot of detail about how your model is organized, so I had to make a few assumptions. Next time, please tell us bit more: what breeds to you have, what are their variables, etc. Ideally, post a bit of code showing what you already tried.
There is a model in NetLogo based on simple preferential attachment. Agents create links thusly:
to go
if count turtles > num-nodes [ stop ]
let partner one-of [both-ends] of one-of links
create-turtles 1 [
set color red
move-to partner
fd 1
create-link-with partner
]
layout
tick
end
In this model, a node's chance of being selected is directly proportional to the number of connections it already has. I want to edit this code so that there is a variable, prestige, which also determines the probability that a node will be selected. I understand that I need to create a variable for turtles called prestige, but I'm stuck on how to make it so that the probability that a link will be created is also proportional to the amount of prestige a turtle has.
I am working on a flocking model with subgroups of agents that form temporary aggregations. I would like to quantify these subgroups by identifying them with a unique ID and a color. Thus I included the following subprocedure (chain-rule) in the go procedure, right before the tick:
to chain-rule
clear-links
ask turtles [
create-links-with other turtles in-radius distance-chain-rule
ask link-neighbors [
set subgroupID [subgroupID] of myself
set color 5 + 10 * subgroupID
]
]
end
This procedure is correctly linking only those agents within a certain distance, and because links die, it only links agents within what I want to call a subgroup (which is a temporary aggregation). The problem is the labelling: if they just acquire the subgroupID of their neighbors, eventually they all end up with the same subgroupID (and color), regardless of whether the agents still belong to the same temporary aggregation. How to update this labelling just like the links? Thanks in advance.
This is the solution I found with help by JenB, using the network extension's nw:weak-component-clusters. This procedure identifies, on each tick, the weak components of a network of agents linked by a given distance.
extensions [ nw ]
to chain-rule
clear-links
ask turtles [ create-links-with other turtles in-radius distance-chain-rule ]
set subgroups nw:weak-component-clusters
show subgroups
end
I am developing a model in Netlogo. I have many agents in my model. each agents must have a radio scope. Two agents can communicate with each other and transfer some critical data When they place in a common scope area.
Imagine that i have 100 agents with 5px scope and 200 agents with 3px scope. I have also 1 master agents that move around in the word. This master agent have a scope too(for example 7px) . Agents can communicate with each other when they place in common scope area. When they communicate they can transfer some of their data. At first just master agent have this critical data and just master agent can transfer this important data. But after he transfer its data to the other agents, those other agents that have this data can transfer this data too. The important condition is being in the common scope.
How can I do this?
Thank you
You just gave a very general statement of your problem. You will get better answers if you make the effort to actually start implementing something and ask about more specific difficulties that you are facing.
That being said, I made a small model that more or less fits with your description. Perhaps it could be useful for you as a starting point and you can ask separate (more precise) follow up questions if you have some.
turtles-own [ scope data ]
to setup
clear-all
; make a big world so agents don't
; bump into one another right away:
resize-world -100 100 -100 100
set-patch-size 3
; create turtles and distribute them around:
crt 100 [ set scope 5 set data "" ]
crt 200 [ set scope 3 set data "" ]
crt 1 [ set scope 7 set data "important data" ]
ask turtles [
set size 3
setxy random-xcor random-ycor
recolor
]
end
to go
ask turtles [ travel ]
ask turtles with [ not empty? data ] [ share-info ]
ask turtles [ recolor ]
end
to travel
; you haven't specified how turtles should move
; so here's a classic "wiggle":
rt random 30
lt random 30
fd 1
end
to share-info
ask other turtles in-radius scope with [ empty? data and distance myself < scope ] [
set data [ data ] of myself
]
end
to recolor
set color ifelse-value empty? data [ grey ] [ red ]
end
Edit:
Following Seth's comment that my first version probably didn't capture the idea of a common scope, I've added and distance myself < scope. This way, only turtles that can see each other can share information.
I've also added a with [ not empty? data ] clause when asking turtles to share info, because there is no use in having turtles with empty data share it.
Hello i will try to be quick
I have a room with a fire that expands , and i have two exits , all i want to do is say to agents that if a door is blocked by fire then to go to the other one. i came up with something like this but not result.
to doorblock
show count neighbors with [pcolor = 77] ;; the patch color of the two doors
end
;;to go
ask smarts [ ;;smarts are the agents inside the room that need to get oout
if [ doorblock > 5 ]
[ set target one-of sexits]] ;;sexits is the other door
Anyone got a better idea? Thanks
OK, so if I understood correctly, you want your agents to take a look at the door that is their current target, check if that door has more than 5 fire agents around it, and choose another target door if that is the case.
If your fire agents are just red turtles (with no specific breed), you probably want something like this:
ask smarts [
if count ([ turtles-on neighbors ] of target) with [ color = red ] > 5 [
if-else ([ breed ] of target = sexits )
[ set target one-of nexits ]
[ set target one-of sexits ]
]
]
The key primitives here are:
neighbors, that will give you the patches around a turtle (the patches around target, in this case)
turtles-on, that will give you the turtles that are on members of a patch set (here, that will be the turtles that are on the patches that are the neighbors of target)
and finally, with allows you to get only the turtles from an agentset that satisfy some condition (here, we use it to get only the red turtles that represent the fires).
You should also try to understand the of primitive.
And I guessed you wanted to assign a new target that was of a different breed than the previous one (south if north, north if south) but that's up to you.