Beispiel #1
0
inline void Restaurant::FillInPredictivesNonGraphical(
    const std::vector<double>& parent_predictives,
    int type,
    int depth,
    const HPYParameter& hpy_parameter,
    std::vector<double>& predictives) const {
  for (size_t i = 0; i < parent_predictives.size(); ++i) {
    predictives[i] = parent_predictives[i];
  }
  for (auto floor_it = floor2c_t_.begin(); floor_it != floor2c_t_.end(); ++floor_it) {
    auto floor_id = (*floor_it).first;
    auto& c_t = (*floor_it).second;
    tmp_c_[floor_id] = c_t.first;
    predictives[floor_id] *=
        (hpy_parameter.concentration(depth, floor_id)
         + hpy_parameter.discount(depth, floor_id) * c_t.second)
        / (c_t.first + hpy_parameter.concentration(depth, floor_id));
  }
  auto type_it = type2internal_.find(type);
  if (type_it == type2internal_.end()) return;

  auto& sections = (*type_it).second.sections_;
  auto section_it = sections.begin();
  for (; section_it != sections.end(); ++section_it) {
    auto floor_id = (*section_it).first;
    auto& section = (*section_it).second;
    auto cw = section.customers;
    auto tw = section.tables;
    predictives[floor_id] +=
        (cw - hpy_parameter.discount(depth, floor_id) * tw)
        / (tmp_c_[floor_id] + hpy_parameter.concentration(depth, floor_id));
  }
}
Beispiel #2
0
void FloorSampler::TakeInSectionLL(
    const boost::container::flat_map<topic_t, std::pair<int, int> >& floor2c_t,
    int add_customers,
    int add_tables,
    int current_k,
    int depth) {
  int s = pdf_.size();
  auto it = floor2c_t.begin();
  int j = 0;
  if (!include_zero_) {
    j = 1;
    if (it != floor2c_t.end() && (*it).first == 0) ++it;
  }
  for (; j < s; ++j) {
    if (it == floor2c_t.end() || (*it).first > j) {
      assert(j != current_k); // current restaurant should never be empty
      pdf_[j] += arrangement_part_[depth]->log_p(add_customers, add_tables, 0, 0);
    } else {
      assert((*it).first == j);
      int c = (*it).second.first;
      int t = (*it).second.second;
      if (j == current_k) {
        c -= add_customers;
        t -= add_tables;
      }
      pdf_[j] += arrangement_part_[depth]->log_p(add_customers, add_tables, c, t);
      ++it;
    }
  }
}
Beispiel #3
0
boost::optional<reaction_task_t> find_automatic_reaction_task(const settler_ai_t &ai) {
    if (automatic_reactions.empty()) return boost::optional<reaction_task_t>{};

    boost::optional<reaction_task_t> result;

    // Iterate through available reactions
    for (auto outerit=automatic_reactions.begin(); outerit != automatic_reactions.end(); ++outerit) {
        // Is the workshop busy?
        auto busy_finder = workshop_claimed.find(outerit->first);
        if (busy_finder == workshop_claimed.end()) {
            // Iterate available automatic reactions
            for (const std::string &reaction_name : outerit->second) {
                auto reaction = reaction_defs.find(reaction_name);
                if (reaction != reaction_defs.end()) {
                    // Is the settler allowed to do this?
                    int target_category = -1;
                    if (reaction->second.skill == "Carpentry") {
                        target_category = JOB_CARPENTRY;
                    } else if (reaction->second.skill == "Masonry") {
                        target_category = JOB_MASONRY;
                    }
                    if (target_category == -1 || ai.permitted_work[target_category]) {
                        // Are the inputs available?
                        bool available = true;
                        std::vector<std::pair<std::size_t,bool>> components;
                        for (auto &input : reaction->second.inputs) {
                            const int n_available = available_items_by_reaction_input(input);
                            if (n_available < input.quantity) {
                                available = false;
                            } else {
                                // Claim an item and push its # to the list
                                std::size_t item_id = claim_item_by_reaction_input(input);
                                components.push_back(std::make_pair(item_id,false));
                            }
                        }

                        if (available) {
                            // Components are available, build job and return it
                            result = reaction_task_t{outerit->first, reaction->second.name, reaction->second.tag, components};
                            workshop_claimed.insert(outerit->first);
                            return result;
                        } else {
                            for (auto comp : components) {
                                unclaim_by_id(comp.first);
                            }
                        }
                    }
                }
            }
        }
    }

    return result;
}
Beispiel #4
0
 std::vector<HeroProfile*> heroProfiles()
 {
     std::vector<HeroProfile*> profiles;
     profiles.reserve(globalHeroTable.size());
     
     transform(globalHeroTable.begin(), globalHeroTable.end(), back_inserter(profiles),
               [](boost::container::flat_map<int, HeroProfile*>::const_reference value){ return value.second; });
     
     std::sort(profiles.begin(), profiles.end(), [](HeroProfile* first, HeroProfile* second){
         return (first->tableId-9999.5)*(second->tableId-9999.5) < 0 ? first->tableId >= 10000 : first->tableId < second->tableId; });
     
     return profiles;
 }
