Author Topic: Version 3.0 status & code?  (Read 3721 times)

Offline nixblik

  • Bot Neophyte
  • *
  • Posts: 2
    • View Profile
Version 3.0 status & code?
« on: June 16, 2005, 05:08:38 AM »
Hi,

at some places in this forum (especially Shvarz's biology section) there is a lot of talk going on about very advanced features, and sometimes a "will be in 3.0". I was wondering how far you have come with the new major version. Do you have any specifications (about physics, DNA, e-grid, multibots, ...)? Is there some working code? Even results of extensive tests?

FYI: In the last 2-3 years I have repeatedly thought about writing some artificial life simulation. I have produced a lot of paperwork dealing with the various problems that arised. The main goals are:
  • Single cells as a whole are the simulation basis.
  • They should have some form of DNA that controls them.
  • Organisms consisting of multiple cells should not only be possible, but be more successfull.
  • Physics/chemistry realistical enough to produce interesting and comprehensible behaviour.
  • Be fast ─ 1000 to 10000 cells in the simulation with reasonable speed.
As you can see, this is very much headed towards the thoughts discussed in Shvarz's forum (a very interesting one, by the way), and differs a lot from the current DarwinBots where physics are a mess (ok, this applies more to earlier versions) and protozoa rule. I did a lot of thinking how the world should be organized to bring forward multicellular organisms, and the conclusions were similar to yours (different substances that disperse through the medium, basic cell metabolics, rather complex physics, lots of numerical computer science for approximating integrals and differential equations).

These kind of things tend to become very complex, and I haven't found a way to simplify some abstract thoughts (for example substance dispersion and metabolics) enough to write some code for it. All I have realized yet is a physical simulation of spheres (in 3-dimensional space) moving around, optionally tied together with elastic links, and collisions. The main goal was to test cell division in the center of a cell agglomerate (where there's not really space for it, thus the cells are pushed outwards). It somehow works, but it is very sensitive to the constants used in the calculation (stiffness, damping, viscosity), and the links break often.

That's why I came here: I was looking for ideas... :help:
:)

Ciao
uwe

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7742
    • View Profile
Version 3.0 status & code?
« Reply #1 on: June 16, 2005, 09:46:40 AM »
What we called 3.0 was going to have all the metabolism stuff working and going together.  But it was taking so long I just took what I had and released it as 2.36, and left metabolism and the grid for later.

And later and later.  I still haven't gotten even an egrid working.  :(

Physics in the current version, you're right, is very lame.  I've reworked it in an as-yet unreleased version to use net forces and vectors, and it's working like a dream.  There are a few instabilities, from the simplistic integreation method being used, but if you'd like to look at how I did it, I can show you the code.  Alot of things just "work", even though I didn't specifically program them, which is very exciting.  Angular momentum for one.

Our program runs a bit slower than it otherwise would becaue it's in VB.  If you did a project in C++, and used assembly for the slow calculations (like square roots, etc.) you might expect to get 30 cycles/second with 1000 spheres.  That's my experience with it anyway, and believe me, I've been working on the program's speed for a long time.

The main slow down is in checking what can see what else.  I suppose if you didn't use eyes as senses, made the spheres move around by touch, you could get faster results.

You'll want to partition your spheres into quad trees or oct trees (oct trees since you're in 3D).  I just recently implemented a quad "tree" in the new version, and the unoptimized, easy to debug version is running as fast as the old, super optimized, thousands of lines of code, ball of mud was.

I'd look in the suggestions forum, under Specialization, Metabolism, Digestions and Env Grid.  It's got alot of good ideas on how to implement metabolism and all that jazz.

As far as DNA goes, it depends on your needs of course.  Are you modelling behavior or something else?  For behavior you'll want a fairly easy, high end language that makes FSMs easy to program and develop through mutations.  The more robust your language (difficult to break the syntax) the more useful any mutations you get will be.

Last, don't go down the route of specifically programming in gimmes to multicellular organisms.  It doesn't seem to really produce any results.  A better route is to craft the rules such that colonies are encouraged to develop, and through colonies, more orchestrated organsisms, on and on until you get a simple differentiated and connected organism of more than one sphere.

If you're interested, we could work together to make some code for the E grid, among other things, and the lessons you learn ahould help towards your own simulation.  There's been alot of reinventing of the wheel in ALife sims, and there's just no need for that.
« Last Edit: June 16, 2005, 09:51:59 AM by Numsgil »

Offline nixblik

  • Bot Neophyte
  • *
  • Posts: 2
    • View Profile
Version 3.0 status & code?
« Reply #2 on: June 16, 2005, 04:19:12 PM »
Numsgil, thanks a lot for the very useful reply! I read through the whole metabolicism thread (quite a discussion :) ). Lots of good ideas in there, especially your enzymes-as-bit-patterns idea.

Not sure what you mean with "angular momentum". If a bot has several ties, they should maintain the same angle in between. This is relatively simple to calculate in 2D, but in 3D it turns out to be fairly complex... I have not even found formulas for that problem yet. But it is very important, because organisms like Volvox can be crunched like aluminium foil otherwise. But I am not sure if I really want to do it 3D. Good thing is, physics for 3D work almost unchanged in 2D (but not the other way round).

