caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Designing a (functional) multi-agent simulation -- illusion of paralellism
@ 2014-06-09 14:24 O Frolovs
  2014-06-09 15:56 ` Anthony Tavener
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: O Frolovs @ 2014-06-09 14:24 UTC (permalink / raw)
  To: caml users

[-- Attachment #1: Type: text/plain, Size: 773 bytes --]

Hello

I am trying to write a predator-prey simulator and I have hit the wall with
functional design. I would appreciate any help or pointers to relevant
literature.

The simulator is that of a world populated with fish and sharks. It is a
discrete-time multi-agent simulation and what I am struggling to think
about is how to implement the illusion of parallelism in simulation. Since
the problem is not specifically with OCaml (but the simulator is in OCaml),
I have kept this email short and put all the details and the code on GitHub:

"On the subject of Toroidal Planets, Sharks and Fish."
https://gist.github.com/olliefr/fb26ca3a7645dae7e203

It's only a hobby project, but it is of some interest to me, so I would
really appreciate any advice.

Best regards,

Ollie

[-- Attachment #2: Type: text/html, Size: 1056 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] Designing a (functional) multi-agent simulation -- illusion of paralellism
  2014-06-09 14:24 [Caml-list] Designing a (functional) multi-agent simulation -- illusion of paralellism O Frolovs
@ 2014-06-09 15:56 ` Anthony Tavener
  2014-06-09 16:44   ` Arnaud Spiwack
  2014-06-09 16:02 ` Arthur Breitman
  2014-06-10  9:12 ` Goswin von Brederlow
  2 siblings, 1 reply; 5+ messages in thread
From: Anthony Tavener @ 2014-06-09 15:56 UTC (permalink / raw)
  To: ollie.frolovs.2012; +Cc: caml users

[-- Attachment #1: Type: text/plain, Size: 1566 bytes --]

To implement something like the bidding you're thinking of (or any
finer-grained competition) you might need to have several sub-iterations to
each timestep... or each timestep is smaller and not sufficient for
completing an "eat" action. Think of pipelined processors, perhaps, as some
inspiration. ;)

For an example of sub-iterations within each timestep: you have claims,
then resolve conflicting claims, then do all resulting actions. In this
case, "losers" of a competition probably wasted their action. If you still
want them to be able to at least do a simpler action or start another
claim, this is where you might want finer-grained steps (and actions).


On Mon, Jun 9, 2014 at 8:24 AM, O Frolovs <
ollie.frolovs.2012@my.bristol.ac.uk> wrote:

> Hello
>
> I am trying to write a predator-prey simulator and I have hit the wall
> with functional design. I would appreciate any help or pointers to relevant
> literature.
>
> The simulator is that of a world populated with fish and sharks. It is a
> discrete-time multi-agent simulation and what I am struggling to think
> about is how to implement the illusion of parallelism in simulation. Since
> the problem is not specifically with OCaml (but the simulator is in OCaml),
> I have kept this email short and put all the details and the code on GitHub:
>
> "On the subject of Toroidal Planets, Sharks and Fish."
> https://gist.github.com/olliefr/fb26ca3a7645dae7e203
>
> It's only a hobby project, but it is of some interest to me, so I would
> really appreciate any advice.
>
> Best regards,
>
> Ollie
>

[-- Attachment #2: Type: text/html, Size: 2205 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] Designing a (functional) multi-agent simulation -- illusion of paralellism
  2014-06-09 14:24 [Caml-list] Designing a (functional) multi-agent simulation -- illusion of paralellism O Frolovs
  2014-06-09 15:56 ` Anthony Tavener
@ 2014-06-09 16:02 ` Arthur Breitman
  2014-06-10  9:12 ` Goswin von Brederlow
  2 siblings, 0 replies; 5+ messages in thread
From: Arthur Breitman @ 2014-06-09 16:02 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 1288 bytes --]

Have two types for world: a regular world, and a dirty world, with
potential conflicts.

From a clean world, generate a dirty world by applying moves (in parallel).

From the dirty world, generate a clean world using a conflict resolving
projection.

Such a projection could involve bidding, bouncing the fishes off each other
when they collide, giving stochastic priority to some fishes, etc.
On Jun 9, 2014 10:26 AM, "O Frolovs" <ollie.frolovs.2012@my.bristol.ac.uk>
wrote:

> Hello
>
> I am trying to write a predator-prey simulator and I have hit the wall
> with functional design. I would appreciate any help or pointers to relevant
> literature.
>
> The simulator is that of a world populated with fish and sharks. It is a
> discrete-time multi-agent simulation and what I am struggling to think
> about is how to implement the illusion of parallelism in simulation. Since
> the problem is not specifically with OCaml (but the simulator is in OCaml),
> I have kept this email short and put all the details and the code on GitHub:
>
> "On the subject of Toroidal Planets, Sharks and Fish."
> https://gist.github.com/olliefr/fb26ca3a7645dae7e203
>
> It's only a hobby project, but it is of some interest to me, so I would
> really appreciate any advice.
>
> Best regards,
>
> Ollie
>