Beispiel #5
0
void Restaurant::FillInPredictives(const std::vector<double>& parent_predictives,
                                   int type,
                                   const LambdaManagerInterface& lmanager,
                                   int depth,
                                   const HPYParameter& hpy_parameter,
                                   std::vector<double>& predictives) const {
  auto floor_it = floor2c_t_.begin();
  auto type_it = type2internal_.find(type);
  predictives[0] = parent_predictives[0];
  if (floor2c_t_.empty()) {
    for (size_t i = 1; i < predictives.size(); ++i) {
      double lambda = lmanager.lambda(i, depth);
      predictives[i] = lambda * parent_predictives[i] + (1 - lambda) * predictives[0];
    }
    return;
  }
  if ((*floor_it).first == 0) {
    auto& c_t = (*floor_it).second;
    predictives[0] *= (hpy_parameter.concentration(depth, 0) + hpy_parameter.discount(depth, 0) * c_t.second) / (c_t.first + hpy_parameter.concentration(depth, 0));
    if (type_it != type2internal_.end()) {
      auto& sections = (*type_it).second.sections_;
      if (!sections.empty()) {
        auto section_begin = sections.begin();
        if ((*section_begin).first == 0) {
          int cw = (*section_begin).second.customers;
          int tw = (*section_begin).second.tables;
          predictives[0] += (cw - hpy_parameter.discount(depth, 0) * tw) / (c_t.first + hpy_parameter.concentration(depth, 0));
        }
      }
    }
  }
  for (size_t i = 1; i < predictives.size(); ++i) {
    double lambda = lmanager.lambda(i, depth);
    predictives[i] = lambda * parent_predictives[i] + (1 - lambda) * predictives[0];
  }
  if ((*floor_it).first == 0) {
    ++floor_it;
  }
  for (; floor_it != floor2c_t_.end(); ++floor_it) {
    auto floor_id = (*floor_it).first;
    auto& c_t = (*floor_it).second;
    tmp_c_[floor_id] = c_t.first;
    predictives[floor_id] *=
        (hpy_parameter.concentration(depth, floor_id)
         + hpy_parameter.discount(depth, floor_id) * c_t.second)
        / (c_t.first + hpy_parameter.concentration(depth, floor_id));
  }
  if (type_it == type2internal_.end()) return;
  auto& sections = (*type_it).second.sections_;

  auto section_it = sections.begin();
  if (section_it != sections.end() && (*section_it).first == 0) {
    ++section_it;
  }
  for (; section_it != sections.end(); ++section_it) {
    auto floor_id = (*section_it).first;
    auto& section = (*section_it).second;
    int cw = section.customers;
    int tw = section.tables;
    predictives[floor_id] +=
        (cw - hpy_parameter.discount(depth, floor_id) * tw)
        / (tmp_c_[floor_id] + hpy_parameter.concentration(depth, floor_id));
  }
}