このページはEtoJ逐語翻訳フィルタによって翻訳生成されました。

翻訳前ページへ


Pt.1-Iterative modeling with Lazarus (or Delphi)-LT3Ng-1.htm HOME - - - - - Lazarus Tutorials TOC - - - - - - Other 構成要素 for programmers
Delicious.Com Bookmark this on Delicious     StumbleUpon.Com Recommend to StumbleUpon

ふりをするing Predator/ Prey 全住民 Dynamics

And 類似の systems... part 1

This is the first of two web pages. 表面上は, they show you haw to make a good start on a 模擬実験/偽ること modeling the 生態学 of a small woodland, 住むd by grass, rabbits and foxes. A Predator/ Prey 全住民 Dynamics 模擬実験/偽ること.

Lots of good stuff here... but the page is still 存在 put together ーに関して/ーの点でs of editing for readability.

The 模擬実験/偽ること won't 勝利,勝つ any prizes... yet... for 存在 true- to- nature. But, having said that, the way the work already done has been done should mean that 延長するing the 模擬実験/偽ること to make it more life-like is 完全に feasible. It would be an 利益/興味ing challenge.

The 最初の/主要な value of the 構成要素 here will be, I think, as an example of how you could build a 模擬実験/偽ること of things like predator/ prey interaction. Things that proceed in "世代s". 細胞の automata, such as Conway's "Life". Traffic flows. River flooding. One thing you could 取り組む this way which 特に tempts me is a 模擬実験/偽ること of how age pyramids proceed... i.e. graphs showing the numbers of males and 女性(の)s in age-範囲 禁止(する)d, over a 一連の years. Many, many 可能性s!

Download the sim06- Predator/ Prey 全住民 Dynamics 模擬実験/偽ること source-code. If you just want the source-code, to adapt to your own 目的s (or to follow along, as you read this essay), it is 利用できる for download, in an 古記録 called, not very imaginatively, "sim06.zip". The .exe that arises from 編集 is 含むd in that .zip, and can be run without any その上の ado. It doesn't read from or 令状 to your hard 運動. You can run it 直接/まっすぐに from the .zip, without doing an 抽出する- and- save first. (収集するd for Windows, on a Win7 machine. Download 実験(する)d under Firefox.)

A few 半端物s and ends of 一般に useful programming tricks and techniques also arise, as ever.

Not "as ever" will be the level of 手渡す-持つ/拘留するing I 一般に 申し込む/申し出, 特に in tutorials of a more elementary nature. I 招待する you to try some of the lower "level" tutorials at my 場所/位置 until you are more Lazarus (or Delphi) "fluent", if you find this one goes too quickly.

Many general techniques are illustrated along the way. A 収集するd .exe is 利用できる so that you can play with the 使用/適用 without having to 収集する it. The Lazarus sourcecode is in the same zip とじ込み/提出する you can download. Both are there for you to play with... but I reserve all 権利s to any 使用/適用s derived from the sourcecode. It is there to show you programming techniques, not to be the basis of a 商業の 製品. 井戸/弁護士席... anyone else's 商業の 製品, anyway.

Where we are going

"We're going", to do what I said above. Let me 繰り返し言う elements...

While it won't be a 完全にする 模擬実験/偽ること of the rise and 落ちる of grass, rabbit and fox 全住民s in a woodland, it is going to illustrate some elements of how you might go about 令状ing such a program. I hope it will 解雇する/砲火/射撃 the imagination of a reader, start them on the road to 令状ing such a program... because it would be a fun, and worthwhile 事業/計画(する).

Why bother?

Working on ふりをするing natural 過程s, be they 生物学の, 化学製品 or physical, can bring on the 楽しみ to be had from better understanding the 過程s you are trying to model. If your model behaves at least plausibly, then you may be 正当化するd in taking some pride in having, perhaps, understood important 面s of the 過程.

A much simpler dynamic 全住民

It may help you to しっかり掴む what the woodland ecosystem model will try to ふりをする if first we look at something even simpler.

There was once a type of 私的な 搭乗 school which 一般に 受託するd pupils into "year 1", hoping they would stay for 5 years. But many would leave after year 3. As far as I 解任する, we had no births or predation.

The 経済的なs were やめる 厳しい... it was important to keep each year group "十分な". For the sake of our discussion, we'll 規定する that the ideal number in each year was 100.

予報するing the 未来 was helpful. Data about the past was 利用できる.

The number of people in "Year 2" for 2005 was the number of pupils 現在の in Year 1 of 2004, PLUS any pupils (usually not many) joining the school at the Year 2 level in 2005, MINUS the number of 2005 Year 1 pupils not returning for Year 2.

