Friday, May 25, 2007

World Simulation Update 25-May-2007

Completed two simulations this past week. I made some changes to the rabbit model as a result of the simulation.

The population didn't peak until 114,000. Not too odd, I really didn't know expect what to expect for the population peak. The collapse leveled out at 40k rabbits. Too many rabbits, unless it was a giant rabbit farm. I adjusted how much a rabbit ate every day. Each increase gave diminishing returns on how much the population dropped. I ended with the rabbits consuming 5 times more than what it was before. This reduced the population by 4 times. The rabbit population averaged about 10k or roughly 1 rabbit per cell Other changes that I made resulted in only small drops that would eventually increase to 10k over time. It just left a higher vitality rate. Still high, but then there isn't any competition for food. I threw in 20 predators at the end and then 40. No changes in the average population, just changes in the wavelength of the population waves.

The second simulation ran faster. I left the rabbit feeding rate unchanged from what I raised it to in the first simulation. The population peak was only 40k this time. I slowly implemented the number of predators into the simulation. First 40 day, then 80, then 120. As you can see the wavelength of the population increases with more predators in the system. apparently 120 predators hit a crossover point. Vitality started going up population growth was barely positive. Vitality growth was not faster than pop growth though. This eventually led to another collapse. This time the collapse left the rabbit population at a level where it couldn't support the predators population.

The predators are very simple they eat 1 rabbit every day. I still need to work on the animal objects and do the coding for the fox so that it is tied down to a cell and can only see so much of the world around him.

I think I'm going to increase the world size from 1 sq km to 10 sq km. That translates to over 1 mil cells. It should be large enough so that when I start to add larger herbavoirs, they will be supported in large enough populations.

Labels:

Thursday, May 17, 2007

World Simulation Update 17-May-2007

Work has been taking up a lot of my time. I've managed to expand the world size from 100 cells to 10,000 cells. So the world is now 100x bigger than before. So I'm up to the equivalent of 1 square kilometer or a Hectare.

I took a shortcut on the display since I haven't had time to work on it. It sends all of the information for the 10,000 cells. No Google map style scrolling. This translates to a very long load time, epically right now with almost 100,000 rabbits in the world. At home with a local connection it takes over 5 minutes. I can't imagine what the timing would be for going out on my DSL connection.

The current simulation has been running for 2 days and has not peaked for the mass die off of the rabbits. I've made a few changes to the database. I added an index on the animal table. When you only have a few thousand rabbits an index doesn't help much. When you have tens of thousands of rabbits an index does help a lot.

I'm estimating that I am now getting at least 300 updates a second. Each rabbit makes at least two updates to the database per cycle, plus the weather update for the land. My estimate should be low since my timing also includes vacuuming the database and running a query that gathers the stats at the end of each day cycle.

After the die off, I'll let the simulation run for a few thousand days. Enough to go through 5-6 die off cycles. I'll then introduce the predator effect on the rabbits. We'll see what effect the predator will have on the simulation. I'll just need to make sure that my daily predator feeding rate doesn't exceed the average minimum daily birth rate. I don't know at this time whether to include a death rate since all of the rabbits tend to die from starvation before they reach an old age and this first predator simulation will eat the oldest rabbit first.

I still need to work on the animal object definition. The expanding of the world has caused me to take another look at how to handle the data being stored on the land, and what information needs to be stored.

Labels:

Friday, April 20, 2007

Rabbit Graphs

Ran through several 2500 day simulations, They all look similar even after getting rid of the Genghis Horde maybe just a little less volatile.

The first one is of the Genghis Horde. The initial peak was shortened due to my noticing a few things wrong with the code.






The rest follow the same pattern, just less volatile. The initial spike does go higher due to the spreading out of the rabbits.







More of the same. This one looks like I had more rain falling for a short time span leading to a larger spike leading to a population of over 200 for a few days.










This on just shows that the range is similar to the second run. I'll do a few runs out to 5k days, but I don't expect to see much change.



