Re: Help with Agent Problem...

• To: mathgroup at smc.vnet.net
• Subject: [mg99903] Re: [mg99874] Help with Agent Problem...
• From: DrMajorBob <btreat1 at austin.rr.com>
• Date: Tue, 19 May 2009 06:42:51 -0400 (EDT)
• References: <200905180630.CAA10436@smc.vnet.net>

```My great-grandfather was Henry Harrison Mitchell (lived in Snyder, TX), so
we could be cousins!

If by "iteration", you mean Manipulate for a specific j, there's already
no calculation being done, other than creating ListPointPlot3D. You can do
that calculation just ONCE for each j as follows:

plot[j_] :=
plot[j] =
ListPointPlot3D[{Steplist[[j]], stufflocations},
PlotStyle -> PointSize[Large]]

Manipulate[plot[j], {j, 1, Length[Steplist], 1}]

If by "iteration", you mean something that occurs in the statement
"Steplist = ....", I'll have to guess what it means to "ignore stuff

From this:

Length@Steplist

2001

Length@Union@steplist2

98

I see that many of the Steplist results duplicate one another, so I'm
guessing you want to avoid calculating the same result many times.

One way to speed things up is this:

Clear[f]
f[x_] :=
f[x] = x +
Sign[stufflocations[[Map[First[Ordering[#, 1]] &,
Outer[Norm[#1 - #2] &, x, stufflocations, 1]]]] - x]/10.
Timing[steplist2 = NestList[f, agentlocations, 2000];]

{0.035816, Null}

Timing[Steplist =
NestList[# +
Sign[stufflocations[[Map[First[Ordering[#, 1]] &,
Outer[Norm[#1 - #2] &, #, stufflocations, 1]]]] - #]/
10. &, agentlocations, 2000];]

{0.671936, Null}

steplist2 == Steplist

True

Speed results from the fact that there were only 98 different arguments
passed to f:

Length@DownValues@f

99

(One down-value is the formula itself.)

Hence f was calculated 98 times, not 2000.

I'm sure there are other optimizations available, but I'd have to pull
apart what f is really doing. I'll leave that to you.

Bobby

On Mon, 18 May 2009 01:30:06 -0500, Earl Mitchell
<earl.j.mitchell at gmail.com> wrote:

> Code:
>
>
> ************
>
> "Making a World of Agents and Stuff"
>
>
> makeNewWorld[agents_]:=Apply[Join,Partition[Riffle[RandomReal[{-10,10},{agents,3}],RandomInteger[9,{agents,3}]],2],1]
>
>
> makeNewStuff[resources_]:=RandomReal[{-10,10},{resources,3}]
>
>
> agentlocations=makeNewWorld[10][[All,1;;3]];
>
> stufflocations=makeNewStuff[5];
>
>
>
> "The Problem of Movement"
>
>
> "Agents search for nearest stuff and move along the vector between their
> current position and that of the stuff."
>
>
> Steplist=NestList[#+Sign[stufflocations[[Map[First[Ordering[#,1]]&,Outer[Norm[#1-#2]&,#,stufflocations,1]]]]-#]/10.&,agentlocations,2000];
>
>
>
> Manipulate[ListPointPlot3D[{Steplist[[j]],stufflocations},PlotStyle->PointSize[Large]],{j,1,Length[Steplist],1}]
> *************
>
> How could I alter this code so that at each iteration an IF statement (or
> multiple IF statements) is applied to the agents, allowing them to, say,
> ignore stuff that's already found by another agent?
>
> I've been trying to figure it out on my own for weeks... My idea's
> outpace
> my intelligence...

--
DrMajorBob at bigfoot.com

```

• Prev by Date: Re: trying to "install" a palette...
• Next by Date: Re: Problem with parallel evaluation of integrals depending on a
• Previous by thread: Help with Agent Problem...
• Next by thread: Re: Help with Agent Problem...