// Private functions double Anneal::AcceptRatioNow(int sequence_size) const { std::uniform_real_distribution<double> distribution(0.0, 1.0); int accept_state_num = 0; int total_state_num = 0; std::vector<Path> state_sequence(sequence_size); std::vector<double> state_value(sequence_size); for (int i = 0; i < sequence_size; i++) { state_sequence[i] = std::move(GenerateRandomPath()); state_value[i] = Evaluate(state_sequence[i]); } for (int i = 0; i < sequence_size; i++) { for (int j = 0; j < sequence_size; j++) { total_state_num++; if (state_value[j] <= state_value[i] || distribution(generator_) < TransitionProbability(state_value[i], state_value[j])) accept_state_num++; } } return static_cast<double>(accept_state_num) / static_cast<double>(total_state_num); }
void Enemy::AI() { if( generated == false ) { GenerateRandomPath(); generated = true; } attacking = false; switch( myAI ) { case PATHWALK: // --- PATHWALK --- PathWalk(); break; case FOLLOW: Follow(); break; case COMBAT: Combat(); break; case RANDOM_PATHWALK: break; case RETURN_TO_PATHWALK: ReturnToPathWalk(); break; default: break; } myWeapon->Logic(attacking,heroPosition); }
Anneal::Path Anneal::FindPath(std::ostream &os) { std::uniform_real_distribution<double> distribution(0.0, 1.0); InitializeTemperature(); temperature_drop_times_ = 0; path_now_ = GenerateRandomPath(); value_now_ = Evaluate(path_now_); while (!ShouldTerminate()) { // a new t_ iterations_this_temperature_ = 0; while (!BalanceReached()) { iterations_this_temperature_++; Path neighbor = GenerateRandomNeighbor(path_now_); double new_value = Evaluate(neighbor); if (new_value <= value_now_ || distribution(generator_) < TransitionProbability(value_now_, new_value)) { path_now_ = neighbor; value_now_ = new_value; } } // balance reached at this temperature // print the path now PrintPath(std::cout); PrintPath(os); DropTemperature(); // counter updated inside } return path_now_; }
DataBaseDirectory::DataBaseDirectory(bool create) : Xeth::DataBaseDirectory(GenerateRandomPath().c_str(), create) {}