Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.math.mathematica

Topic: 3D Agent Problem
Replies: 0  

Advanced Search

Back to Topic List Back to Topic List  
Earl.J.Mitchell@gmail.com

Posts: 12
Registered: 4/23/09
3D Agent Problem
Posted: Apr 23, 2009 6:42 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Hi,

I am trying to set up a 3D environment having 'agents' and 'stuff' whose
coordinates are random real numbers.

The program should then move the agents towards the closest stuff in
increments of, say, .1 units.

I was able to create a program that did what I need for one iteration, but
am having problems making it iterative... below is the code. I'm
inexperienced and learning quickly but would really appreciate any guidance
on iterating this system.

*****************
Making a World of Agents and Stuff

MakeNewWorld[Agents_] :=
Partition[Flatten[
Riffle[Table[RandomReal[{-10, 10}, {Agents, 3}]],
Table[RandomInteger[9, 3], {Agents}]]], 6, 6]

MakeNewStuff[Resources_] := Table[RandomReal[{-10, 10}, {Resources, 3}]]

agentpos1 = MakeNewWorld[10][[All, 1 ;; 3]];
stuffpos1 = MakeNewStuff[5];

ListPointPlot3D[{agentpos1, stuffpos1 }, PlotStyle -> PointSize[Large]]

***** 3D plot of agent positions and stuff positions *******

The Problem of Movement

Agents search for nearest stuff and move along the vector between their
current position and that of the stuff.

Ax = agentpos1[[All, 1]];
Bx = stuffpos1[[All, 1]];
Ay = agentpos1[[All, 2]];
By = stuffpos1[[All, 2]];
Az = agentpos1[[All, 3]];
Bz = stuffpos1[[All, 3]];

dx = Part[Ax, #] - Bx &;
dy = Part[Ay, #] - By &;
dz = Part[Az, #] - Bz &;

TOTdx = dx /@ {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
TOTdy = dy /@ {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
TOTdz = dz /@ {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

squared = #^2 &;

distance = (squared /@ TOTdx + squared /@ TOTdy + squared /@ TOTdz)^.5;

mindistance = Min /@ distance;

stufffinder = Flatten[Position[distance, #]] &;

stuffpositions = Flatten[stufffinder ] /@ mindistance;

newstuff = stuffpositions[[All, 2]];

coords = Part[stuffpos1, #] &;

stuffcoords = coords /@ newstuff;

WalkFunct2 =
If[Part[Flatten[agentpos1], #] < Part[Flatten[stuffcoords], #],
Part[Flatten[agentpos1], #] + .5, Part[Flatten[agentpos1], #] - .5] &;

newagentcoords =
WalkFunct2 /@ {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30};

agentpos2 = Partition[newagentcoords, 3, 3, {1, 3}];

ListPointPlot3D[{agentpos2, stuffpos1 }, PlotStyle -> PointSize[Large]]





Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2013. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.