Etc, etc.

It WAS trivial to create a spreadsheet to 記録,記録的な/記録する the school's enrollment history....

With a little history, it was 平易な enough to calculate the 逮捕する influx/ outflow for each year group, at the end of each year. Then, with not much bother, the spreadsheet could be 延長するd into the hypothetical 未来, using best-guesses for the 逮捕する influxes/ outflows. With that "予測" to "sharpen the mind" of those responsible, 活動/戦闘 (or reaction) could 続いて起こる.

(Of course, for the extra work, extra "where to put your 成果/努力" (警察などへの)密告,告訴(状) would arise if instead of 単に using NET influx/ outflow, the system 跡をつけるd each 分かれて.... but that "frill" isn't necessary for our 進歩 に向かって a 模擬実験/偽ること of a woodland's 全住民 dynamics)

Think a little about how you would build such a spreadsheet, and I hope it will help you get ready for what comes next.

Into the 支持を得ようと努めるd...

In a very, VERY simple woodland, you might have Grass and Rabbits and Foxes. The rabbits eat the grass, the foxes eat the rabbits.

In the first year, you might have "lots" of grass, 10 rabbits, and 10 foxes. (I will call the first year "Y0" 今後. (Always best to count from 無 in computer stuff. You get used to it.))

Start like that, and in the second year, you would probably have no rabbits and no foxes.... everyone has 餓死するd. Start with "lots" of grass, 1000 rabbits, and 2 foxes (a dog and a vixen), and the 模擬実験/偽ること might run longer, be more 利益/興味ing.

Before we go any その上の, we're going to make a simplification which will help us. Instead of counting our grass 工場/植物s, rabbits, and foxes, we are, 今後, 単に going to 重さを計る them all. So... we might have 20,000 kg of grass, 1000 kg of rabbits, and 20 kg of foxes.

We are その上の going to assume that the woodland is so large, that we won't get 負かす/撃墜する to just 1 fox with no one to mate with, etc. Nor will we worry about the fact that as the rabbits become more 不十分な, they will become harder to find... although that is an example of an important thing to 追加する 早期に on, if you take the 演習 その上の.

We're not going to worry about the seasons. We'll have a "clock" that ticks, like the school, once each year.

We're not going to divide the grass, rabbit and fox 全住民s up into "young ones", "middle 老年の", and "old". Important... but not 含むd in our 計画(する). But! The 計画(する) has been done in a way that 許すs 追加するing that "frill" in, at a later date. ("young" foxes and rabbits don't 産む/飼育する. "old" rabbits run いっそう少なく 急速な/放蕩な, and get eaten more often. If grass becomes plentiful, the rabbit 全住民 doesn't すぐに rise at the 率 it will at a time when the first extra youngsters become sexually 円熟した... in a "proper", コンビナート/複合体 model (and the real world.)

So what ARE we going to worry about??!

Our model is 簡単に going to go '一連の会議、交渉/完成する and '一連の会議、交渉/完成する the に引き続いて 宙返り飛行....

REPEAT....
   Make a 公式文書,認める of how things stood, end of previous period.

   Based on the grass you have, 追加する more. (It grew)
   Based on number of rabbits, 減少(する) grass by a 確かな  量.

   Based on number of rabbits, 増加する number of rabbits. (They bred)
   Based in number of foxes, 減少(する) number of rabbits. (They got eaten)

   Based on number of rabbits, 増加する or 減少(する) number of foxes. (Their 増加する from 産む/飼育するing either did, or did not, 越える the deaths 予定 to 餓死.)

UNTIL YOU ARE BORED (or a 全住民 衝突,墜落s!)

Begin "stop 圧力(をかける)"

The above is very plausible, I hope. Sadly, 解釈する/通訳するd one way, there is something 不正に wrong with it!... which I discovered rather late in the day, having "finished" the first 行う/開催する/段階 of this program's 開発!

I am going to leave the "finished" first 行う/開催する/段階 as it was, and also the tutorial. DO 完全にする your reading of it. Keep you 注目する,もくろむ open; see if you 位置/汚点/見つけ出す the 欠陥. In a その後の tutorial, I am going to show you how all of my work, 関わりなく the design 欠陥, was not in vain... because I was using good program design and 開発 techniques.

From here, remember: You are reading an account, not edited to 訂正する the mistake, 欠陥d (not irredeemably!) of my first 試みる/企てる (for a few years, anyway!) at creating the 全住民 dynamics 模擬実験/偽ること.

End "stop 圧力(をかける)"

