private void RecursiveSolveCombinationsNegative(JournalEntryLineModel targetLine, double currentSum, List <JournalEntryLineModel> included, List <JournalEntryLineModel> notIncluded, int startIndex, int milliseconds) { var roundTotalsAccuracy = DiManager.Company.GetCompanyService().GetAdminInfo().TotalsAccuracy; for (int index = startIndex; index < notIncluded.Count; index++) { //if (stopwatch.ElapsedMilliseconds > 4000) //{ // return; //} double goal = targetLine.Debit == 0 ? targetLine.Credit : targetLine.Debit; JournalEntryLineModel nextLine = notIncluded[index]; double nextAmount = nextLine.Debit == 0 ? nextLine.Credit : nextLine.Debit; double amountToCompare = Math.Round(currentSum + nextAmount, roundTotalsAccuracy); if (amountToCompare + goal == 0) { List <JournalEntryLineModel> newResult = new List <JournalEntryLineModel>(included); newResult.Add(nextLine); _sourceLines = newResult; } else if (Math.Abs(amountToCompare) < Math.Abs(goal)) { List <JournalEntryLineModel> nextIncuded = new List <JournalEntryLineModel>(included); nextIncuded.Add(nextLine); List <JournalEntryLineModel> nextNonIncluded = new List <JournalEntryLineModel>(notIncluded); nextNonIncluded.Remove(nextLine); RecursiveSolveCombinationsNegative(targetLine, amountToCompare, nextIncuded, nextNonIncluded, startIndex++, milliseconds); } } }
public List <JournalEntryLineModel> SolveCombinationsNegative(JournalEntryLineModel targetLine, List <JournalEntryLineModel> searchLines, int milliseconds) { //stopwatch = new Stopwatch(); // stopwatch.Start(); _sourceLines = new List <JournalEntryLineModel>(); RecursiveSolveCombinationsNegative(targetLine, 0, new List <JournalEntryLineModel>(), searchLines, 0, milliseconds); return(_sourceLines); }