Line | |
---|
1 | using System.Collections.Generic;
|
---|
2 | using System.Diagnostics;
|
---|
3 | using HeuristicLab.Core;
|
---|
4 | using HeuristicLab.Data;
|
---|
5 |
|
---|
6 | namespace 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.