Just to make things a little more fun, we could easily 修正する the app, to let you "play God"... 井戸/弁護士席, nature 保存する 経営者/支配人, at least.... as the 宙返り飛行 goes '一連の会議、交渉/完成する and '一連の会議、交渉/完成する. You would be 許すd to "注入する" extra grass, or rabbits, or foxes. If we 限界 how MUCH you can 注入する, and make building the biggest 全住民s (最大限 total biomass) in a 直す/買収する,八百長をするd number of years, it becomes a little game, along the way.

But first, the basics. This is what sim06, "finished" looks like...

-

(陳謝s, if it still remains, for the 非,不,無-機能(する)/行事ing label "Click here..." at the upper left. The "click here to copy..." button 作品 罰金!)

The image above gives you an idea of where we are going. 結局, of course, you would "fancy things up" with graphical 陳列する,発揮するs. The 支配(する)/統制するs are laid out more or いっそう少なく in the order they were 追加するd to the form, so that you can see the history of the 開発. They are not, I 保証する you, how I would lay them out, さもなければ, of course.

近づく the beginning, the 覚え書き just scrolled each time you clicked "Go 今後 one year", with the same numbers over and over! I built up from something that had, and could 陳列する,発揮する, the status quo.

Of course, a bunch of initializing has to be done. This is in two 手続きs... InitOnce and InitToRestartSim. The first is things that have to happen when the app is first 開始する,打ち上げるd. The second is for things that have to be 始める,決める 支援する to starting values if, umm, you want to 再開する the sim. Both are called by the FormActivate event handler. (Do not try to put them in the FormActivate event handler... If you 含む what I did, you will be trying to 令状 to a 覚え書き before the 覚え書き 存在するs, and get an error, but not, maybe when you would 推定する/予想する to. (I got a SIGSEGV error when I tried to の近くに the app.)

For the sake of a few bytes, I wasn't going to 危険 data 洪水, so all the biomasses are 蓄える/店d in type LongWord variables. lwBM_grass, lw_BM_rabbit, lwBM_fox. (The plural forms of the two latter should be assumed... they 持つ/拘留する the "rabbit" biomass, which you might more intuitively think of as "the biomass of the rabbitS"... but I begrudge the extra character.)

New lines for the 覚え書き (meReportData) will be 追加するd at THE TOP, and 押し進める older lines 負かす/撃墜する the page. As I may want to 追加する lines from さまざまな places, I've 小包d up the small 量 of code 要求するd in the simple 手続き AddToTopOfMemo.

The font of the 覚え書き (and of the label with the column headings) was 始める,決める to a mono-spaced font, to keep the columns of 人物/姿/数字s 提携させるd vertically.

===

Remember, please... the point of this is NOT to produce the 最新の, greatest 全住民 dynamics simulator. Rather, it is to 論証する some programming 原則s. Not least of which is "Build a 枠組み that is 強健な. One which can 徐々に be developed, 高めるd, made to 会社にする/組み込む more 詳細(に述べる)s."

Working from such a 枠組み is useful in many, many programming 演習s.

You can't just start coding without careful thought about where you are going. But it 支払う/賃金s to start "small", and build 徐々に.

So... onward with building our 全住民 dynamics 模擬実験/偽ること.

The 初期の biomasses for the grass, rabbit, fox were 設立するd during InitToRestartSim

Now we have to arrange for our organisms to 料金d, and to die.

In the pseudo-code 輪郭(を描く), you may have noticed "Make a 公式文書,認める of how things stood, end of previous period."

This is a ありふれた necessity in programs of this sort. It arises thus....

早期に on, we are going to 改訂する the biomass of grass 現在の. And after that, we are going to do a 計算/見積り on the feeding success of the rabbits 含むing as a factor, the grass 利用できる to them. But we don't want to be using the NEW grass biomass. We want 接近 to what the grass biomass was at the end of last year.

Hence, we will create the に引き続いて....

lwBM_grassPrev, lwBM_rabbitPrev, lwBM_foxPrev:longword;

We will fill them, at the beginning of the 宙返り飛行, from lwBM_grass, lwBM_rabbit and lwBM_fox.

=== Building the app===

やめる 早期に, I had something which produced the に引き続いて. The numbers for the biomass of grass, rabbit and fox were not yet changing, but at least I had my form, and a way to 陳列する,発揮する the numbers. That was a big help when I (機の)カム to try to get the program to 生成する them!

-

At one point, at the heart of the code, I had...

手続き Tsim006f1.DoYear;
begin
  MakeNoteOfPreviousBiomasses;
  GrassAdd;
  GrassReduce;
  RabbitsAdd;
  RabbitsReduce;
  FoxesAdd;
  FoxesReduce;
  ReportBiomasses;
end;//DoYear

手続き Tsim006f1.GrassAdd;
begin

end;//GrassAdd

手続き Tsim006f1.GrassReduce;
begin

end;//GrassReduce

手続き Tsim006f1.RabbitsAdd;
begin

end;//RabbitsAdd

手続き Tsim006f1.RabbitsReduce;
begin

end;//RabbitsReduce

手続き Tsim006f1.FoxesAdd;
begin

end;//FoxesAdd

手続き Tsim006f1.FoxesReduce;
begin

end;//FoxesReduce

Pretty boring and dull, you might say! But I like "boring and dull", if it will do the 職業!

より小数の hidey 穴を開けるs for bugs and gremlins. Easier to "keep your place", as you build the app up.

Starting with an empty 骸骨/概要 also lets you take care of the sundry "trivial" tedious typos in the "mere 枠組み" before your mind needs all its gray 独房s for "the clever bits".

I won't go into all the 詳細(に述べる) of how every one of the "追加する"/"減ずる" 決まりきった仕事s were developed, but perhaps some 詳細(に述べる) in a few 事例/患者s will be of 利益/興味.

For this simple デモ, I thought I would just 増加する the 量 of grass each year by a simple 2%.

Ha! "Simple?"....

First I had...

lwBM_grass:=lwBM_grassPrev*1.02;

THAT wouldn't 飛行機で行く, because you can't use a real number (1.02) on in integer, if you want to 蓄える/店 the answer in an integer-type variable.

So then I tried....

lwBM_grass:=(lwBM_grassPrev*102) mod 100;

... feeling やめる smug as I typed that over my earlier 決定/判定勝ち(する) to use a really "big" data type (one 有能な of 蓄える/店ing very large numbers) for the grass biomass variable.

"Of course", I should have used "div", not "mod".

Once all of that had been sorted out, the grass biomass went up nicely, 2% per year, 構内/化合物d.

Oh. But then I noticed that the starting values weren't appearing in the 覚え書き. Trivial? Probably. But untidy. And untidy is BAD... and often comes 支援する to haunt you.

See why I like to break things 負かす/撃墜する to a "ridiculous" level, and take it one tiny step at a time? Imaging if I'd been trying to do something 複雑にするd at this point, AND 競う with the "trivial" 半端物s and ends?

The final form of even this simple 決まりきった仕事 illustrates another general 原則. The final form is...

lwBM_grass:=(lwBM_grassPrev*wGrassGR) mod 1000;

... where wGrassGR is an integer, 始める,決める to 1020 どこかよそで. "始める,決める"- for now. The day may come when I want to be able to 変化させる the growth 率. Suppose, for instance, we switch to making the "tick" of the model be a month? At that time, we will be able to build into the model the fact that the grass grows more quickly in the summer than in the winter, won't we?

Even if growth 率 remains a constant, it is always good to "抽出する" all the places where a constant is 始める,決める. Have them in one place. E.g. a 決まりきった仕事 called "SetConstants"! Given that there will be many "constants" in this program, and the fact that when I think of the "far horizon", I imagine I might 変化させる things like the grass growth 率, I think in this 事例/患者, for now (the 早期に 行う/開催する/段階 of the 旅行), I'll 始める,決める up a 決まりきった仕事, to be called during InitToRestartSim, called EstablishInitialRates. (If they don't change, it doesn't 事柄 what you might be inferring from "初期の". You can quickly search the code to discover that the final 率 is the same as the 初期の. And in any 事例/患者, there is the comment....

手続き Tsim006f1.EstablishInitialRates;
//Some of these 率s may be static, may remain 不変の
//  over the whole 死刑執行 of the program's code.
//ppk: Parts per thousand. I.e. 1020 is 同等(の) to 102 パーセント
begin
  wGrassGR:=1020;//ppk, grass growth per cycle.
end;//EstablishInitialRates;

And yes... I did change the 決まり文句/製法 in GrassAdd...

lwBM_grass:=(lwBM_grassPrev*wGrassGR) div 1000;

... to make finer 支配(する)/統制する of the 率 possible.

Once that was in place, which took a little while, the time taken was repaid when I (機の)カム to 令状 GrassReduce, because GrassGrow was a useful starting point... although I was annoyed because I'd 初めは called the 率 at which the grass was 追加するd "wGrassRG". I went 支援する and changed that to "wGrassRA" in the code and here in the tutorial, because it was a better 指名する. Using that would make all the "率" 指名するs follow a 論理(学)の pattern. (And then was unhappy again, because the "R" in the 指名する is easily 混乱させるd... some of the Rs mean 率, others meant "change"... so changed the "R"s for "change" to "D"s for "Delta", an old fashioned way to 指定する "a change 率"... so, finally (I hope), the 率 of 新規加入 (by growth, in the simple model (and probably the final)) to the grasses biomass is in wGrassAD, and the 率 at which the grass biomass 減ずるs (but rabbits eating it) is in wGrassRD.

最初, the 決まり文句/製法 was....

  lwBM_grass:=lwBM_grassPrev-(lwBM_rabbit*wGrassRD);

But then I "had" to "fancy it up" (and make 関係のある changes どこかよそで) to 許す for the "率" to be 始める,決める in 100ths of biomass 部隊s.

公式文書,認める, by the way, that grass is "追加するd" 単に by multiplying the old biomass by a constant, greater than 1.

On the other 手渡す, the grass biomass after the rabbits have grazed is calculated by subtracting a number for what the rabbits ate from the old biomass, that number 存在 calculated by multiplying the number of rabbits by their "eating 率" (wGrassRD). (The rabbit's eating 率... grass per rabbit... is just the other 味方する of the coin of the 率 the grass's biomass 減ずるs.)

====

Whew! Lots of 詳細(に述べる), recently... but there are lots of devils in programming, and you know where devils are 設立する.

You may be pleased to learn that the fortunes of the rabbits and foxes were, for our simple wants, (比較して) easily dealt with by 公正に/かなり 類似の code.

Ta da!... and example of how a good "general 枠組み" can save you work: good, and, even better, mean that you don't have to 取り組む each element of a puzzle as 完全に new and different. 完全にする with new and different ways to Go Wrong.

Sadly, there was a 飛行機で行く in the ointment... the 削減 of fox numbers had to be dealt with 異なって from how we dealt with the 削減 of rabbits or grass... for 推論する/理由s which you should be able to identify for yourself.

Happily, it was just a 事柄 of わずかに adapting the "GrassAdd" idea, and using a 率 of いっそう少なく than one, to create a useable 初期の "FoxReduce".

Done... sort of....

So! A basic 全住民 dynamics 模擬実験/偽ること was "finished", and "working".

I then began playing with the 率s, 推定する/予想するing different 結果s... and didn't get them. For instance, changing the 率 of fox 削減 didn't change the pattern of the changes in fox biomass. Which is really 半端物, in more ways than one.

As I said in the "stop 圧力(をかける)" earlier, I've LEFT this as it was... and, in the next tutorial, have written up how I went from the 欠陥d 模擬実験/偽ること to one that 作品 better! I hope you will read on!....

That's a lot done... even if bits were 欠陥d! Now we'll go on, 直す/買収する,八百長をする the 欠陥s, and ass some "fancy bits"... in lt3Ng-2.htm.

I hope you liked Part 1, whether you feel the need of Part 2 or not, and will recommend 経由で social マスコミ (see 最高の,を越す of page), etc. Feedback welcome other than "needs more graphics". (I know that!)





Search across all my 場所/位置s with the Google search...

Custom Search
            力/強力にするd by FreeFind
  場所/位置 search Web search
場所/位置 地図/計画する    What's New    Search This search 単に looks for the words you enter. It won't answer "Where can I download InpOut32?"
広告 from page's editor: Yes.. I do enjoy 収集するing these things for you. I hope they are helpful. However... this doesn't 支払う/賃金 my 法案s!!! Sheepdog ソフトウェア (tm) is supposed to help do that, so if you 設立する this stuff useful, (and you run a Windows or MS-DOS PC) please visit my freeware and shareware page, download something, and 循環させる it for me? Links on your page to this page would also be 高く評価する/(相場などが)上がるd!
Click here to visit editor's freeware, shareware page.

Link to Lazarus Tutorials main page
How to 接触する the editor of this page, Tom Boyd


Please consider 与える/捧げるing to the author of this 場所/位置... and if you don't want to do that, at least check out his introduction to the new micro-寄付s system Flattr.htm....



Valid HTML 4.01 Transitional Page 実験(する)d for 同意/服従 with INDUSTRY (not MS-only) 基準s, using the 解放する/自由な, 公然と accessible validator at validator.w3.org. Mostly passes. There were two "unknown せいにするs" in Google+ button code. Sigh.


If this page 原因(となる)s a script to run, why? Because of things like Google パネル盤s, and the code for the search button. Why do I について言及する scripts? Be sure you know all you need to about spyware.

....... P a g e . . . E n d s .....