public void Apportion() { foreach (CostCategory <T> category in m_categories) { if (category.Apportionable) { // Push my apportionable costs down foreach (Cost <T> child in m_master.CostChildren.Select(n => n.Cost)) { CostCategory <T> childsCategory = child.GetMatchingCategory(category); double portion = childsCategory.ApportionmentFraction((T)child.m_master); if (s_diagnostics) { Console.WriteLine("{0} is assigning {1:0%} of its {2} apportionable cost {3} to {4}.", ((IHasName)m_master).Name, portion, category.Name, category.ApportionableCost, ((IHasName)child.m_master).Name); } childsCategory.ApportionedCost = portion * category.ApportionableCost; } } } }
private void _DumpCostData(Thing thing, int indentLevel) { Console.WriteLine("{0}{1} - total cost {2}", StringOperations.Spaces(indentLevel * 3), thing.Name, thing.Cost.Total); foreach (string categoryName in Thing.COST_CATEGORIES.Select(n => n.Name)) { CostCategory <Thing> category = ((IHasCost <Thing>)thing).Cost[categoryName]; Console.WriteLine("{0}{1} : {2:F2}\t{3:F2}\t{4:F2}", StringOperations.Spaces(15), category.Name, category.InheritedCost, category.DirectCost, category.ApportionedCost); } foreach (Thing child in thing.Children) { _DumpCostData(child, indentLevel + 1); } }
public void Subsume() { foreach (CostCategory <T> category in Categories) { if (category.Inheritable) { // Pull inheritable costs up. foreach (Cost <T> child in m_master.CostChildren.Select(n => n.Cost)) { CostCategory <T> childsCategory = child.GetMatchingCategory(category); if (s_diagnostics) { Console.WriteLine("{0} is inheriting {1} cost {2} from {3}.", ((IHasName)m_master).Name, category.Name, childsCategory.InheritableCost, ((IHasName)child.m_master).Name); } category.InheritedCost += (childsCategory.InheritableCost); } } } }
CostCategory <T> GetMatchingCategory(CostCategory <T> exemplar) { return(m_categories.Single(n => n.Name.Equals(exemplar.Name))); }