bool RequirementGroup::recurseForUnitTime(int &latestTime, std::vector<Requirement>::iterator currentRequirement, int currentStartTime, int currentEndTime, std::set<Unit> ¤tUnits) { // If we have reached the end we have found a time, save it and return if(currentRequirement == mUnitRequirements.end()) { latestTime = currentStartTime; return true; } assert(currentRequirement->unitRequirement()); // get a selection of free times for this requirement const std::map<int, int> &unitTimes = currentRequirement->earliestUnitTime(currentStartTime, currentEndTime, currentUnits); // For each one for(std::map<int, int>::const_iterator it = unitTimes.begin(); it != unitTimes.end(); ++it) { currentUnits.insert(currentRequirement->getUnit()); int newEndTime = it->second; if(newEndTime != Requirement::maxTime) newEndTime += it->first; // go to the next requirement with these times to see if it is suitable for the rest too if(recurseForUnitTime(latestTime, ++(std::vector<Requirement>::iterator(currentRequirement)), it->first, newEndTime, currentUnits)) return true; currentUnits.erase(currentRequirement->getUnit()); } return false; }