/// <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]);
Exemple #2
0
    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]);