Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.BioBoost/HeuristicLab.Problems.BioBoost/3.3/Utils/ValueParameterCollectionExtensions.cs @ 13069

Last change on this file since 13069 was 13069, checked in by gkronber, 9 years ago

#2499: imported source code for HeuristicLab.BioBoost from private repository with some changes

File size: 1.3 KB
Line 
1using System.Collections.Generic;
2using System.Diagnostics;
3using HeuristicLab.Core;
4using HeuristicLab.Data;
5
6namespace HeuristicLab.BioBoost.Utils {
7
8  public static class ValueParameterCollectionExtensions {
9    /// <summary>
10    /// total conversion cost including costs for required supplies minus revenue for side products.
11    /// </summary>
12    /// <param name="productsAndAmounts">the list of products and amounts</param>
13    /// <param name="productPrices">a dictionary containing the prices to use</param>
14    /// <param name="mainProductName">the main product i.e. no side product and hence excluded from this calculation</param>
15    /// <returns></returns>
16    public static double TotalCost(this ValueParameterCollection productsAndAmounts, IDictionary<string, double> productPrices, string mainProductName) {
17      double cost = 0;
18      foreach (var p in productsAndAmounts) {
19        var productName = p.Name;
20        var amount = p.Value as DoubleValue;
21        double price;
22        if (amount != null && productName != mainProductName && productPrices.TryGetValue(p.Name, out price)) {
23          cost -= amount.Value*price; // as amount*price is sales revenue -amount*price is cost ;-)
24        }
25      }
26      return cost;
27    }
28  }
29}
Note: See TracBrowser for help on using the repository browser.