caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Goswin von Brederlow <goswin-v-b@web.de>
To: caml-list@inria.fr
Subject: Re: [Caml-list] Designing a (functional) multi-agent simulation -- illusion of paralellism
Date: Tue, 10 Jun 2014 11:12:03 +0200	[thread overview]
Message-ID: <20140610091203.GA31598@frosties> (raw)
In-Reply-To: <CAERFpKW7Zpb4u5nVLt_cEj=z5JxbupEyAzYL_z5dNqVVguP4sw@mail.gmail.com>

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

      parent reply	other threads:[~2014-06-10  9:12 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-09 14:24 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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140610091203.GA31598@frosties \
    --to=goswin-v-b@web.de \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).