/// <inheritdoc/> public override EvaluationResult Evaluate(long[] selection, int depth, long sum) { long totalCost = sum + CurrentInputCosts; if (IncludedCoinsCount > Parameters.MaxInputCount) { // Too many coins in the selection. Cut the branch. return(EvaluationResult.SkipBranch); } if (sum > Target) { // Excessive funds, cut the branch. return(EvaluationResult.SkipBranch); } long maximumSum = sum + RemainingAmounts[depth - 1]; if (maximumSum < BestSelection.PaymentAmount || maximumSum < MinimumTarget) { // The remaining coins cannot sum up to our best solution, or it is less than minimum acceptable target value. return(EvaluationResult.SkipBranch); } if (sum > BestSelection.PaymentAmount || (sum == BestSelection.PaymentAmount && totalCost < BestSelection.TotalCosts)) { BestSelection.Update(sum, totalCost, IncludedCoinsCount, selection[0..depth]);
/// <inheritdoc/> public override long[]? GetBestSelectionFound() { if (BestSelection.PaymentAmount < MinimumTarget) { return(null); } return(BestSelection.GetSolutionArray()); }
public override EvaluationResult Evaluate(long[] selection, int depth, long sum) { long totalCost = sum + CurrentInputCosts; if (sum > BestSelection.PaymentAmount || sum > MaximumTarget) { // Our solution is already better than what we might get here. return(EvaluationResult.SkipBranch); } if (sum >= Target) { if (sum < BestSelection.PaymentAmount || (sum == BestSelection.PaymentAmount && totalCost < BestSelection.TotalCosts)) { BestSelection.Update(sum, totalCost, selection[0..depth]);
/// <summary>Gets best valid found selection as an array of effective values, or <c>null</c> if none was found.</summary> public virtual long[]? GetBestSelectionFound() => BestSelection.GetSolutionArray();