Switching to assembly is not an option, because all calculations are done using real numbers. It is much simpler this way, and the modern FPUs are just as fast as the processor with integers (tested). I use D for programming, it is some changed C++ and should be at least equally fast. Slowdown seems to come mostly from the collision detection, as it is quadratic now (no use to optimize it for testing). I have commented it out and the execution speed almost explodes.

You have talked about a quadtree... what is that? Do you only divide the flat space into small squares, and sort every cell into one square? Or is it some more complex dynamic thing (I once thought about dividing the room dynamically, with the grid density proportional to the cell density, to make large space simulations possible).

I also thought of adjusting the conditions in a way that multicellular organisms are leveraged automatically. My idea was to make the single cells incapable of doing cool things like shooting, moving around fast, seeing things and stuff. Instead they are very basic, emitting enzymes and absorbing substances from the environment, merely drifting around and reacting on chemical gradients. They are simply incapable of killing another cell, they can only eat the remainders. The first thing MBs evolve is a hole in the body (=stomach) where they can rise the concentration of enzymes (which would otherwise disperse into the great wide open) to lethal levels. The question is how to calculate the substances dispersion in such a world? The system needs to be aware of the fact that substances cannot disperse through cells. Brute force approach would be to model substances as little particles moving around randomly, and colliding with cells. It would be a *lot* of particles, perhaps 100·cellcount. Collision detection for them is just impossible. :(

Ciao
uwe

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7742
    • View Profile
Version 3.0 status & code?
« Reply #3 on: June 16, 2005, 04:57:28 PM »
Quote
Not sure what you mean with "angular momentum".

You'd have to experiment in current Darwinbots, and then play around in the new version I have.  Basically, current Darwinbots doesn't behave realistically with ties.  The bots just sort of wiggle alot.  You just can't get them to rotate about their center of gravity.

The only things I calculate are tie (spring) forces: ie: -kx - bv, voluntary forces (like when the bots move), gravity, drag, friction, collisions, etc.  All incredibly simple equations.  (-kx - bv is by far the most complex)  But it seems that some complex laws, like the conservation of angular momentum, arise naturally from these simpler rules, which is a good sign that I have a very good physics engine (albeit simple since it's only dealing with spheres).

The great thing about using forces and vectors is that it's N-dimensional.  Vectors work just as well in 3D as in 2D.  I can show you the code if you like, it took a while to really get it all working, but it's just so simple.

Quote
Switching to assembly is not an option, because all calculations are done using real numbers.

You don't have to switch everything to assembly, but C language derivatives allow in-line assemby, which means you can really optimize the oft-called functions (sqr especially) in assembly for speed quite easily (well, assuming you know assembly).

Quote
Slowdown seems to come mostly from the collision detection

And that's where a quad tree is going to save you cycles and cycles, which leads us to...

Quote
You have talked about a quadtree... what is that? Do you only divide the flat space into small squares, and sort every cell into one square? Or is it some more complex dynamic thing (I once thought about dividing the room dynamically, with the grid density proportional to the cell density, to make large space simulations possible).

A quad tree is basically taking the entire simulation universe and dividing it into grids, and then operating from those grids.  For collision detection, you only need to check spheres that are in the same or adjacent grids, since grids further than that can't collide with each other.

An oct tree is the 3D equivelant.  A Kd-tree divides the space more reasonably based on distributions of objects (that is, highly clumped areas get more grids than empty areas).

Search for quad tree, oct tree, and kd trees on google or wikipedia or gamedev.net. You should be able to find what I'm talking about.

Quote
The question is how to calculate the substances dispersion in such a world? The system needs to be aware of the fact that substances cannot disperse through cells. Brute force approach would be to model substances as little particles moving around randomly, and colliding with cells. It would be a *lot* of particles, perhaps 100·cellcount. Collision detection for them is just impossible. :(

Yes, this is more or less where I'm stuck too.  Here's my thoughts on the idea:

The world is defined in a grid, and you just store the concentrations of substances in each grid.  The smaller each grid, the more exact you simulation will be, but also the slower.

Every N cycles (every cycle is very slow, but you may need to do it that way) you calculate diffusion.

Now this is where it gets tricky, since you want to move substances inside multicells with them, and substances outside around them.  So the answer is to have a seperate grid for enclosed spaces (how you find at run time what an enclosed space is I have no idea).  Enclosed spaces can then be moved around by the critters.  Something like this:

each number represents a concentration in that grid square, with (number) being the enclosed space:

(0) 5 6 8 4 4 5
enclosed space moves:
(0) 6 8 4 4 5
and again (note that the grid it was over is unchanged)
5 (0) 8 4 4 5

You can then program some interfaces between the enclosed space and the grid it's on if you want to simulate leakage or something along those lines.  The trick is just to keep enclosed spaces and the rest of the game universe seperated logically.  Then most everything else falls into place.
« Last Edit: June 16, 2005, 04:58:00 PM by Numsgil »