From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id 6263F7F8FC for ; Tue, 10 Jun 2014 11:12:06 +0200 (CEST) Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of goswin-v-b@web.de) identity=pra; client-ip=212.227.15.14; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="goswin-v-b@web.de"; x-sender="goswin-v-b@web.de"; x-conformance=sidf_compatible Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of goswin-v-b@web.de) identity=mailfrom; client-ip=212.227.15.14; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="goswin-v-b@web.de"; x-sender="goswin-v-b@web.de"; x-conformance=sidf_compatible Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mout.web.de) identity=helo; client-ip=212.227.15.14; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="goswin-v-b@web.de"; x-sender="postmaster@mout.web.de"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AoUBAL7KllPU4w8OnGdsb2JhbABZg1/EVgGBDRYPAQEBAQEGDQkJFCiEAwEBBScTTwsYCSUPBSiIYQEYCcRqH4V/EwSOCQERAVeDK4EWBJoghmASjlCBQoF0 X-IPAS-Result: AoUBAL7KllPU4w8OnGdsb2JhbABZg1/EVgGBDRYPAQEBAQEGDQkJFCiEAwEBBScTTwsYCSUPBSiIYQEYCcRqH4V/EwSOCQERAVeDK4EWBJoghmASjlCBQoF0 X-IronPort-AV: E=Sophos;i="4.98,1008,1392159600"; d="scan'208";a="66521894" Received: from mout.web.de ([212.227.15.14]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 10 Jun 2014 11:12:05 +0200 Received: from frosties.localnet ([78.43.112.61]) by smtp.web.de (mrweb002) with ESMTPSA (Nemesis) id 0LZet2-1WUstk1RPw-00lT71 for ; Tue, 10 Jun 2014 11:12:04 +0200 Received: from mrvn by frosties.localnet with local (Exim 4.82) (envelope-from ) id 1WuI67-00005Q-JY for caml-list@inria.fr; Tue, 10 Jun 2014 11:12:03 +0200 Date: Tue, 10 Jun 2014 11:12:03 +0200 From: Goswin von Brederlow To: caml-list@inria.fr Message-ID: <20140610091203.GA31598@frosties> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) X-Provags-ID: V03:K0:kjWgHeTKRgw6QyI42bwwlErLCp5ZS0Ng8lBNH5zDEipgCUHPUVx b1LMvI7V7PujI1Yj0RZzZPArnwAm5IpPsrz1MSXDD3EoMWjXou2KwuwWaRnvWt+toodXfN9 0tqSLSl3VO/+OrECNYmAbSfnkwfJpJtbqcKW9AOwpbu9Bb/ZpDKywyTKfGwu3lLIK0lArFR OCzvxN+idKSO2+8L7NVlQ== Subject: Re: [Caml-list] Designing a (functional) multi-agent simulation -- illusion of paralellism 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