void countInversions(int* A,int left,int right) { int mid; if(left < right) { mid = (left+right)/2; countInversions(A,left,mid); countInversions(A,mid+1,right); countSplit(A,left,mid,right); } return; }
//---------------------------------------------------------------------------------- void Simulation::measurePopulation(MeasurementsTable& table) { if (mErrorCode!=EcNoError) return; checkPopSize("void Simulation::measurePopulation()"); const unsigned int popSize = SoilMiteBase::getPopSize(); std::vector<double> bodySizeTable(popSize); std::vector<double> reservesTable(popSize); std::vector<double> chanceToDieTable(popSize); std::vector<double> foodIntakeTable(popSize); std::vector<double> allocationTable(popSize); std::vector<double> fractionBiomassPerOffspringInitialTable(popSize); std::vector<double> fractionBiomassPerOffspringTable(popSize); std::vector<bool> isAdultTable(popSize); const double splitValue = SoilMiteBase::getBodySizeAdult(); for (unsigned int i=0; i<popSize; ++i) { bodySizeTable[i] = mPop[i]->getBodySize(); reservesTable[i] = mPop[i]->getReserves(); foodIntakeTable[i] = mPop[i]->getFeedRate(); chanceToDieTable[i] = mPop[i]->getChanceToDie(); allocationTable[i] = mPop[i]->getAllocation(); fractionBiomassPerOffspringInitialTable[i] = mPop[i]->getFractionBiomassPerOffspringInitial(); fractionBiomassPerOffspringTable[i] = mPop[i]->getFractionBiomassPerOffspring(); isAdultTable[i] = ( bodySizeTable[i]>splitValue ? true : false); assert(allocationTable[i]>=0.0 && allocationTable[i]<=1.0); assert(fractionBiomassPerOffspringInitialTable[i]>=0.0 && fractionBiomassPerOffspringInitialTable[i]<=1.0); assert(fractionBiomassPerOffspringTable[i]>=0.0 && fractionBiomassPerOffspringTable[i]<=1.0); assert(mPop[i]->getChanceToDie()>=0.0 && mPop[i]->getChanceToDie()<=1.0); } double meanBodySize, stdDevBodySize; SafeMeanAndStdDev(bodySizeTable, meanBodySize, stdDevBodySize); table.mMeanBodySize.push_back(meanBodySize); table.mStdDevBodySize.push_back(stdDevBodySize); double meanReserves, stdDevReserves; SafeMeanAndStdDev(reservesTable, meanReserves, stdDevReserves); table.mMeanReserves.push_back(meanReserves); table.mStdDevReserves.push_back(stdDevReserves); double meanFoodIntake, stdDevFoodIntake; SafeMeanAndStdDev(foodIntakeTable, meanFoodIntake, stdDevFoodIntake); table.mMeanFoodIntake.push_back(meanFoodIntake); table.mStdDevFoodIntake.push_back(stdDevFoodIntake); double meanChanceToDie, stdDevChanceToDie; SafeMeanAndStdDev(chanceToDieTable, meanChanceToDie, stdDevChanceToDie); table.mMeanChanceToDie.push_back(meanChanceToDie); table.mStdDevChanceToDie.push_back(stdDevChanceToDie); //Plus int popSizeJuvenileInt, popSizeAdultInt; countSplit(splitValue, bodySizeTable, popSizeJuvenileInt, popSizeAdultInt); double popSizeJuvenile = static_cast<double>(popSizeJuvenileInt); double popSizeAdult = static_cast<double>(popSizeAdultInt); table.mPopSizeJuvenile.push_back(popSizeJuvenile); table.mPopSizeAdult.push_back(popSizeAdult); double meanBodySizeJuvenile, meanBodySizeAdult; SafeMeanSplit(splitValue,bodySizeTable, meanBodySizeJuvenile, meanBodySizeAdult); assert(meanBodySizeJuvenile<=splitValue); assert(meanBodySizeAdult>=splitValue || meanBodySizeAdult==0.0); table.mMeanBodySizeJuvenile.push_back(meanBodySizeJuvenile); table.mMeanBodySizeAdult.push_back(meanBodySizeAdult); double meanReservesJuvenile, meanReservesAdult; SafeMeanSplit(isAdultTable,reservesTable, meanReservesJuvenile, meanReservesAdult); table.mMeanReservesJuvenile.push_back(meanReservesJuvenile); table.mMeanReservesAdult.push_back(meanReservesAdult); double meanChanceToDieJuvenile, meanChanceToDieAdult; SafeMeanSplit(isAdultTable,chanceToDieTable, meanChanceToDieJuvenile, meanChanceToDieAdult); table.mMeanChanceToDieJuvenile.push_back(meanChanceToDieJuvenile); table.mMeanChanceToDieAdult.push_back(meanChanceToDieAdult); double meanFoodIntakeJuvenile, meanFoodIntakeAdult; SafeMeanSplit(isAdultTable,foodIntakeTable, meanFoodIntakeJuvenile, meanFoodIntakeAdult); table.mMeanFoodIntakeJuvenile.push_back(meanFoodIntakeJuvenile); table.mMeanFoodIntakeAdult.push_back(meanFoodIntakeAdult); //Plus plus double meanAllocationJuvenile, meanAllocationAdult; SafeMeanSplit(isAdultTable,allocationTable, meanAllocationJuvenile, meanAllocationAdult); table.mMeanAllocation.push_back(meanAllocationAdult); double meanFractionBiomassPerOffspringInitialJuvenile, meanFractionBiomassPerOffspringInitialAdult; SafeMeanSplit(isAdultTable,fractionBiomassPerOffspringInitialTable, meanFractionBiomassPerOffspringInitialJuvenile, meanFractionBiomassPerOffspringInitialAdult); table.mMeanFractionBiomassPerOffspringInitial.push_back(meanFractionBiomassPerOffspringInitialAdult); double meanFractionBiomassPerOffspringJuvenile, meanFractionBiomassPerOffspringAdult; SafeMeanSplit(isAdultTable,fractionBiomassPerOffspringTable, meanFractionBiomassPerOffspringJuvenile, meanFractionBiomassPerOffspringAdult); table.mMeanFractionBiomassPerOffspring.push_back(meanFractionBiomassPerOffspringAdult); }