[-- Attachment #2: Type: text/html, Size: 1868 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] Designing a (functional) multi-agent simulation -- illusion of paralellism
  2014-06-09 15:56 ` Anthony Tavener
@ 2014-06-09 16:44   ` Arnaud Spiwack
  0 siblings, 0 replies; 5+ messages in thread
From: Arnaud Spiwack @ 2014-06-09 16:44 UTC (permalink / raw)
  To: Anthony Tavener; +Cc: ollie.frolovs.2012, caml users

[-- Attachment #1: Type: text/plain, Size: 2037 bytes --]

I don't quite understand the specifics of your needs. But the typical
starting point is the comonadic structure of the grid (see
http://blog.sigfpe.com/2006/12/evaluating-cellular-automata-is.html ) where
you basically iterate over the resulting cells rather than the existing
agents. I don't know if your example can fit in this framework.


On 9 June 2014 17:56, Anthony Tavener <anthony.tavener@gmail.com> wrote:

> To implement something like the bidding you're thinking of (or any
> finer-grained competition) you might need to have several sub-iterations to
> each timestep... or each timestep is smaller and not sufficient for
> completing an "eat" action. Think of pipelined processors, perhaps, as some
> inspiration. ;)
>
> For an example of sub-iterations within each timestep: you have claims,
> then resolve conflicting claims, then do all resulting actions. In this
> case, "losers" of a competition probably wasted their action. If you still
> want them to be able to at least do a simpler action or start another
> claim, this is where you might want finer-grained steps (and actions).
>
>
> On Mon, Jun 9, 2014 at 8:24 AM, O Frolovs <
> ollie.frolovs.2012@my.bristol.ac.uk> wrote:
>
>> Hello
>>
>> I am trying to write a predator-prey simulator and I have hit the wall
>> with functional design. I would appreciate any help or pointers to relevant
>> literature.
>>
>> The simulator is that of a world populated with fish and sharks. It is a
>> discrete-time multi-agent simulation and what I am struggling to think
>> about is how to implement the illusion of parallelism in simulation. Since
>> the problem is not specifically with OCaml (but the simulator is in OCaml),
>> I have kept this email short and put all the details and the code on GitHub:
>>
>> "On the subject of Toroidal Planets, Sharks and Fish."
>> https://gist.github.com/olliefr/fb26ca3a7645dae7e203
>>
>> It's only a hobby project, but it is of some interest to me, so I would
>> really appreciate any advice.
>>
>> Best regards,
>>
>> Ollie
>>
>
>

[-- Attachment #2: Type: text/html, Size: 3093 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] Designing a (functional) multi-agent simulation -- illusion of paralellism
  2014-06-09 14:24 [Caml-list] Designing a (functional) multi-agent simulation -- illusion of paralellism O Frolovs
  2014-06-09 15:56 ` Anthony Tavener
  2014-06-09 16:02 ` Arthur Breitman
@ 2014-06-10  9:12 ` Goswin von Brederlow
  2 siblings, 0 replies; 5+ messages in thread
From: Goswin von Brederlow @ 2014-06-10  9:12 UTC (permalink / raw)
  To: caml-list

On Mon, Jun 09, 2014 at 03:24:11PM +0100, O Frolovs wrote:
> Hello
> 
> I am trying to write a predator-prey simulator and I have hit the wall with
> functional design. I would appreciate any help or pointers to relevant
> literature.
> 
> The simulator is that of a world populated with fish and sharks. It is a
> discrete-time multi-agent simulation and what I am struggling to think
> about is how to implement the illusion of parallelism in simulation. Since
> the problem is not specifically with OCaml (but the simulator is in OCaml),
> I have kept this email short and put all the details and the code on GitHub:
> 
> "On the subject of Toroidal Planets, Sharks and Fish."
> https://gist.github.com/olliefr/fb26ca3a7645dae7e203
> 
> It's only a hobby project, but it is of some interest to me, so I would
> really appreciate any advice.
> 
> Best regards,
> 
> Ollie

As others have said you need to do things in steps, first plan, then
do, to make all fish and shark move atomically at the same time.

But is that realy relevant? Is that even practical?

I assume you don't just want the fish and shark to move completly
random. A fish that is next to a shark should move away from a shark.
A shark that is next to some fish should pick a random one and eat it.
And so on.

But if all fish and sharks move at the same time then a fish would
always escape unless cornered by multiple sharks. And a shark would
just follow a fish once it found one.


So lets go back to the begining:

When you move one fish/shark at a time you say that the problem is
that the first fish has more choices than the second. It is true that
with 2 fishes next to each other the movement of the first can block a
field for the second fish. But also it vacates its old field adding
more choices for the second fish. Overall the number of choices taken
and given will even out.

So I think moving fish and sharks in a round-robin way with some
intelligenz added for when they are near each other would make things
more interesting.



Some more ideas:

- create a common agent class and inherit that in both fish and
sharks. Then in the world just keep a list/set/whatever of agents.
Don't have a list of fish and list of sharks.

- The agent class should provide a method val can_eat : agent -> bool,
or val food_value : agent -> int, which values <= 0 denoting that the
agent would get eaten rather than eat the other. That way you can have
more agents, species that can coexist, a food chain and so on. You can
have sharks that prefer bigger fish when given a choice or sharks that
don't eat small fish.

- Make the movement biased. If an agent swims in one direction it
can't easily swim back the next tick. Make it go forward, turn left or
turn right. Give it some memory of what direction it is going. Maybe
even add speed (going in the same direction as last adds speed,
turning slows you down?). Add some genetic material to the agent that
weighs those options and mutate them when an agent breeds.

- Make the world have 4 (up, down, left, right), 6 (hexagonal) or 8
(like 4 + diagonals) directions.

- Have multiple prey agents and have the prefered food source as part
of the predators genetic material. Then you can simulate rabits, moose
and wolfs. You would see the wolfs switch between rabits and moose
over time depending on which prey population is more common.

- Add graphics support so you can see the world as it is each
iteration and to draw a histogram (how many prey, hwo many predators
at each tick?).

MfG
	Goswin

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-06-10  9:12 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-09 14:24 [Caml-list] Designing a (functional) multi-agent simulation -- illusion of paralellism O Frolovs
2014-06-09 15:56 ` Anthony Tavener
2014-06-09 16:44   ` Arnaud Spiwack
2014-06-09 16:02 ` Arthur Breitman
2014-06-10  9:12 ` Goswin von Brederlow

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).