I did change a few items. The scripts that I use to advance the days, I added some database maintenance scripts to improve performance. The first run took 8 hours. The second took 5 after I made manual interventions. The third and fourth runs took 2 hours each after adding the changes. Of course none of the code is optimized, and the database doesn't have any indexing.

The last big environmental change I need to add back is when an animal dies a part of it goes back into the land as vitality. This should boost the base line population, as well as cause an echo from the initial spike.

Two things I've noticed so far. One, grazers if left unchecked will devastate the land and have massive die off cycles where 50-60% of the populations dies off in a short space of time dues to starvation. Second, the map is mostly brown and yellow. The brown tiles represents bare ground no grass growing. Yellow means sparse amounts of grass. I'm sure if I was going to model environmental effect this would eventually turn into desert or a barren wasteland.

Over the next few weeks, I'm going to review the current code and replace the code with procedures. I've created a few procedures, but some of the code generated this week is directly into the main code loop. Then I'll look at encapsulating the procedures into objects. Once that is completed, I'll look at making the undying, non breeding, predator. I'm thinking Fox at this point.

Labels:

Thursday, April 19, 2007

Genghis Rabbit Hordes

Ran through a 2000+ day simulation over night. The days start to drag as the number of animals increase. The early part revealed a few bugs I had on removing dead rabbits. I also saw a big trend when there are a lot of rabbits running around looking for something to eat. I'll call it the Genghis Rabbit Horde affect. The rule for the rabbits was to eat then move to the best place to eat next ("The grass is always greener rule"). This led to a horde of rabbits moving together from one cell to the next. The bad thing is that the horde would get so big that not all of the rabbits would have something to eat. This led to massive die offs from starvation. I expect boom bust cycles, but I think this pattern exaggerates the cycle magnitude.

I set up a simple history tracking table, at the end of each day it takes the average vitality of the cells in the grid and the number of rabbits. I'll post some pictures of the graphs later after going through several runs.

I made a change in the order of what the rabbits do. It moves to a new cell then eats. Hopefully this will cut down on the horde affect.

World Display

Labels:

Wednesday, April 18, 2007

Die Rabbit Die

Rabbits can now die. The earliest scheduled death is day 1825. I'm glad I limited the first initial birth rate to a single rabbit.

Updated the display to show a count by animal.

With that many rabbits running around eden is starting to look like a dust bowl.

I also upped the hourly calculations to a 100 days per hour.

World Display

Next step is to setup an animal vitality so that they can starve to death, and set a limit on when the land vitality goes down to a certain level they can no longer eat / draw vitality from the land.

Labels:

Saturday, March 24, 2007

Rabbit Mania

World display

Created a basic rabbit, and changed the display program so that it displays all animals in the grid. The rabbit right now eats it's fill for the day, and then moves to another location in the cell. I discovered that the energy going into the cells was too high. It was supporting over 14 rabbits and there was no degradation of the vitality in the cells. According to a quick estimate I should be supporting maybe 3 rabbits in this amount of area.

So the next step was to half the energy input into the cells. It fell rapidly in less than 2 years it went down to under half of the vitality. I've jumped up the energy to 75% of the original and reduced the rabbits to 5. Total vitality of the cells has slowly grown over 10 years.

I set up a cron job to run a shell script that executes about 1000 days at a time.

Next steps is the tune the energy levels, and make the rabbits more rabbit like.

Labels:

Wednesday, March 21, 2007

World Simulation: Rabbit

Drew a rabbit like icon and have it displaying. No data behind the image still working out the details of the data that will be needed. I started up a discussion in the forums.

Picking a rabbit seems to be a good choice of animals to pick. Lots of data and studies on these little critters. Found an article that confirms my simplified simulation seems to be going down the correct path. I can't read the full article, but the abstract gave me enough information on determining what my vitality figure for a cell represents and how to relate it to the rest.

