public bool Activate(List <CompanySubType> errands, List <Constraint> constraints, Dictionary <CompanySubType, List <Appointment> > appointmentDataBase, Dictionary <Tuple <string, string>, int> deltaTimeMatrix) { constraints = constraints.OrderBy(c => c.Start).ToList(); // the number of options in every row var numberOfErrandCombinations = (int)Math.Pow(2, errands.Count); _routeMatrix = new PathHandler[HOUR_MAX - HOUR_MIN + 1, numberOfErrandCombinations]; _routeMatrix[HOUR_MAX - HOUR_MIN, 0] = new PathHandler(new Path { Constraints = constraints }); var finalOptionList = new List <PathHandler>(); // for every hour in day, counting from the end for (var currHour = HOUR_MAX - 1; currHour >= HOUR_MIN; currHour--) { // set all empty path _routeMatrix[currHour - HOUR_MIN, 0] = new PathHandler(new Path { Constraints = constraints }); // for every errand combination in the row for (var i = 1; i < numberOfErrandCombinations; i++) { // check raised bits var bits = new bool[errands.Count]; var tmp = i; for (var bit = 0; bit < errands.Count; bit++) { bits[bit] = tmp % 2 == 1; tmp /= 2; } var optionList = new List <PathHandler>(); for (var bit = 0; bit < bits.Length; bit++) { if (bits[bit] && appointmentDataBase.ContainsKey(errands[bit])) { for (int j = currHour; j < HOUR_MAX; j++) { if (_routeMatrix[j - HOUR_MIN + 1, i - (int)Math.Pow(2, bit)] != null) { optionList.AddRange(FindAppointmentsBetweenTimes(currHour, currHour + 1, _routeMatrix[j - HOUR_MIN + 1, i - (int)Math.Pow(2, bit)], appointmentDataBase[errands[bit]], deltaTimeMatrix)); } if (i - (int)Math.Pow(2, bit) == 0) { break; } } // 2 path combiner ?????? TODO: } } //pick best for the slot from option list if (optionList.Count != 0) { PathHandler best = optionList[0]; foreach (var option in optionList) { if (best.GetOverallDeadTime(deltaTimeMatrix) > option.GetOverallDeadTime(deltaTimeMatrix)) { best = option; } } _routeMatrix[currHour - HOUR_MIN, i] = best; } else { _routeMatrix[currHour - HOUR_MIN, i] = null; } if (i == numberOfErrandCombinations - 1) { finalOptionList.AddRange(optionList); } } } if (finalOptionList.Count < 3 && numberOfErrandCombinations != 2) { for (var i = 0; i < HOUR_MAX - HOUR_MIN; i++) { for (var j = 1; j < numberOfErrandCombinations; j *= 2) { if (_routeMatrix[i, numberOfErrandCombinations - j - 1] != null) { finalOptionList.Add(_routeMatrix[i, numberOfErrandCombinations - j - 1]); } } } } ExtractResultFromPathHandlerList(FindTheBestPath(finalOptionList)); return(Results.Count != 0); }