void Algorithm<T>::CalculateFitnessProbability() { m_fitnessProbability.clear(); CalculateTotal(); for (int i = 0; i < m_chromosomes.size(); i++) { m_fitnessProbability.push_back(m_fitnessValue[i] / m_total); } }
bool GetEncumbranceFunction::execute() { enum Encumbrance { kCurrent = 0, kMax = 1, kBase = 2 }; double encumbrance = -999999.0; unsigned long record_type; unsigned char* reference; unsigned char* temp; unsigned char* base; if (GetTargetData(machine, &reference, &temp, &record_type, &base) && (record_type == NPC || record_type == CREATURE)) { MACPRecord const* const macp = reinterpret_cast<MACPRecord*>(GetAttachPointer( machine, reference, MACHNODE)); long encumbrance_type; long round_result; machine.pop(encumbrance_type); machine.pop(round_result); if (macp != NULL) { if (encumbrance_type == kMax) { encumbrance = macp->weight_limit.base; } else if (encumbrance_type == kBase || encumbrance_type == kCurrent) { encumbrance = macp->weight_limit.current; if (macp->num_active_effects > 0) { // first effect is a "dummy" node MACPRecord::ActiveEffect* current_effect = macp->active_effects->next; for (int i = 0; i < macp->num_active_effects; i++) { // It's not sufficient to simply read the current // magnitude of the effect (ActiveEffect.magnitude) for // two reasons: First, it does not take into account // any Magicka Resistance active when the effect was // applied to the actor (burden is affected by MR, // feather is not). Second, when a spell that is // already affecting an entity is cast again on that // entity, the game applies the effects of both copies // for one frame, doubling the effect on encumbrance // for that frame. if (current_effect->effect_type == kFeather || current_effect->effect_type == kBurden) { if (encumbrance_type == kBase) { encumbrance += CalculateTotal(reference); } else { encumbrance += CalculateCorrection(reference); } break; } current_effect = current_effect->next; } } } // The smallest item weight is 0.01, so round to nearest 0.01. if (round_result != 0) encumbrance = round(encumbrance * 100.0) / 100.0; } } float value = static_cast<float>(encumbrance); return (machine.push(value)); }