你可以拉在一起決定了兩個Tuple<N1,N2,N3,N4>
狀物體父子關係的方法。想法:位陣列表示和輪班。有了這個天真的模型:
public class Budget
{
public int Id { get; set; }
//
public int N1 { get; set; }
public Nullable<int> N2 { get; set; }
public Nullable<int> N3 { get; set; }
public Nullable<int> N4 { get; set; }
//
public float Amount { get; set; }
/// <summary>
/// Method analyzes if current object is a parent of <paramref name="other"/>
/// if you override GetHashCode or provide a nifty bit array representation
/// you can infer parent-child relationships with really fast bit shifting
/// </summary>
/// <param name="other">budget to compare with</param>
public bool IsParentOf (Budget other)
{
// ommitted for too-time-consuming and 'your work obviously'
// or 'not-the-purpose-of-this-site'reasons
return true;
}
}
,你可以嘗試讓子(你在這裏分類)每預算條目:
Budget b1 = new Budget() { N1 = 1, N2 = null, N3 = null, N4 = null, Amount = 1200f };
Budget b11 = new Budget() { N1 = 1, N2 = 1, N3 = null, N4 = null, Amount = 800f };
Budget b111 = new Budget() { N1 = 1, N2 = 1, N3 = 1, N4 = null, Amount = 800f };
Debug.Assert (b1.IsParentOf(b11));
Debug.Assert(b1.IsParentOf(b111));
Debug.Assert(b11.IsParentOf(b111));
var budgetEntries = new List<Budget>() { b11, b111 };
var subCombinations = budgetEntries.Where(be => b1.IsParentOf(be));
Debug.Assert(b1.Amount > subCombinations.Sum(sc => sc.Amount));
當然預算條目的整個數據集,你不得不匹配每一個反對所有其他人喜歡笛卡爾產品。我不認爲這很快,但它肯定應該完成這項工作。
闕? - 我認爲你需要更好地解釋你的例子。否則,我希望一些比我聰明的人能夠幫助你。 – Enigmativity 2014-10-28 09:35:54
@Enigmativity;考慮一個由4級數據組成的預算樹。 但在我的情況下,數據結構不是分層的(自引用),並且由4個固定列完成。我希望它有幫助 – 2014-10-28 09:41:08
對不起,我不明白你的數據或你的例子。我認爲您可能需要對數據進行全面的手動計算,並向我們展示工作。 – Enigmativity 2014-10-28 10:01:37