tag:blogger.com,1999:blog-3497857781721412138.post7194242564762747021..comments2018-01-11T10:06:08.272+01:00Comments on Self-Organizing Networked Systems: Sixth IEEE Xtreme Programming Contest: Bunnies in the ForestWilfried Elmenreichhttps://plus.google.com/102872922312027842434noreply@blogger.comBlogger5125tag:blogger.com,1999:blog-3497857781721412138.post-80134517811498088372012-11-23T18:50:43.385+01:002012-11-23T18:50:43.385+01:00Dear Mr. Elmenreich,
I tested your statement as fo...Dear Mr. Elmenreich,<br />I tested your statement as follow :<br /> Console.WriteLine("Rounding error test: 1680*0.7=1176=[{0}?]", (int)(1680 * 0.7));<br />and it did output the right value :<br /> > Rounding error test: 1680*0.7=1176=[1176?]<br /><br />I understand it could be a rounding problem, but not with the given case of 1680*0.7.<br /><br /><br />Francis Gagnonhttps://www.blogger.com/profile/02272351872445228879noreply@blogger.comtag:blogger.com,1999:blog-3497857781721412138.post-29290745257094012472012-10-25T01:31:21.328+02:002012-10-25T01:31:21.328+02:00"In every 30 days , 25% dies off due to flu.&..."In every 30 days , 25% dies off due to flu." makes sense to do it your way. If I change my program by adding a condition for the flu to appear only every second iteration it creates almost the same values as your program. The remaining differences are because of rounding errors which are different for different programming languages.<br />e.g. in Python, int(1680*0.7) evaluates to 1176<br />in C/C++, there is a rounding error which makes (int)(1680*0.7) evaluate to 1175 Wilfried Elmenreichhttps://www.blogger.com/profile/13527662530751362421noreply@blogger.comtag:blogger.com,1999:blog-3497857781721412138.post-22573171500438330672012-10-24T13:10:47.631+02:002012-10-24T13:10:47.631+02:00Dear Prof.Wilfried Elmenreich let me thank you for...Dear Prof.Wilfried Elmenreich let me thank you for your reply and your effort .i totaly agree with your point of view ,i misunderstood the adult meaning .but i think i could use "if (i % 2 == 0)" to calculate the bunnies dies due to flu because the case did not mention that they die every 15 day so my code will be as follows :<br /> int CalcBunnies(int InitialBunnies)<br /> {<br /> int _intMatureBunnies30 = InitialBunnies;<br /> int _intOldAdultBunnies15 = 0;<br /> int _intNewAdult0 = 0;<br /> int _intNewAdultTemp = 0;<br /> int _intTotal = 0;<br /> for (int i = 1; i <= 24; i++)//24 of 15days<br /> {<br /><br /> _intNewAdultTemp = _intNewAdult0;<br /><br /> _intNewAdult0 = (int)((_intMatureBunnies30) * 0.9);<br /><br /> _intMatureBunnies30 += (int)(_intOldAdultBunnies15 * .7);//Old Become Mature<br /><br /> _intOldAdultBunnies15 = _intNewAdultTemp;<br /><br /> if (i % 2 == 0)//after 30 day<br /> {<br /> //====25 % of bunnies die=================<br /> _intNewAdult0 = (int)(_intNewAdult0 * .75);<br /> _intOldAdultBunnies15 = (int)(_intOldAdultBunnies15 * .75);<br /> _intMatureBunnies30 = (int)(_intMatureBunnies30 * .75);<br /> }<br /> _intTotal = _intNewAdult0 + _intOldAdultBunnies15 + _intMatureBunnies30;<br /><br /> }<br /><br /> return _intTotal;<br /><br /> }<br />Mahmoud abdelsalamhttps://www.blogger.com/profile/12020702711349449687noreply@blogger.comtag:blogger.com,1999:blog-3497857781721412138.post-60320056585530830612012-10-23T20:11:25.661+02:002012-10-23T20:11:25.661+02:00Dear Mahmoud, your approach is similar, but I thin...Dear Mahmoud, your approach is similar, but I think your concept of "adult" is wrong. I would connect the concept of "adult" with "mature". In your simulation you have the newborn already doubling within 15 days, which leads to very high numbers of your rabbit population even for small starting values (444 bunnies become 154936 after one year). I doubt also your approach with "if (i % 2 == 0)" - once new rabbits are born every 15 days you will also have maturing events every 15 days instead of 30.Wilfried Elmenreichhttps://www.blogger.com/profile/13527662530751362421noreply@blogger.comtag:blogger.com,1999:blog-3497857781721412138.post-19502321921904654012012-10-23T14:24:50.106+02:002012-10-23T14:24:50.106+02:00Hello prof. Wilfried Elmenreich :
I wrote a code ...Hello prof. Wilfried Elmenreich : <br />I wrote a code in c# that tries to solve the Forest bunnies case, when I read your blog i discovered that my code is 80% similar to your code so it will be so nice if if you give me your opinion ,because this will help me a lot to know how much i understood the requirement and how good i implemented it : my code is written by c# as follows :<br /><br /><br /> int CalcBunnies(int InitialBunnies)<br /> {<br /> int _intMatureBunnies = 0;<br /> int _intOldAdultBunnies = InitialBunnies;//because they are adult this means that 15 day left <br /> int _intNewAdult = 0;<br /> int _intNewAdultTemp = 0;<br /> int _intTotal = 0;<br /> for (int i = 1; i <= 24; i++)//24 of 15days<br /> {<br /><br /> if (i % 2 == 0)//after 30 day<br /> {<br /> _intMatureBunnies += (int)(_intOldAdultBunnies * .7);//Old Become Mature<br /> _intNewAdultTemp = _intNewAdult;<br /> //calculate New Adult ,i added OldBunnies to the previous newAdults because Oldbunnies and NewAdults<br /> //are still being adults so we will assume that 10% of their childs will day<br /> _intNewAdult = (int)((_intOldAdultBunnies + _intNewAdult) * 0.9);<br /> //_intNewAdult = (int)(_intNewAdult * 0.9);//calculate New Adults<br /> _intOldAdultBunnies = _intNewAdultTemp;//New Become Old<br /><br /><br /> //====25 % of bunnies die=================<br /> _intNewAdult = (int)(_intNewAdult * .75);<br /> _intOldAdultBunnies = (int)(_intOldAdultBunnies * .75);<br /> _intMatureBunnies = (int)(_intMatureBunnies * .75);<br /><br /><br /> _intTotal = _intNewAdult + _intOldAdultBunnies + _intMatureBunnies;<br /><br /> }<br /> else//after 15 day<br /> {<br /><br /> //because old adults and new adults are still adults we will assume that both of them will be duplicated<br /> _intNewAdult = (int)((_intOldAdultBunnies + _intNewAdult) * 0.9);<br /><br /> }<br /><br /> }<br /><br /> return _intTotal;<br /><br /> }<br /><br /><br />Thanks alotMahmoud abdelsalamhttps://www.blogger.com/profile/12020702711349449687noreply@blogger.com