- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在构建 hive 模拟,并使用名为 workerBee 的二维数组。它有以下 6 个字段:beeId、Age、Type(egg = 1、larva = 2、pupa = 3、worker = 4、drone = 5)、PollenCollection、Eaten、Alive
模型简介:蜂王每天产卵(10 到 50 个卵),并将它们添加到 hive 中。每天,有关蜜蜂的数据都会更新(它们的年龄和类型)。
对于过去的每一天,我都会打印 hive 状态,其中打印有关蜜蜂数量、出生、死亡等的信息。在模拟过程中的某些日子(开始时,例如第 6 至 10 天),报告的幼虫数量为 1 天约 800 至 900 只。以下是处理打印和计数的代码:
public static int layDailyEggs() {
Random randomEggs = new Random();
final int MAX_EGGS = 50;
final int MIN_EGGS = 10;
int x = randomEggs.nextInt((MAX_EGGS - MIN_EGGS) + 1) + MIN_EGGS;
eggsLaid = x;//eggsLaid as a global variable to be used in printBeehiveStatus
return x;//To pass as argument to addEggToHive
}
public static void addEggToHive(int eggsLaid) {
//Update the workerBee array with available slots
//Traverse the 2D array and while beeId != 0, add eggs and update
for (int i = 0; i < workerBee.length; i++) {
if (workerBee[i][0] == 0 && eggsLaid > 0) {
//Available space
workerBee[i][0] = i;//Update beeID
workerBee[i][1] = 1;//Update age
workerBee[i][2] = 1;//Update Type
eggsLaid--;
}
}
}
public static void countTypesOfBees() {
//Initialize for each day
totalEggsLaid = 0;
numberOfBirths = 0;
numberOfLarva = 0;
numberOfPupa = 0;
numberOfWorkerBees = 0;
numberOfDrones = 0;
//To call upon updating type of each bee
for (int i = 0; i < workerBee.length; i++) {
if(workerBee[i][2] == 1) {
totalEggsLaid++;
}else if(workerBee[i][2] == 2) {
numberOfLarva++;
numberOfBirths++;
}else if(workerBee[i][2] == 3) {
numberOfPupa++;
numberOfBirths++;
}else if(workerBee[i][2] == 4) {
numberOfWorkerBees++;
numberOfBirths++;
}else if(workerBee[i][2] == 5) {
numberOfDrones++;
numberOfBirths++;
}
}
}
//Method called once daily
public static void metamorphose() {
numberOfDeaths = 0;
Random random = new Random();
for (int i = 0; i < workerBee.length; i++) {
//Updating the type of bee based on age of Bee
if(workerBee[i][1] == 4) {
workerBee[i][2] = 2;
}else if (workerBee[i][1] == 10) {
workerBee[i][2] = 3;
}else if(workerBee[i][1] == 20){
//Probability for a drone to emerge is 10%(As per area under curve, should be less than or equal to 10%)
double probability = random.nextDouble();
if (probability <= 0.1) {
workerBee[i][2] = 5;//Drone Bee
}else{
workerBee[i][2] = 4;//Worker Bee
}
}
if (workerBee[i][1] == 35 || workerBee[i][1] == 56) {
//Call a funeral
funeral(i);
numberOfDeaths++;
}
}
countTypesOfBees();
}
//To be called at the end of the day
public static void printBeehiveStatus() {
System.out.print("Queen laid " + eggsLaid + " eggs!" +
"\nBeehive status\nEgg Count: "+ totalEggsLaid + "\nLarva Count: " + numberOfLarva + "\nPupa Count: " + numberOfPupa +
"\nWorker Count: "+ numberOfWorkerBees + "\nDrone Count: " + numberOfDrones +
"\nDeath Count: " + numberOfDeaths + "\nBirth Count: "+ numberOfBirths +
"\nHoney Stock: " + honeyStock +"\n");
printFlowerGarden();
}
workerBee数组的字段索引按照上面指定的顺序排列。每天执行的顺序如下(注意不是完整的)
addEggToHive(layDailyEggs());
incrementAge();
metamorphose();
printBeehiveStatus();
屏幕截图[1]:/image/qTeuo.png
截图[2]:/image/eMsHq.png
注意
卵在4天大时孵化成幼虫如果您认为还有其他可能导致问题的原因,请告诉我,我将上传该部分代码。
最佳答案
找到了解决方案。实际上,incrementAge() 方法应该每天将 hive 中所有蜜蜂的年龄增加 1。然而,我只是简单地增加数组中的所有年龄,而不检查该特定行是否是实际的蜜蜂,因为我已将未使用的行初始化为0
关于java - hive 模拟 : A counter of a type of bee returns unusually high numbers,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59234595/
哪个更快? Counter()+=Counter 或 Counter.update(Counter)? 为什么一个比另一个更快? 我尝试了一些简单的分析,但我认为这不足以最终证明 Counter+=C
这个问题在这里已经有了答案: ++someVariable vs. someVariable++ in JavaScript (7 个答案) 关闭 7 年前。 var counter = 0; va
下面是我正在使用的代码。如果我按 addQuanity m_label 设置显示一个而不是两个。如果我再次按 addWuantity,m_label 显示 2。按 minusQuantity 将 m_
这个问题已经有答案了: Does Java evaluate remaining conditions after boolean result is known? (7 个回答) 已关闭 6 年前。
因此,当我将计数器(from collections import Counter)打印到一个文件时,我总是得到它的文字 Counter ({'Foo': 12}) 有没有办法让计数器不那么字面地写出
我正在使用 CSS2.1 计数器将数字应用于棋盘上的人,以实现棋盘游戏,其棋盘图使用 HTML 和 CSS,方法如下: .ply {counter-increment:main;} .move:be
这个问题在这里已经有了答案: 关闭 11 年前。 Possible Duplicate: Is there a performance difference between i++ and ++i
我在尝试编译 Arduino 草图时遇到此错误。我看不出它认为我试图在没有参数的情况下调用 Counter::Counter 的地方。这是怎么回事? sketch/periodic_effect.cp
调用Get-Counter时使用-ComputerName参数和使用-Counter参数中的路径有区别吗? Get-Counter -Counter "\Memory\Available MB
姓名 Counter在 collections 中都定义了(作为一个类(class))和在 typing (作为通用类型名称)。不幸的是,它们略有不同。处理这个问题的推荐方法是什么? 相同点和不同点:
此代码不会给出任何失败,但如果您使用 counter++,则第一次迭代会失败。 parameters="one two three" counter=0 for option in $param
powershell 中的 get-counter/export-counter cmdlet 似乎以美国格式返回日期,这在这种情况下是相当不受欢迎的。我浏览了两个 get-help -full 页面
我有 2 个计数器(来自集合的计数器),我想将一个附加到另一个,而第一个计数器的重叠键将被忽略。喜欢 dic.update (python 词典更新) 例如: from collections imp
我想在我的项目中为 Provider ( ChangeNotifierProvider ) 创建一个单元测试,我的单元测试、小部件测试和集成测试成功通过 ✔️,所以现在我尝试(努力尝试🥵...)创建
我知道以下代码的复杂度为 O(log(n)): while (n>1) { counter++; n/=2; } 我知道在这里,n 在每次迭代中被分成两半,这意味着如果 n 是 100
Counter.getName() 方法与 Counter.getDisplayName() 方法有什么区别。我没有从文档中看到太多信息 http://hadoop.apache.org/docs/r
我有一个 python 文件,用于在 Hadoop(版本 2.6.0)上使用 mrjob 来计算二元语法,但我没有得到我希望的输出,而且我在破译终端中的输出时遇到了问题我哪里出错了。 我的代码: re
我看到带有错误消息的事件 ID 2001: It has taken too long to refresh the W3SVC counters , the stale counters are b
我对 React 完全陌生,我正在 YouTube 上学习教程(使用 MOSH 编程),但我遇到了这个错误,在找到类似问题后无法解决。 index.js import React from 'reac
我正在运行一个 hadoop 作业(来自 oozie),它有几个计数器和多输出。 我收到如下错误:org.apache.hadoop.mapreduce.counters.LimitExceededE
我是一名优秀的程序员,十分优秀!