Is this an acceptable algorithm for pedestrian motion that searches and mingles with "buddies" on its path to the goal? - simulation

I'll put my pseudocode here first, please advise regarding its validity according to real-world pedestrian motion, and how I can improve it.
Premise: A turtle walk from its spawn point to the goal. On the way, it meets other turtles. Turtles of the same color will be treated as a "buddy" and will go near it, simulating a "friends-walking-down-the-street" scenario. Turtles of the same color with nearer distance has higher priority, e.g. friend A is nearer than friend B so I will approach friend A first.
Upon approaching the goal, the turtle goes back to its spawn point.
Pseudocode:
determine if i am already in the goal
if yes,
determine if there are patches I can walk on
set eyes on nearest patch I can walk on (for the goal path)
if there is a friend nearby, approach friend
if there is no friend nearby, continue walking the goal path
if im already in the goal, respawn.
Advise for improvement please?

The premise doesn't say anything about how returning to spawn point occurs so I will assume it is a one step action (ie you are not interested in those details). I see something more along the lines of
spawn loop:
spawn
goal loop:
determine if turtle already reached goal
if no,
determine if there are patches I can walk on
set eyes on nearest patch I can walk on (for the goal path)
if there is a friend nearby, approach friend
if there is no friend nearby, continue walking the goal path
if yes,
setup so can respawn (return to spawn loc, etc)
goal loop ends

Related

AnyLogic - determination of lane in road traffic

In my model, car-agents sort in the correct lanes just a few car-length before the crossing when the traffic light is green. That way, the intersection gets unrealistically inefficient. What I can not find in the APIs is a way to determine the lane choice x meter before the intersection.
Is there a parameter, if not any idea, to set the lane choice of car-agents in front of a crossing?
Thankful for any thoughts.
I have found intermediate stop lines, which only cover certain lanes, can be used to give you more precise control. You can send a car to the intermediate stop line, and then send on to the final destination of choice.
the lane can only be chosen in the beginning when the car is created or through the enter/exit blocks... otherwise you have to just accept the randomness of the internal model and you have no control over it.
Edit: but amy in her answer is right that you can redirect cars to strategic intermediary stop lines in order to choose the lane or group of lanes the cars will choose whenever it's going to a certain destination.

Turtle Movement Netlogo

I have a network of turltes that each share two links. At the start of each turn the turtles decide to cooperate or defect, which updates a beta distribution of likelihood of cooperation in the next tick. If the turtles fail to cooperate over n turns they no longer interact. Through this I am able to create clusters in the cooperation network.
Right now, I am trying to figure out how to make the turtles move closer together proportional to the weight of their ties. Is there code to do this? I have only been able to find example code for patches.
I think this model might have something similar to what you want:
http://modelingcommons.org/browse/one_model/3632#model_tabs_browse_procedures

Move to the opposite location of a detected turtle

I have an agent mouse and an agent cat.
When a mouse detects the presence of a cat around him, I want the mouse to rotate to the opposite positions where it detected the cat.
You can make one agent face another with face. You can then make the agent turn around with rt 180. The result will be that they're facing exactly away from the other agent!
When you have the option of multiple cats there might be a problem when running away from just one of them...
In that case you might want to make some weighted new direction, depending on the cats in the surroundings. But then your definition of the 'empty directions' and possible problems with multiple groups of cats coming in from different directions...
alternatively, you just move-to one-of neighbors with [count cats-here == 0]
(which will probably cause a run-time error if all neighbors harbour a cat.. :-)

netlogo turtles moving on coordinates

I created turtles called "birds" that shall move on a specific route. The route is made out of links between turtles I called "rasts". As I couldn't find a way to make the turtles move from the first rast to the second, third, fourth and fifth, I changed the rasts an created them as patches.
So, now I have patches in red (rests).
How do I get the birds moving to exactly these patches and, when they are at the patch, how do I make them go to the next one?
I have no code at the moment, because I always hope to find the fault in my first model (see my other questions).
Is there anybody who knows how to solve my problem?
the move-to command moves your turtle to any other turtle or patch you specify. You can also use the face and forward commands to gradually move along a route (see the 'Move Towards Target' code example in the Models Library that comes with NetLogo)

A specific PathFinding approach

I am working on Unity, using C# for a project that should be quite simple.
I am stuck to pathFinding .
I have Looked at Dikjstra's and A* for reference, but for some reason I still can't adopt them to work in my case. I guess my brain :=while(1);
Here is the Idea:
From a textfile I import a "map" where each "*" means Wall, and each " " walkarea. In the map there area randomly placed 2 objects: a bomb and an agent.
The agent must investigate the map (which forms a maze) and discover the bomb. The agent may move to his 8 neighbour tiles if they are NOT Wall. In my code , the agent class hold his own map. for every tile that he visits, he asks the "world map" for info, about his 8 neighbour tiles.
On his own map then he takes a note of the known tiles type(wall / walkpath) , and if it is a walkpath, he also notes, how many times he has visited it. The agent also has a "Prefered direction " list. This tells which tile to choose next to move to, if more than 1 have not been visited.
Up to this point, I have set it up all good and running, and if I let it run, he eventually finds the bomb. The Issue is that because he only runs on a Prefered direction according to the least visited tile , he has to re-visit some tiles too many times like a moron. So what
I must do is this:
If the agent reaches a tile for which, every nighbour is either wall or already visited, then he should investigate his own map, and the notes from the past to find an unvisited tile , and walk to there. Every walk direction has the same weight/cost, so we don't need to consider cost of path.
In my opinion, Dijkstra's is the closest to apply , but I still can't get it right .
Any Ideas or help would be much appreciated.
Thank You
Alex
Part of the issue is how much information you want to allow your agent. If you're willing to let him know where the target is, or at least its general direction in relation to himself, then you can use that to help influence the agent's decisions. This would allow you him to always favor moving in the direction that gets him closest to the goal while taking the least visited path.
Otherwise I'd keep track of each place he visited in a separate map, as well as the 8 neighboring tiles since he has "seen" them, with something like -1 indicating a wall that has been seen, -2 indicating an unseen location, and 0 indicating seen but unvisited. I'd then use A* or a variant on it that would move him to the closest unvisited point based on number of tiles traversed, breaking ties randomly. This would lead to a more trial and error rat in a maze approach.