コード例 #1
0
    /// <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]);
コード例 #2
0
    /// <inheritdoc/>
    public override long[]? GetBestSelectionFound()
    {
        if (BestSelection.PaymentAmount < MinimumTarget)
        {
            return(null);
        }

        return(BestSelection.GetSolutionArray());
    }
コード例 #3
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]);
コード例 #4
0
 /// <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();