Closed sahil-khan11 closed 3 months ago
yeah this shouldn't find any neighbor, it should return nothing
in nearest_neighbors
. Probably a bug.
@Datseris What do you think about this? I was thinking maybe replacing nearest_neighbor() in interaction_pair() with this logic. At the moment it compares all partners in a given radius based on Euclidean distance and gives out one that is nearest to the agent within that given radius. It can be modified to give all neighbors for a given radius too.
r = 0.5
agent = model[27]
partner = agent #To create a similar type of variable
partner_dist = 10.0 #Variable with some random big number for saving and comparing new partner distances
z = partner_dist #For return verification
for id in allids(model)
if id != agent.id
x = euclidean_distance(agent.pos, model[id].pos, model)
if x <= r && x <= partner_dist
partner_dist = x
partner = model[id]
end
end
if partner_dist == z
return nothing
else
return (partner, partner_dist)
end
end
It doesn't look elegant at the moment but I think it does the work :)
Some outputs here:
with r = 1
(SocialAgent(56, [0.4123437422626348, 0.8654172979541885], [0.0014994958181429924, -0.0013234471245092032], 1.0), 0.11955423401462202)
with r = 0.7
(SocialAgent(56, [0.4123437422626348, 0.8654172979541885], [0.0014994958181429924, -0.0013234471245092032], 1.0), 0.11955423401462202)
with r = 0.5
(SocialAgent(56, [0.4123437422626348, 0.8654172979541885], [0.0014994958181429924, -0.0013234471245092032], 1.0), 0.11955423401462202)
with r = 0.1
nothing
with r = 10^-100
nothing
Let me know what you think :)
I'm not on my computer to test this, but I think this can be fixed simply by using nearby_ids_exact
instead of nearby_ids
in nearest_neighbors
Yes, it seems nice. I just checked but there is a difference that nearby_ids()
doesn't count self-agent which is the point of reference while nearby_ids_exact()
does. How it can be avoided? because it will be an issue otherwise.
I don't think that it is true, nearby_ids_exact
just filters out nearby_ids
Fixed in #1044
Issue The nearest neighbor for a given agent within the radius "r" doesn't align with the Euclidean distance between the agent and its nearest neighbor. The following example shows that the distance between neighbors is quite big compared to r used in the nearest_neighbor() function.
Minimal Working Example
Output
Agents v6.0.12 Julia v1.10.1