Rabbits eat a lot over a year. I'm going to use the 1.7% as a base reference. I'm calculating that a rabbit consumes all net productivity of .0068 hectares. My little play pen is representing .01 hectares. Since this is not southern Ill, but my version of Eden. I should see less of an impact. Even so this .01 hectares could only support 3 rabbits at most before there is a gradual degradation of the cell.

Found some other links that gave ranges of food pellets in grams that a rabbit can consume in an average day. It comes out to between 25-50 grams per kilo per day. I figure that an average grassy plot of 10 sq meters may contain between 5-10 pounds of grass. Thats 1270-2540 grams of grass. Since those are pellets and pellets contain cereal grains in them and no water. A rabbit would eat maybe twice as much in unprocessed food. Just from what I have put together I'm getting between 20 and 30 cells to support a rabbit. It looks that I might be estimating high on the grass weight or underestimating the consumption needs of a rabbit.

Labels:

Converted Weather Perl script over to PHP

display

Since I had the weather script working, I wanted to take the time and convert it over to PHP before going into more elaborate work. I’ll start to break out segments of the program into separate files. It should make maintenance easier. The conversion worked on the first try. The differences in syntax between Perl and PHP are not that great. The big difference is in the random number generator. My first pass at looking for examples on random number generation for PHP found only an integer generator. No big deal. Place a max range and divide by max rand and I get a real number between 0 and 1.

It appears that less energy is being passed through with this random generator. I’ll run through several tests. And make some adjustments.

The php script might be slower, or it’s speed decline could be caused by the web server or going over the network. Doesn’t really matter, as the scripts start to get finalized, parts of it will be changing over to database procedures and packages.

Labels:

Tuesday, March 20, 2007

Weather update

Think I have a stable weather distribution, Just sunny days or rainy days. 20% chance for rainy, otherwise it's sunny. Rain adds 25% moister to the soil and a random between 0 and 1 added for vitality. Sunny reduces moister by 10% and adds vitality random between 0 and 1. If moister goes below 0% then deduct 1 from vitality.

Ran the first simulation with everything set to zero. It took about 650 days to get most of the cells up to a green level of vitality. (between 75 and 100)
This shows that there is enough energy going into the simulation to support the basic land unit and have the vitality increase over time.

I've added a day counter to the display to show the age of the simulation.

Here's the link to the display: Display


I've set up a forum section for discussions on ideas or general discussion about building a model. Link

Labels:

Monday, March 19, 2007

World simulation

One of the ideas, I've had churning in my head for years have been to develop a world simulation. This simulation would contain a self-sustaining eco-system. The eco-system would have basic food-chain systems that function all the way up to having humanoid forms.

Where to start? Well I need to start with a piece of land.

This will be my basic land unit. The world will be made up of a basic land unit. So what kind of traits will this piece of land contain? All eco systems are based on energy. Our source of energy is sunlight; sunlight has two effects heat, and provides plants with the required energy for photosynthesis. The other main ingredient is water.

The fluctuation of the energy being imparted onto a piece of land is weather. The goal is to create weather that leaves the land in a perpetual state of Eden. For me Eden is around 75 degrees Fahrenheit for the high and enough rain every few days to keep everything green.

I’m going to take a shortcut and make the assumption that every land piece is covered by grass. This combination of Land and Grass will be my vitality value.

The following is a list of the data elements that I have identified as being needed.

land_id
grid_number
cell_number
land_type
vitality
soil_moister
water_level

The first 3 are elements that will be used to identify where the piece of land is located. I’m going with a single land element = cell. A grid contains a 10 x 10 grouping of cells. As things grow I will use an area = a 10 x 10 grouping of grids. If a cell is equal to 10 x 10 meters then an area will be equal to a square kilometer. The grid and areas will help keep track of events that impact a large group of cells, or if events cause persistant lingering effects that need to be tracked.

Here is a link of the visual display of my first sample grid. Right now instead of a grid effect of the weather each cell will have its own weather event.

http://www.4rca.com/cgi-bin/world/display.php

Labels: