public static void Test06a() { PartitionSet set = PartitionsCalculator.Calculate(6); Console.WriteLine("Partitions of {0}:", set.Number); Console.WriteLine("{0}", set); }
public bool isViolated(Quartet q, PartitionSet p) { string t1 = string.Empty; string t2 = string.Empty; string t3 = string.Empty; string t4 = string.Empty; t1 = q._First_Taxa_Value; t2 = q._Second_Taxa_Value; t3 = q._Third_Taxa_Value; t4 = q._Fourth_Taxa_Value; Partition PartitionA = p.PartitionList[0]; Partition PartitionB = p.PartitionList[1]; if ((isInPart(PartitionA, t1) && isInPart(PartitionB, t2)) || (isInPart(PartitionA, t2) && isInPart(PartitionB, t1))) { if ((isInPart(PartitionA, t2) && isInPart(PartitionB, t3)) || (isInPart(PartitionA, t3) && isInPart(PartitionB, t2))) { return(true); } } return(false); }
public bool isSatisfied(Quartet q, PartitionSet p) { string t1 = string.Empty; string t2 = string.Empty; string t3 = string.Empty; string t4 = string.Empty; t1 = q._First_Taxa_Value; t2 = q._Second_Taxa_Value; t3 = q._Third_Taxa_Value; t4 = q._Fourth_Taxa_Value; Partition PartitionA = p.PartitionList[0]; Partition PartitionB = p.PartitionList[1]; if (isInSamePart(PartitionA, t1, t2) && isInSamePart(PartitionB, t3, t4)) { return(true); } else if (isInSamePart(PartitionB, t1, t2) && isInSamePart(PartitionA, t3, t4)) { return(true); } //if (isInSamePart(PartitionA, t2, t1) && isInSamePart(PartitionB, t4, t3)) //{ // return true; //} //else if (isInSamePart(PartitionB, t2, t1) && isInSamePart(PartitionA, t4, t3)) //{ // return true; //} return(false); }
public static void Test03c() { PartitionSet set = PartitionsCalculator.Calculate(7); set.SortDescending(); Console.WriteLine(set); }
public static void Test07b() { PartitionSet set = PartitionsCalculator.Calculate(5); foreach (Partition p in set) { Console.WriteLine(p); } }
public void GenerateGainTable(PartitionSet p) { //------------ Calculate Gain Summary CalculateGainSummary(p, _TaxaGainTable); // ---- Calculate Second Gain Summary ------------------------ // Cleaning Up all the Data before Calculation if (Get_Set_Of_Sorted_Distinct_Quartets_Original().Count != 0) { _GainTableList[0].PartitionSet._ListQuatrets = new List <Quartet>(Get_Set_Of_Sorted_Distinct_Quartets_Original()); p = _GainTableList[0].PartitionSet; foreach (Partition pp in p.PartitionList) { foreach (Taxa tb in pp.TaxaList) { tb._CumulativeGain = 0; tb._DifferedCount = 0; tb._Gain = 0; tb._IsolatedCount = 0; tb._SatisfiedCount = 0; tb._ViotatedCount = 0; tb.IsFreeze = false; } } p._DifferedCount = 0; p._IsolatedCount = 0; p._Final_Score = 0; p._Gain = 0; p._SatisfiedCount = 0; p._taxValueForGainCalculation = string.Empty; SetSortedDistinctQuartetsWithPartitionStatus(ref p, _GainTableList[0].PartitionSet); _TaxaGainTable = new List <Taxa>(); CalculateGainSummary(p, _TaxaGainTable); if (_GainTableList[0]._MaxCumulativeGain >= _GainTableList[1]._MaxCumulativeGain) { _GainTableList.RemoveAt(1); return; } else { _GainTableList.RemoveAt(0); GenerateGainTable(_GainTableList[0].PartitionSet); } } else { return; } //----------------End Of Calculationn Gain Summary }
public static void Test11() { const int number = 5; PartitionSet set = PartitionsCalculator.Calculate(number); Console.WriteLine("Partitions of {0}:", set.Number); Console.WriteLine("{0}", set); int numPartitions = PartitionsCalculator.NumberOfPartitions(number); Console.WriteLine("b({0}) = {1}", number, numPartitions); }
public static void Test02a() { PartitionSet ps = new PartitionSet(3); // add partitions of number 3 manually Partition p; p = new Partition(new int[] { 3 }); ps.Insert(p); p = new Partition(new int[] { 1, 2 }); ps.Insert(p); p = new Partition(new int[] { 1, 1, 1 }); ps.Insert(p); Console.WriteLine(ps); }
public bool isTransferrable(List <Taxa> pSet_Of_TaxaWithScore, PartitionSet p) { List <Taxa> _Set_Of_TaxaWithScore = new List <Taxa>(pSet_Of_TaxaWithScore); _Set_Of_TaxaWithScore.RemoveAll(x => x.IsFreeze == true); int _NUMBER_OF_FREE_TAXA = 0; _NUMBER_OF_FREE_TAXA = _Set_Of_TaxaWithScore.Count(); if (_NUMBER_OF_FREE_TAXA >= 1 && ((p.PartitionList[0].TaxaList.Count != 1 && p.PartitionList[1].TaxaList.Count > 1) || (p.PartitionList[1].TaxaList.Count != 1 && p.PartitionList[0].TaxaList.Count > 1))) { return(true); } return(false); }
public static void Test07() { PartitionSet set = PartitionsCalculator.Calculate(5); if (set is IEnumerable) { IEnumerator ienum = set.GetEnumerator(); Console.WriteLine("Partitions of {0}:", set.Number); while (ienum.MoveNext()) { Partition p = (Partition)ienum.Current; Console.WriteLine(p); } } }
public PartitionSet ChangePositionForGainCalculation(int i, PartitionSet InitialPartion, string pTaxaValue) { PartitionSet p = new PartitionSet("Partition" + i.ToString()); Partition PA0 = new Partition("PartitionA" + i.ToString()); Partition PB0 = new Partition("PartitionB" + i.ToString()); List <Taxa> TaxaListA0 = new List <Taxa>(InitialPartion.PartitionList[0].TaxaList); List <Taxa> TaxaListB0 = new List <Taxa>(InitialPartion.PartitionList[1].TaxaList); foreach (Taxa t in InitialPartion.PartitionList[0].TaxaList) { // Need Checking the List count greater than 2 to avoid SingleTone Bipartition //if (t._Taxa_Value == pTaxaValue && t.IsFreeze == false && TaxaListA0.Count > 2) if (t._Taxa_Value == pTaxaValue && t.IsFreeze == false) { p._taxValueForGainCalculation = pTaxaValue; TaxaListA0.Remove(t); TaxaListB0.Add(t); } } foreach (Taxa t in InitialPartion.PartitionList[1].TaxaList) { // Need Checking the List count greater than 2 to avoid SingleTone Bipartition //if (t._Taxa_Value == pTaxaValue && t.IsFreeze == false && TaxaListB0.Count > 2) if (t._Taxa_Value == pTaxaValue && t.IsFreeze == false) { p._taxValueForGainCalculation = pTaxaValue; TaxaListB0.Remove(t); TaxaListA0.Add(t); } } PA0.TaxaList = TaxaListA0; PB0.TaxaList = TaxaListB0; p.PartitionList = new List <Partition>(); p._ListQuatrets = new List <Quartet>(Get_Set_Of_Sorted_Distinct_Quartets_Original()); p.PartitionList.Add(PA0); p.PartitionList.Add(PB0); return(p); // this.PartitionSets.Add(p); }
public Bipartition(InputProcessing input) { this.inputData = input; this.Set_Of_Quartets = inputData.Get_SetOfQuartets(); this.Set_Of_Taxa = inputData.Get_SetOfTaxa(); SetDistinctQuartets(); SetDistinctDuplicateQuartets(); SetDistinctQuartetsAfterAddingDuplicateQuartets(); SetSortedDistinctQuartets(); InitialBipartition(0); this.PartitionSets[0]._ListQuatrets = Set_Of_Sorted_Distinct_Quartets; PartitionSet p = this.PartitionSets[0]; SetSortedDistinctQuartetsWithPartitionStatus(ref p, this.PartitionSets[0]); OutputProcessing.WriteInititalBiPartion(p, this.Set_Of_Taxa); GenerateGainTable(p); }
public static void Test02b() { PartitionSet ps = new PartitionSet(3); // add partitions of number 3 manually // (note order of 'Insert' calls) Partition p; p = new Partition(new int[] { 1, 1, 1 }); ps.Insert(p); p = new Partition(new int[] { 2, 1 }); ps.Insert(p); p = new Partition(new int[] { 3 }); ps.Insert(p); ps.SortDescending(); // sorting partitions Console.WriteLine(ps); }
public void CalculateGainSummary(PartitionSet p, List <Taxa> _TaxaGainTable) { GainTable Gt = new GainTable(); LoadSet_Of_TaxaWithScore(); LaterPartition(p, this._Set_Of_TaxaWithScore, this.Set_Of_Taxa.Count()); int Step = 0; int _CGain = 0; foreach (Taxa tx in _TaxaGainTable) { _CGain = _CGain + tx._Gain; tx._CumulativeGain = _CGain; tx.StepK = Step; Step++; } if (_TaxaGainTable.Count != 0) { var maximumCGain = _TaxaGainTable.Max(x => x._CumulativeGain); if (maximumCGain != null) { var TotalCount = _TaxaGainTable.Where(x => x._CumulativeGain == maximumCGain).Count(); if (TotalCount != null) { if (TotalCount > 0) { foreach (Taxa tt in _TaxaGainTable) { if (tt._CumulativeGain == maximumCGain) { Gt = new GainTable(); Gt.PartitionSet = tt._TaxaPartitionSet; Gt.TaxValue = tt._Taxa_Value; Gt._MaxCumulativeGain = tt._CumulativeGain; Gt.MaximumGainOfTaxValue = tt._Gain; Gt._TaxaGainSummary = new List <Taxa>(_TaxaGainTable); _GainTableList.Add(Gt); break; } } } } } } }
public static void Test05() { PartitionSet ps = new PartitionSet(2); // add partitions of number 2 manually Partition p; p = new Partition(new int[] { 2 }); ps.Insert(p); p = new Partition(new int[] { 1, 1 }); ps.Insert(p); Console.WriteLine("Partitions of {0}:", ps.Number); for (int i = 0; i < ps.Count; i++) { p = ps[i]; Console.WriteLine(p); } }
public void SetSortedDistinctQuartetsWithPartitionStatus(ref PartitionSet set, PartitionSet setInitial) { foreach (Quartet q in set._ListQuatrets) { q._PartitionStatus = getPartitionStatus(q, set); } var IsolatedCount = set._ListQuatrets.Where(x => x._PartitionStatus == PartitionStatus.Isolated).Count(); var ViotatedCount = set._ListQuatrets.Where(x => x._PartitionStatus == PartitionStatus.Viotated).Count(); var DifferedCount = set._ListQuatrets.Where(x => x._PartitionStatus == PartitionStatus.Differed).Count(); var SatisfiedCount = set._ListQuatrets.Where(x => x._PartitionStatus == PartitionStatus.Satisfied).Count(); set._IsolatedCount = IsolatedCount; set._ViotatedCount = ViotatedCount; set._DifferedCount = DifferedCount; set._SatisfiedCount = SatisfiedCount; set._Final_Score = set._SatisfiedCount - set._ViotatedCount; set._Gain = set._Final_Score - setInitial._Final_Score; }
public void Divide(PartitionSet pPartitionSet, string DummyTaxaCharacter, int Level, List <string> _VALID_TAXA_LIST) { string DummyTaxa = DummyTaxaCharacter + Level.ToString(); Taxa TaxaDummy = new Taxa(); TaxaDummy._Taxa_Value = DummyTaxa; //Adding Dummy Taxa to the Set PA and PB FinalPartionPair PartionPair; List <FinalPartionPair> ListPartionPair = new List <FinalPartionPair>(); foreach (Partition p in pPartitionSet.PartitionList) { PartionPair = new FinalPartionPair(); p.TaxaList.Add(TaxaDummy); PartionPair = SubDivideQuatret(pPartitionSet._ListQuatrets, p, DummyTaxa); PartionPair._Root = p.TaxaList; ListPartionPair.Add(PartionPair); } foreach (FinalPartionPair pair in ListPartionPair) { if (CountValidTaxa(pair._P.TaxaList, _VALID_TAXA_LIST) >= 1 && (pair._Q == null)) { _ListFinalPartionPair.Add(pair); } else if (CountValidTaxa(pair._P.TaxaList, _VALID_TAXA_LIST) >= 3 && (pair._Q != null)) { InputProcessing input = new InputProcessing(pair._Q, pair._P.TaxaList); Bipartition bpA = new Bipartition(input); GainTable GTable = bpA.getFinalGainTable(); Divide(GTable.PartitionSet, DummyTaxaCharacter, Level + 1, _VALID_TAXA_LIST); } else if (CountValidTaxa(pair._P.TaxaList, _VALID_TAXA_LIST) < 3 && (pair._Q != null)) { _ListFinalPartionPair.Add(pair); } } }
public static void Test10b() { PartitionSet set = PartitionsCalculator.Calculate(5); Console.WriteLine("Partitions of {0}:", set.Number); Console.WriteLine("{0}", set); int n; n = PartitionsCalculator.NumberOfPartitions(5, 1); Console.WriteLine("b(5,1) = {0}", n); n = PartitionsCalculator.NumberOfPartitions(5, 2); Console.WriteLine("b(5,2) = {0}", n); n = PartitionsCalculator.NumberOfPartitions(5, 3); Console.WriteLine("b(5,3) = {0}", n); n = PartitionsCalculator.NumberOfPartitions(5, 4); Console.WriteLine("b(5,4) = {0}", n); n = PartitionsCalculator.NumberOfPartitions(5, 5); Console.WriteLine("b(5,5) = {0}", n); Console.WriteLine(); }
public static PartitionSet Calculate(int number) { PartitionSet result = new PartitionSet(number); if (number == 1) { Partition p = new Partition(new int[] { 1 }); result.Insert(p); } else { PartitionSet setMinusOne = Calculate(number - 1); for (int i = 0; i < setMinusOne.Count; i++) { int[] numbers = setMinusOne[i].Numbers; for (int j = 0; j < numbers.Length; j++) { numbers[j]++; Partition p = new Partition(numbers); result.Insert(p); numbers[j]--; } } // create missing partition (just consisting of '1's) int[] partitionOnes = new int[number]; for (int k = 0; k < partitionOnes.Length; k++) { partitionOnes[k] = 1; } Partition pOnes = new Partition(partitionOnes); result.Insert(pOnes); } return(result); }
public PartitionStatus getPartitionStatus(Quartet q, PartitionSet p) { if (isSatisfied(q, p)) { return(PartitionStatus.Satisfied); } else if (isDiffered(q, p)) { return(PartitionStatus.Differed); } else if (isIsolated(q, p)) { return(PartitionStatus.Isolated); } else if (isViolated(q, p)) { return(PartitionStatus.Viotated); } else { return(PartitionStatus.Viotated); } }
public static void Test10a() { PartitionSet set = PartitionsCalculator.Calculate(7); Console.WriteLine("Partitions of {0}:", set.Number); Console.WriteLine("{0}", set); int n; n = PartitionsCalculator.NumberOfPartitions(7, 1); Console.WriteLine("b(7,1) = {0}", n); n = PartitionsCalculator.NumberOfPartitions(7, 2); Console.WriteLine("b(7,2) = {0}", n); n = PartitionsCalculator.NumberOfPartitions(7, 3); Console.WriteLine("b(7,3) = {0}", n); n = PartitionsCalculator.NumberOfPartitions(7, 4); Console.WriteLine("b(7,4) = {0}", n); n = PartitionsCalculator.NumberOfPartitions(7, 5); Console.WriteLine("b(7,5) = {0}", n); n = PartitionsCalculator.NumberOfPartitions(7, 6); Console.WriteLine("b(7,6) = {0}", n); n = PartitionsCalculator.NumberOfPartitions(7, 7); Console.WriteLine("b(7,7) = {0}", n); }
public List <List <string> > getHyBridDepthOneTaxaListWithoutRemovingCommonTaxa(PartitionSet SetP, SplitModel DuplicateSplit) { List <List <string> > list = new List <List <string> >(); List <string> _Left = new List <string>(); List <string> _Right = new List <string>(); _Left = DuplicateSplit._LeftPartOfSplit.Distinct().ToList(); _Right = DuplicateSplit._RightPartOfSplit.Distinct().ToList(); _Left.Sort(); _Right.Sort(); list.Add(_Left); list.Add(_Right); return(list); }
public void LaterPartition(PartitionSet InitialPartitionSet, List <Taxa> pSet_Of_TaxaWithScore, int _GlobalCountTaxaValue) { int count = 1; PartitionSet p; List <Taxa> _Set_Of_TaxaWithScore = new List <Taxa>(pSet_Of_TaxaWithScore); _Set_Of_TaxaWithScore.RemoveAll(x => x.IsFreeze == true); Taxa _Current_Moved_Taxa = new Taxa(); Taxa MaximumGainedTaxa = new Taxa(); foreach (Taxa tx in _Set_Of_TaxaWithScore) { if (tx.IsFreeze == false) { p = ChangePositionForGainCalculation(count, InitialPartitionSet, tx._Taxa_Value); SetSortedDistinctQuartetsWithPartitionStatus(ref p, InitialPartitionSet); tx._IsolatedCount = p._IsolatedCount; tx._ViotatedCount = p._ViotatedCount; tx._DifferedCount = p._DifferedCount; tx._SatisfiedCount = p._SatisfiedCount; tx._TaxaPartitionSet = p; tx._Gain = p._Gain; _Current_Moved_Taxa = tx; // Checking the Singleton if (!isTransferrable(_Set_Of_TaxaWithScore, p)) { p = null; p = InitialPartitionSet; tx._TaxaPartitionSet = p; } } count++; } if (!string.IsNullOrEmpty(_Current_Moved_Taxa._Taxa_Value)) { var maxGain = _Set_Of_TaxaWithScore.Where(x => x.IsFreeze == false).Max(x => x._Gain); if (maxGain != null) { var TotCount = _Set_Of_TaxaWithScore.Where(x => x._Gain == maxGain && x.IsFreeze == false).Count(); if (TotCount != null) { var maxGainedRow = _Set_Of_TaxaWithScore.Where(x => x._Gain == maxGain && x.IsFreeze == false).ToList(); if (maxGainedRow != null) { if (TotCount > 1) { var maximumValueSatisfiedCount = maxGainedRow.Max(x => x._SatisfiedCount); MaximumGainedTaxa = maxGainedRow.Where(x => x._SatisfiedCount == maximumValueSatisfiedCount && x.IsFreeze == false).FirstOrDefault(); } else { MaximumGainedTaxa = maxGainedRow.Where(x => x._Gain == maxGain && x.IsFreeze == false).FirstOrDefault(); } foreach (Partition pp in MaximumGainedTaxa._TaxaPartitionSet.PartitionList) { foreach (Taxa ttpp in pp.TaxaList) { if (ttpp._Taxa_Value == MaximumGainedTaxa._Taxa_Value) { ttpp.IsFreeze = true; } } } foreach (Taxa txx in _Set_Of_TaxaWithScore) { if (txx._Taxa_Value == MaximumGainedTaxa._Taxa_Value) { txx.IsFreeze = true; } } MaximumGainedTaxa.IsFreeze = true; _TaxaGainTable.Add(MaximumGainedTaxa); _GlobalCountTaxaValue--; } } } } else { } if (_GlobalCountTaxaValue == 0) { return; } else { LaterPartition(MaximumGainedTaxa._TaxaPartitionSet, _Set_Of_TaxaWithScore, _GlobalCountTaxaValue); } }
public void InitialBipartition(int PartitionSetNo) { PartitionSet Partition = new PartitionSet("Partition" + PartitionSetNo.ToString()); List <Partition> Partitions = new List <Partition>(); Partition _PartitionA; Partition _PartitionB; int index = 0; _PartitionA = new Partition("A" + index.ToString()); _PartitionB = new Partition("B" + index.ToString()); List <string> SetOfTaxa = new List <string>(this.Set_Of_Taxa); string t1 = string.Empty; string t2 = string.Empty; string t3 = string.Empty; string t4 = string.Empty; foreach (Quartet q in Set_Of_Sorted_Distinct_Quartets) { t1 = q._First_Taxa_Value; t2 = q._Second_Taxa_Value; t3 = q._Third_Taxa_Value; t4 = q._Fourth_Taxa_Value; var Qurtet_Name = q._Quartet_Name; if (!CheckForNoneOfTheValuesBelongTo(q._Quartet_Name, _PartitionA, _PartitionB, q._First_Taxa_Value, q._Second_Taxa_Value, q._Third_Taxa_Value, q._Fourth_Taxa_Value)) { // If none of the 4 taxa belongs to either PartitionSet then Insert t1 and t2 in Pa0 and t3 and t4 in Pb0 _PartitionA.TaxaList.Add(GetTaxa(t1, Qurtet_Name, 0)); SetOfTaxa.Remove(t1); _PartitionA.TaxaList.Add(GetTaxa(t2, Qurtet_Name, 1)); SetOfTaxa.Remove(t2); _PartitionB.TaxaList.Add(GetTaxa(t3, Qurtet_Name, 2)); SetOfTaxa.Remove(t3); _PartitionB.TaxaList.Add(GetTaxa(t4, Qurtet_Name, 3)); SetOfTaxa.Remove(t4); } else { // insert t1 if (!isBelongToPartition(_PartitionA, t1) && !isBelongToPartition(_PartitionB, t1)) { if (isBelongToPartition(_PartitionA, t2)) { _PartitionA.TaxaList.Add(GetTaxa(t1, Qurtet_Name, 0)); SetOfTaxa.Remove(t1); } else if (isBelongToPartition(_PartitionB, t2)) { _PartitionB.TaxaList.Add(GetTaxa(t1, Qurtet_Name, 0)); SetOfTaxa.Remove(t1); } else { if (isBelongToPartition(_PartitionA, t3)) { _PartitionB.TaxaList.Add(GetTaxa(t1, Qurtet_Name, 0)); SetOfTaxa.Remove(t1); } else if (isBelongToPartition(_PartitionB, t3)) { _PartitionA.TaxaList.Add(GetTaxa(t1, Qurtet_Name, 0)); SetOfTaxa.Remove(t1); } else { if (isBelongToPartition(_PartitionA, t4)) { _PartitionB.TaxaList.Add(GetTaxa(t1, Qurtet_Name, 0)); SetOfTaxa.Remove(t1); } else if (isBelongToPartition(_PartitionB, t4)) { _PartitionA.TaxaList.Add(GetTaxa(t1, Qurtet_Name, 0)); SetOfTaxa.Remove(t1); } } } } //insert t2 else if (!isBelongToPartition(_PartitionA, t2) && !isBelongToPartition(_PartitionB, t2)) { if (isBelongToPartition(_PartitionA, t1)) { _PartitionA.TaxaList.Add(GetTaxa(t2, Qurtet_Name, 1)); SetOfTaxa.Remove(t2); } else if (isBelongToPartition(_PartitionB, t1)) { _PartitionB.TaxaList.Add(GetTaxa(t2, Qurtet_Name, 1)); SetOfTaxa.Remove(t2); } } //insert t3 else if (!isBelongToPartition(_PartitionA, t3) && !isBelongToPartition(_PartitionB, t3)) { if (isBelongToPartition(_PartitionA, t4)) { _PartitionA.TaxaList.Add(GetTaxa(t3, Qurtet_Name, 2)); SetOfTaxa.Remove(t3); } else if (isBelongToPartition(_PartitionB, t4)) { _PartitionB.TaxaList.Add(GetTaxa(t3, Qurtet_Name, 2)); SetOfTaxa.Remove(t3); } else { if (isBelongToPartition(_PartitionA, t1)) { // Add t3 to _PartitionB _PartitionB.TaxaList.Add(GetTaxa(t3, Qurtet_Name, 2)); SetOfTaxa.Remove(t3); } else if (isBelongToPartition(_PartitionB, t1)) { // Add t3 to _PartitionA _PartitionA.TaxaList.Add(GetTaxa(t3, Qurtet_Name, 2)); SetOfTaxa.Remove(t3); } else if (isBelongToPartition(_PartitionA, t2)) { // Add t3 to _PartitionB _PartitionB.TaxaList.Add(GetTaxa(t3, Qurtet_Name, 2)); SetOfTaxa.Remove(t3); } else if (isBelongToPartition(_PartitionB, t2)) { // Add t3 to _PartitionA _PartitionA.TaxaList.Add(GetTaxa(t3, Qurtet_Name, 2)); SetOfTaxa.Remove(t3); } } } //insert t4 else if (!isBelongToPartition(_PartitionA, t4) && !isBelongToPartition(_PartitionB, t4)) { if (isBelongToPartition(_PartitionA, t3)) { _PartitionA.TaxaList.Add(GetTaxa(t4, Qurtet_Name, 3)); SetOfTaxa.Remove(t4); } else if (isBelongToPartition(_PartitionB, t3)) { _PartitionB.TaxaList.Add(GetTaxa(t4, Qurtet_Name, 3)); SetOfTaxa.Remove(t4); } } } //if (SetOfTaxa.Count == 0) // break; } //-------------Step 4 if SetOfTaxa Remains Non Empty then add remaining taxa to either part randomly Random rnd = new Random(); int number = rnd.Next(1, 1000); if (number % 2 == 0) { foreach (string ii in SetOfTaxa) { _PartitionA.TaxaList.Add(GetTaxa(ii, "", 0)); } } else { foreach (string ii in SetOfTaxa) { _PartitionB.TaxaList.Add(GetTaxa(ii, "", 0)); } } //----------------------------------------End of Step 4 Partitions.Add(_PartitionA); Partitions.Add(_PartitionB); Partition.PartitionList = Partitions; PartitionSets.Add(Partition); }
public static void WriteInititalBiPartion(PartitionSet PartitionSets, List <string> Set_Of_Taxa) { if (File.Exists(Constant.OutputFilePath)) { return; } StringBuilder sb = new StringBuilder(); sb.AppendLine("======================================================Initial Partition======================================================"); sb.AppendLine("----------------Set Of Taxa (" + Set_Of_Taxa.Count.ToString() + ")-----------------"); string SetOfTaxa = "P={"; foreach (string tx in Set_Of_Taxa) { SetOfTaxa = SetOfTaxa + tx.ToString() + ","; } SetOfTaxa = SetOfTaxa.Substring(0, SetOfTaxa.Length - 1); sb.AppendLine(SetOfTaxa + "}"); sb.AppendLine("----------------Set Of Quatret(" + PartitionSets._ListQuatrets.Count.ToString() + ")-----------------"); string SetOfQuatrets = "Q={"; foreach (Quartet tx in PartitionSets._ListQuatrets) { SetOfQuatrets = SetOfQuatrets + "((" + tx._First_Taxa_Value.ToString() + "," + tx._Second_Taxa_Value.ToString() + "),(" + tx._Third_Taxa_Value.ToString() + "," + tx._Fourth_Taxa_Value.ToString() + "));"; } SetOfQuatrets = SetOfQuatrets.Substring(0, SetOfQuatrets.Length - 1); sb.AppendLine(SetOfQuatrets + "}"); sb.AppendLine("----------------Initial Bipartition-----------------"); string InitialBiPart = string.Empty; int ii = 0; //foreach (PartitionSet set in PartitionSets) //{ PartitionSet set = PartitionSets; foreach (Partition part in set.PartitionList) { InitialBiPart = InitialBiPart + "P" + part._PartitionName + "={"; foreach (Taxa t in part.TaxaList) { InitialBiPart = InitialBiPart + t._Taxa_Value.ToString() + ","; } InitialBiPart = InitialBiPart.Substring(0, InitialBiPart.Length - 1); InitialBiPart = InitialBiPart + "}"; sb.AppendLine(InitialBiPart); InitialBiPart = string.Empty; } sb.AppendLine("----------------Set Of Satisfied-----------------"); SetOfQuatrets = "Satisfied: (" + set._SatisfiedCount.ToString() + ")={"; foreach (Quartet tx in set._ListQuatrets) { if (tx._PartitionStatus == PartitionStatus.Satisfied) { SetOfQuatrets = SetOfQuatrets + "((" + tx._First_Taxa_Value.ToString() + "," + tx._Second_Taxa_Value.ToString() + "),(" + tx._Third_Taxa_Value.ToString() + "," + tx._Fourth_Taxa_Value.ToString() + "));"; } } SetOfQuatrets = SetOfQuatrets.Substring(0, SetOfQuatrets.Length - 1); if (set._SatisfiedCount != 0) { sb.AppendLine(SetOfQuatrets + "}"); } else { sb.AppendLine(SetOfQuatrets); } sb.AppendLine("----------------Set Of Violated-----------------"); SetOfQuatrets = "Viotated : (" + set._ViotatedCount.ToString() + ")={"; foreach (Quartet tx in set._ListQuatrets) { if (tx._PartitionStatus == PartitionStatus.Viotated) { SetOfQuatrets = SetOfQuatrets + "((" + tx._First_Taxa_Value.ToString() + "," + tx._Second_Taxa_Value.ToString() + "),(" + tx._Third_Taxa_Value.ToString() + "," + tx._Fourth_Taxa_Value.ToString() + "));"; } } SetOfQuatrets = SetOfQuatrets.Substring(0, SetOfQuatrets.Length - 1); if (set._ViotatedCount != 0) { sb.AppendLine(SetOfQuatrets + "}"); } else { sb.AppendLine(SetOfQuatrets); } sb.AppendLine("----------------Set Of Differed-----------------"); SetOfQuatrets = "Differed : (" + set._DifferedCount.ToString() + ")={"; foreach (Quartet tx in set._ListQuatrets) { if (tx._PartitionStatus == PartitionStatus.Differed) { SetOfQuatrets = SetOfQuatrets + "((" + tx._First_Taxa_Value.ToString() + "," + tx._Second_Taxa_Value.ToString() + "),(" + tx._Third_Taxa_Value.ToString() + "," + tx._Fourth_Taxa_Value.ToString() + "));"; } } SetOfQuatrets = SetOfQuatrets.Substring(0, SetOfQuatrets.Length - 1); if (set._DifferedCount != 0) { sb.AppendLine(SetOfQuatrets + "}"); } else { sb.AppendLine(SetOfQuatrets); } sb.AppendLine("----------------Set Of Isolated-----------------"); SetOfQuatrets = "Isolated : (" + set._IsolatedCount.ToString() + ")={"; foreach (Quartet tx in set._ListQuatrets) { if (tx._PartitionStatus == PartitionStatus.Isolated) { SetOfQuatrets = SetOfQuatrets + "((" + tx._First_Taxa_Value.ToString() + "," + tx._Second_Taxa_Value.ToString() + "),(" + tx._Third_Taxa_Value.ToString() + "," + tx._Fourth_Taxa_Value.ToString() + "));"; } } SetOfQuatrets = SetOfQuatrets.Substring(0, SetOfQuatrets.Length - 1); if (set._IsolatedCount != 0) { sb.AppendLine(SetOfQuatrets + "}"); } else { sb.AppendLine(SetOfQuatrets); } sb.AppendLine("----------------Score Calculation-----------------"); if (ii == 0) { sb.AppendLine("Initial Score: (" + set._Final_Score.ToString() + ")"); } else { sb.AppendLine("Gain Of: (" + set._taxValueForGainCalculation.ToString() + ")"); sb.AppendLine("Final Score: (" + set._Final_Score.ToString() + ")"); sb.AppendLine("Gain Score: (" + (set._Final_Score - PartitionSets._Final_Score).ToString() + ")"); } sb.AppendLine("----------------End OF " + set._PartitionSetName); ii++; // } //System.Console.WriteLine(sb.ToString()); //System.Console.ReadLine(); File.WriteAllText(Constant.OutputFilePath, sb.ToString()); }
public static void WriteCountInformationFromMaxGainTable(GainTable _TaxaGainTable) { PartitionSet PartitionSets = _TaxaGainTable.PartitionSet; StringBuilder sb = new StringBuilder(); sb.AppendLine("----------------Set Of Quatret(" + PartitionSets._ListQuatrets.Count.ToString() + ")-----------------"); string SetOfQuatrets = "Q={"; foreach (Quartet tx in PartitionSets._ListQuatrets) { SetOfQuatrets = SetOfQuatrets + "((" + tx._First_Taxa_Value.ToString() + "," + tx._Second_Taxa_Value.ToString() + "),(" + tx._Third_Taxa_Value.ToString() + "," + tx._Fourth_Taxa_Value.ToString() + "));"; } SetOfQuatrets = SetOfQuatrets.Substring(0, SetOfQuatrets.Length - 1); sb.AppendLine(SetOfQuatrets + "}"); sb.AppendLine("----------------After Bipartition-----------------"); string InitialBiPart = string.Empty; int ii = 0; PartitionSet set = PartitionSets; foreach (Partition part in set.PartitionList) { InitialBiPart = InitialBiPart + "P" + part._PartitionName + "={"; foreach (Taxa t in part.TaxaList) { InitialBiPart = InitialBiPart + t._Taxa_Value.ToString() + ","; } InitialBiPart = InitialBiPart.Substring(0, InitialBiPart.Length - 1); InitialBiPart = InitialBiPart + "}"; sb.AppendLine(InitialBiPart); InitialBiPart = string.Empty; } sb.AppendLine("----------------Set Of Satisfied-----------------"); SetOfQuatrets = "Satisfied: (" + set._SatisfiedCount.ToString() + ")={"; foreach (Quartet tx in set._ListQuatrets) { if (tx._PartitionStatus == PartitionStatus.Satisfied) { SetOfQuatrets = SetOfQuatrets + "((" + tx._First_Taxa_Value.ToString() + "," + tx._Second_Taxa_Value.ToString() + "),(" + tx._Third_Taxa_Value.ToString() + "," + tx._Fourth_Taxa_Value.ToString() + "));"; } } SetOfQuatrets = SetOfQuatrets.Substring(0, SetOfQuatrets.Length - 1); if (set._SatisfiedCount != 0) { sb.AppendLine(SetOfQuatrets + "}"); } else { sb.AppendLine(SetOfQuatrets); } sb.AppendLine("----------------Set Of Violated-----------------"); SetOfQuatrets = "Viotated : (" + set._ViotatedCount.ToString() + ")={"; foreach (Quartet tx in set._ListQuatrets) { if (tx._PartitionStatus == PartitionStatus.Viotated) { SetOfQuatrets = SetOfQuatrets + "((" + tx._First_Taxa_Value.ToString() + "," + tx._Second_Taxa_Value.ToString() + "),(" + tx._Third_Taxa_Value.ToString() + "," + tx._Fourth_Taxa_Value.ToString() + "));"; } } SetOfQuatrets = SetOfQuatrets.Substring(0, SetOfQuatrets.Length - 1); if (set._ViotatedCount != 0) { sb.AppendLine(SetOfQuatrets + "}"); } else { sb.AppendLine(SetOfQuatrets); } sb.AppendLine("----------------Set Of Differed-----------------"); SetOfQuatrets = "Differed : (" + set._DifferedCount.ToString() + ")={"; foreach (Quartet tx in set._ListQuatrets) { if (tx._PartitionStatus == PartitionStatus.Differed) { SetOfQuatrets = SetOfQuatrets + "((" + tx._First_Taxa_Value.ToString() + "," + tx._Second_Taxa_Value.ToString() + "),(" + tx._Third_Taxa_Value.ToString() + "," + tx._Fourth_Taxa_Value.ToString() + "));"; } } SetOfQuatrets = SetOfQuatrets.Substring(0, SetOfQuatrets.Length - 1); if (set._DifferedCount != 0) { sb.AppendLine(SetOfQuatrets + "}"); } else { sb.AppendLine(SetOfQuatrets); } sb.AppendLine("----------------Set Of Isolated-----------------"); SetOfQuatrets = "Isolated : (" + set._IsolatedCount.ToString() + ")={"; foreach (Quartet tx in set._ListQuatrets) { if (tx._PartitionStatus == PartitionStatus.Isolated) { SetOfQuatrets = SetOfQuatrets + "((" + tx._First_Taxa_Value.ToString() + "," + tx._Second_Taxa_Value.ToString() + "),(" + tx._Third_Taxa_Value.ToString() + "," + tx._Fourth_Taxa_Value.ToString() + "));"; } } SetOfQuatrets = SetOfQuatrets.Substring(0, SetOfQuatrets.Length - 1); if (set._IsolatedCount != 0) { sb.AppendLine(SetOfQuatrets + "}"); } else { sb.AppendLine(SetOfQuatrets); } ii++; File.AppendAllText(Constant.OutputFilePath, sb.ToString()); }
public void StepByStep() { #region Step:1 Find Depth One Chain and Consistancy Calculation ConsistancyCalculation obj = new ConsistancyCalculation(); obj.CalculateConsistancy(); // Getting the GainTable After Initial Bipartition GainTable GB = obj.getFinalGainTableAfterGainCalculation(); // Getting Partition with maximum Gained Taxa PartitionSet SetP = GB.PartitionSet; // Getting Differred, Isolated And Violated Quatret Before Devide and Conquer List <Quartet> _DifferedQuatretListAfterGain = obj.getDifferedQuatretListAfterGain(); List <Quartet> _IsolatedQuatretListAfterGain = obj.getIsolatedQuatretListAfterGain(); List <Quartet> _ViolatedQuatretListAfterGain = obj.getViolatedQuatretListAfterGain(); // Getting All QUatret List <Quartet> _ALLQuatretListAfterGain = obj.getALLQuatretListAfterGain(); // Getting Depth One Chain After Devide And Conquer List <ConsistencyDataModel> _ListConsistencyDataModel = obj.getListConsistencyDataModel(); List <ConsistencyDataModel> _ListConsistencyDataModelRandom = obj.getListConsistencyDataModelRandom(); List <ConsistencyDataModel> _ListConsistencyDataModelRandomAfterDuplication = new List <ConsistencyDataModel>(); #region OriginalDepthOneTree for Duplication with Random Technique List <ConsistencyDataModel> _ListConsistencyDataModelOriginal = new List <ConsistencyDataModel>(); List <ConsistencyDataModel> _ListConsistencyDataModelOriginalAfterRandomDuplication = new List <ConsistencyDataModel>(); ConsistencyDataModel Cmodel; Quartet CQuatet; List <Quartet> CListQuatret; List <DepthOneTreeNode> CListDepthOneTreeNode = new List <DepthOneTreeNode>(); DepthOneTreeNode CDepthOneTreeNode; foreach (ConsistencyDataModel model in _ListConsistencyDataModel) { Cmodel = new ConsistencyDataModel(); if (_ListConsistencyDataModelRandom[0]._ALL_Quatret != null) { if (_ListConsistencyDataModelRandom[0]._ALL_Quatret.Count != 0) { CListQuatret = new List <Quartet>(); foreach (Quartet q in _ListConsistencyDataModelRandom[0]._ALL_Quatret) { CQuatet = new Quartet() { _First_Taxa_Value = q._Fourth_Taxa_Value, _Second_Taxa_Value = q._Third_Taxa_Value, _Third_Taxa_Value = q._Second_Taxa_Value, _Fourth_Taxa_Value = q._First_Taxa_Value, _Quartet_Name = q._Quartet_Name, _Quartet_Input = q._Quartet_Input, _Quartet_LeftPart = q._Quartet_LeftPart, _Quartet_LeftPartReverse = q._Quartet_LeftPartReverse, _Quartet_RightPart = q._Quartet_RightPart, _Quartet_RightPartReverse = q._Quartet_RightPartReverse, _isDistinct = q._isDistinct, _Frequency = q._Frequency, _ConsistancyStatus = ConsistencyStatus.None, _PartitionStatus = q._PartitionStatus }; CListQuatret.Add(CQuatet); } Cmodel._ALL_Quatret = new List <Quartet>(CListQuatret); } } CListQuatret = new List <Quartet>(); foreach (Quartet q in model._Isolated_Quatret) { CQuatet = new Quartet() { _First_Taxa_Value = q._Fourth_Taxa_Value, _Second_Taxa_Value = q._Third_Taxa_Value, _Third_Taxa_Value = q._Second_Taxa_Value, _Fourth_Taxa_Value = q._First_Taxa_Value, _Quartet_Name = q._Quartet_Name, _Quartet_Input = q._Quartet_Input, _Quartet_LeftPart = q._Quartet_LeftPart, _Quartet_LeftPartReverse = q._Quartet_LeftPartReverse, _Quartet_RightPart = q._Quartet_RightPart, _Quartet_RightPartReverse = q._Quartet_RightPartReverse, _isDistinct = q._isDistinct, _Frequency = q._Frequency, _ConsistancyStatus = q._ConsistancyStatus, _PartitionStatus = q._PartitionStatus }; CListQuatret.Add(CQuatet); } Cmodel._Isolated_Quatret = new List <Quartet>(CListQuatret); CListQuatret = new List <Quartet>(); foreach (Quartet q in model._Violated_Quatret) { CQuatet = new Quartet() { _First_Taxa_Value = q._Fourth_Taxa_Value, _Second_Taxa_Value = q._Third_Taxa_Value, _Third_Taxa_Value = q._Second_Taxa_Value, _Fourth_Taxa_Value = q._First_Taxa_Value, _Quartet_Name = q._Quartet_Name, _Quartet_Input = q._Quartet_Input, _Quartet_LeftPart = q._Quartet_LeftPart, _Quartet_LeftPartReverse = q._Quartet_LeftPartReverse, _Quartet_RightPart = q._Quartet_RightPart, _Quartet_RightPartReverse = q._Quartet_RightPartReverse, _isDistinct = q._isDistinct, _Frequency = q._Frequency, _ConsistancyStatus = q._ConsistancyStatus, _PartitionStatus = q._PartitionStatus }; CListQuatret.Add(CQuatet); } Cmodel._Violated_Quatret = new List <Quartet>(CListQuatret); CListQuatret = new List <Quartet>(); foreach (Quartet q in model._Differed_Quatret) { CQuatet = new Quartet() { _First_Taxa_Value = q._Fourth_Taxa_Value, _Second_Taxa_Value = q._Third_Taxa_Value, _Third_Taxa_Value = q._Second_Taxa_Value, _Fourth_Taxa_Value = q._First_Taxa_Value, _Quartet_Name = q._Quartet_Name, _Quartet_Input = q._Quartet_Input, _Quartet_LeftPart = q._Quartet_LeftPart, _Quartet_LeftPartReverse = q._Quartet_LeftPartReverse, _Quartet_RightPart = q._Quartet_RightPart, _Quartet_RightPartReverse = q._Quartet_RightPartReverse, _isDistinct = q._isDistinct, _Frequency = q._Frequency, _ConsistancyStatus = q._ConsistancyStatus, _PartitionStatus = q._PartitionStatus }; CListQuatret.Add(CQuatet); } Cmodel._Differed_Quatret = new List <Quartet>(CListQuatret); CListDepthOneTreeNode = new List <DepthOneTreeNode>(); foreach (DepthOneTreeNode node in model._DepthOneChain) { CDepthOneTreeNode = new DepthOneTreeNode(); CDepthOneTreeNode._Position = node._Position; CDepthOneTreeNode._Taxa_Value = node._Taxa_Value; CListDepthOneTreeNode.Add(CDepthOneTreeNode); } Cmodel._DepthOneChain = CListDepthOneTreeNode; _ListConsistencyDataModelOriginal.Add(Cmodel); } #endregion // Getting Consistent and Inconsistent Quatret List <Quartet> _DifferredConsistentAfterDevideAndConquer = obj.getDifferedQuatretConsistentAfterDevideAndConquer(); List <Quartet> _IsolatedConsistentAfterDevideAndConquer = obj.getIsolatedQuatretConsistentAfterDevideAndConquer(); List <Quartet> _ViolatedConsistentAfterDevideAndConquer = obj.getViolatedQuatretConsistentAfterDevideAndConquer(); List <Quartet> _IsolatedInConsistentAfterDevideAndConquer = obj.getIsolatedQuatretInConsistentAfterDevideAndConquer(); List <Quartet> _DifferredInConsistentAfterDevideAndConquer = obj.getDifferedQuatretInConsistentAfterDevideAndConquer(); List <Quartet> _ViolatedInConsistentAfterDevideAndConquer = obj.getViolatedQuatretInConsistentAfterDevideAndConquer(); List <Quartet> _RandomConsistentAfterDevideAndConquer = obj.getRandomQuatretConsistentAfterDevideAndConquer(); List <Quartet> _RandomInConsistentAfterDevideAndConquer = obj.getRandomQuatretInConsistentAfterDevideAndConquer(); #endregion #region Step:2 Get The Input (Isolated ,Violated, Differred ) var vAllInConsistentQuatret = _IsolatedInConsistentAfterDevideAndConquer.Concat(_DifferredInConsistentAfterDevideAndConquer).Concat(_ViolatedInConsistentAfterDevideAndConquer); OutputProcessing.WriteListOfQuatretInConsistancy(vAllInConsistentQuatret.ToList()); #endregion #region Step:3 Calculate Super Split List using All Inconsistent Quatret SplitCalculation objSplitCalculation = new SplitCalculation(); SplitModel SuperSplit = new SplitModel(); if (vAllInConsistentQuatret.ToList().Count != 0) { SuperSplit = objSplitCalculation.CalculateSuperSplit(vAllInConsistentQuatret.ToList()); OutputProcessing.WriteSplitValues(SuperSplit, "Super Split"); } #endregion #region Step:4 Calculate HyBrid DepthOne List List <List <string> > HyBridDepthOneList = new List <List <string> >(); if (SuperSplit._LeftPartOfSplit.Count < SuperSplit._RightPartOfSplit.Count) { SuperSplit._RightPartOfSplit = new List <string>(); } else if (SuperSplit._RightPartOfSplit.Count < SuperSplit._LeftPartOfSplit.Count) { SuperSplit._LeftPartOfSplit = new List <string>(); } else if (SuperSplit._RightPartOfSplit.Count == SuperSplit._LeftPartOfSplit.Count) { SuperSplit._LeftPartOfSplit = new List <string>(); } HyBridDepthOneList = objSplitCalculation.getHyBridDepthOneTaxaListWithoutRemovingCommonTaxa(SetP, SuperSplit); List <string> LeftMost = HyBridDepthOneList[0]; List <string> RightMost = HyBridDepthOneList[1]; List <DepthOneTreeNode> DepthOneTreeNodeLeft = new List <DepthOneTreeNode>(); List <DepthOneTreeNode> DepthOneTreeNodeRight = new List <DepthOneTreeNode>(); DepthOneTreeNode __node; int pos = 0; foreach (string tx in LeftMost) { __node = new DepthOneTreeNode(); __node._Position = pos; __node._Taxa_Value = tx; pos++; DepthOneTreeNodeLeft.Add(__node); } pos = 0; foreach (string tx in RightMost) { __node = new DepthOneTreeNode(); __node._Position = pos; __node._Taxa_Value = tx; pos++; DepthOneTreeNodeRight.Add(__node); } _ListConsistencyDataModel.Insert(0, new ConsistencyDataModel() { _Isolated_Quatret = _ListConsistencyDataModel[0]._Isolated_Quatret, _Differed_Quatret = _ListConsistencyDataModel[0]._Differed_Quatret, _Violated_Quatret = _ListConsistencyDataModel[0]._Violated_Quatret, _DepthOneChain = new List <DepthOneTreeNode>(DepthOneTreeNodeLeft) }); _ListConsistencyDataModel.Add(new ConsistencyDataModel() { _Isolated_Quatret = _ListConsistencyDataModel[0]._Isolated_Quatret, _Differed_Quatret = _ListConsistencyDataModel[0]._Differed_Quatret, _Violated_Quatret = _ListConsistencyDataModel[0]._Violated_Quatret, _DepthOneChain = new List <DepthOneTreeNode>(DepthOneTreeNodeRight) }); OutputProcessing.PrintHyBridDepthOneTree(_ListConsistencyDataModel); OutputProcessing.GenerateInputForHyBridDepthOneTree(_ListConsistencyDataModel); OutputProcessing.GenerateCountOfDuplicateTaxa(DepthOneTreeNodeLeft, DepthOneTreeNodeRight); #endregion #region Step:5 Calculate Random DepthOne Chain string OutputHeaderRandom = "===============================================Consistancy Calculation(Randomized Technique)======================================================"; OutputProcessing.PrintHyBridDepthOneTree(_ListConsistencyDataModelRandom, "Randomized Divide and Conquer Approach with Split Analysis Technique", "====================================Depth One Element with Randomized Technique======================"); OutputProcessing.WriteQuatretConsistancy(_ListConsistencyDataModelRandom[0]._ALL_Quatret, PartitionStatus.None, OutputHeaderRandom); List <Quartet> all_InconsistentQuatret_for_Random = new List <Quartet>(); var vInConsistent_for_Random = _ListConsistencyDataModelRandom[0]._ALL_Quatret.FindAll(x => x._ConsistancyStatus == ConsistencyStatus.InConsistent); foreach (Quartet q in vInConsistent_for_Random) { CQuatet = new Quartet() { _First_Taxa_Value = q._Fourth_Taxa_Value, _Second_Taxa_Value = q._Third_Taxa_Value, _Third_Taxa_Value = q._Second_Taxa_Value, _Fourth_Taxa_Value = q._First_Taxa_Value, _Quartet_Name = q._Quartet_Name, _Quartet_Input = q._Quartet_Input, _Quartet_LeftPart = q._Quartet_LeftPart, _Quartet_LeftPartReverse = q._Quartet_LeftPartReverse, _Quartet_RightPart = q._Quartet_RightPart, _Quartet_RightPartReverse = q._Quartet_RightPartReverse, _isDistinct = q._isDistinct, _Frequency = q._Frequency, _ConsistancyStatus = q._ConsistancyStatus, _PartitionStatus = q._PartitionStatus }; all_InconsistentQuatret_for_Random.Add(CQuatet); } #endregion #region Step:6 Calculate Duplication For Random DepthOne Chain objSplitCalculation.CalculateRandomDepthOneChainWithRandomizedUnionOperationDuplicationNew(_ListConsistencyDataModelRandom[0]._ALL_Quatret, _ListConsistencyDataModelRandom); _ListConsistencyDataModelRandomAfterDuplication = objSplitCalculation.getListConsistencyDataModelRandomAfterDuplication(); bool isAddedtotheleft = objSplitCalculation.getIsAddedToLeft(); int totalCount = _ListConsistencyDataModelRandomAfterDuplication.Count() - 1; //OutputHeaderRandom = "======================================================Consistancy Calculation(Random Technique Duplication)======================================================"; OutputProcessing.PrintHyBridDepthOneTree(_ListConsistencyDataModelRandomAfterDuplication, "Randomized Depth One Element With Duplicated Taxa"); if (isAddedtotheleft) { OutputProcessing.GenerateCountOfDuplicateTaxaOfRandomDepthTree(_ListConsistencyDataModelRandomAfterDuplication[0]._DepthOneChain, isAddedtotheleft); } else { OutputProcessing.GenerateCountOfDuplicateTaxaOfRandomDepthTree(_ListConsistencyDataModelRandomAfterDuplication[totalCount]._DepthOneChain, isAddedtotheleft); } #endregion #region Step:7 Calculate Super Split for Random DepthOne Chain OutputHeaderRandom = "======================================================Inconsistant Quatrets(Randomized Divide and Conquer Approach)======================================================"; OutputProcessing.WriteQuatretConsistancy(all_InconsistentQuatret_for_Random, PartitionStatus.None, OutputHeaderRandom); objSplitCalculation = new SplitCalculation(); SuperSplit = new SplitModel(); if (vAllInConsistentQuatret.ToList().Count != 0) { SuperSplit = objSplitCalculation.CalculateSuperSplit(all_InconsistentQuatret_for_Random.ToList()); OutputProcessing.WriteSplitValues(SuperSplit, "Super Split For Randomized Depth One Chain"); } // Calculate Random DepthOne Chain With SuperSplit List <List <string> > HyBridDepthOneListRandom = new List <List <string> >(); if (SuperSplit._LeftPartOfSplit.Count < SuperSplit._RightPartOfSplit.Count) { SuperSplit._RightPartOfSplit = new List <string>(); } else if (SuperSplit._RightPartOfSplit.Count < SuperSplit._LeftPartOfSplit.Count) { SuperSplit._LeftPartOfSplit = new List <string>(); } else if (SuperSplit._RightPartOfSplit.Count == SuperSplit._LeftPartOfSplit.Count) { SuperSplit._LeftPartOfSplit = new List <string>(); } HyBridDepthOneListRandom = objSplitCalculation.getHyBridDepthOneTaxaListWithoutRemovingCommonTaxa(null, SuperSplit); List <string> LeftMostRandom = HyBridDepthOneListRandom[0]; List <string> RightMostRandom = HyBridDepthOneListRandom[1]; List <DepthOneTreeNode> DepthOneTreeNodeLeftRandom = new List <DepthOneTreeNode>(); List <DepthOneTreeNode> DepthOneTreeNodeRightRandom = new List <DepthOneTreeNode>(); DepthOneTreeNode __nodeRandom; pos = 0; foreach (string tx in LeftMostRandom) { __nodeRandom = new DepthOneTreeNode(); __nodeRandom._Position = pos; __nodeRandom._Taxa_Value = tx; pos++; DepthOneTreeNodeLeftRandom.Add(__nodeRandom); } pos = 0; foreach (string tx in RightMostRandom) { __nodeRandom = new DepthOneTreeNode(); __nodeRandom._Position = pos; __nodeRandom._Taxa_Value = tx; pos++; DepthOneTreeNodeRightRandom.Add(__nodeRandom); } if (isAddedtotheleft) { _ListConsistencyDataModelRandom.RemoveAt(0); } else { _ListConsistencyDataModelRandom.RemoveAt(_ListConsistencyDataModelRandom.Count - 1); } _ListConsistencyDataModelRandom.Insert(0, new ConsistencyDataModel() { _Isolated_Quatret = _ListConsistencyDataModelRandom[0]._Isolated_Quatret, _Differed_Quatret = _ListConsistencyDataModelRandom[0]._Differed_Quatret, _Violated_Quatret = _ListConsistencyDataModelRandom[0]._Violated_Quatret, _DepthOneChain = new List <DepthOneTreeNode>(DepthOneTreeNodeLeftRandom) }); _ListConsistencyDataModelRandom.Add(new ConsistencyDataModel() { _Isolated_Quatret = _ListConsistencyDataModelRandom[0]._Isolated_Quatret, _Differed_Quatret = _ListConsistencyDataModelRandom[0]._Differed_Quatret, _Violated_Quatret = _ListConsistencyDataModelRandom[0]._Violated_Quatret, _DepthOneChain = new List <DepthOneTreeNode>(DepthOneTreeNodeRightRandom) }); OutputProcessing.PrintHyBridDepthOneTree(_ListConsistencyDataModelRandom, "Randomized Depth One Element with Minimum Super-Element"); //OutputProcessing.GenerateInputForHyBridDepthOneTree(_ListConsistencyDataModelRandom); OutputProcessing.GenerateCountOfDuplicateTaxa(DepthOneTreeNodeLeftRandom, DepthOneTreeNodeRightRandom); //------- #endregion #region Step 8: Calculate Duplication for Original Depth One Chain with Random Technique List <Quartet> all_Quatret = new List <Quartet>(); all_Quatret = obj.GetConsistancyStatusOfQuatret(_ListConsistencyDataModelOriginal, _ListConsistencyDataModelOriginal[0]._ALL_Quatret); foreach (ConsistencyDataModel dmodel in _ListConsistencyDataModelOriginal) { dmodel._ALL_Quatret = new List <Quartet>(all_Quatret); } OutputProcessing.PrintHyBridDepthOneTree(_ListConsistencyDataModelOriginal, "Depth One Element from Bipartition Based Divide and Conquer Approach"); ConsistencyDataModel dmodelOriginal = _ListConsistencyDataModelOriginal[0]; OutputHeaderRandom = string.Empty; var vConsistentOriginal = dmodelOriginal._ALL_Quatret.FindAll(x => x._ConsistancyStatus == ConsistencyStatus.Consistent); var vInConsistentOriginal = dmodelOriginal._ALL_Quatret.FindAll(x => x._ConsistancyStatus == ConsistencyStatus.InConsistent); objSplitCalculation.CalculateRandomDepthOneChainWithRandomizedUnionOperationDuplicationNew(vInConsistentOriginal, _ListConsistencyDataModelOriginal); _ListConsistencyDataModelOriginalAfterRandomDuplication = objSplitCalculation.getListConsistencyDataModelRandomAfterDuplication(); isAddedtotheleft = objSplitCalculation.getIsAddedToLeft(); totalCount = _ListConsistencyDataModelOriginalAfterRandomDuplication.Count() - 1; OutputProcessing.WriteQuatretConsistancy(dmodelOriginal._ALL_Quatret, PartitionStatus.None, OutputHeaderRandom); OutputProcessing.PrintHyBridDepthOneTree(_ListConsistencyDataModelOriginalAfterRandomDuplication, "Depth One Element with Randomized Duplication"); if (isAddedtotheleft) { OutputProcessing.GenerateCountOfDuplicateTaxaOfRandomDepthTree(_ListConsistencyDataModelOriginalAfterRandomDuplication[0]._DepthOneChain, isAddedtotheleft); } else { OutputProcessing.GenerateCountOfDuplicateTaxaOfRandomDepthTree(_ListConsistencyDataModelOriginalAfterRandomDuplication[totalCount]._DepthOneChain, isAddedtotheleft); } #endregion }
public void CalculateConsistancy() { if (File.Exists(Constant.OutputFilePath)) { File.Delete(Constant.OutputFilePath); } DivideAndConquer divideAndConquer = new DivideAndConquer(); InputProcessing input = new InputProcessing(); Bipartition bp = new Bipartition(input); GainTable GainTable = new GainTable(); GainTable = bp.getFinalGainTable(); int loop = 0; ConsistencyDataModel data = new ConsistencyDataModel(); DepthOneTreeNode node; List <DepthOneTreeNode> ListDepthOneTreeNode = new List <DepthOneTreeNode>(); ConsistencyDataModel dataRandom = new ConsistencyDataModel(); DepthOneTreeNode nodeRandom; List <DepthOneTreeNode> ListDepthOneTreeNodeRandom = new List <DepthOneTreeNode>(); if (GainTable != null) { SetFinalGainTableAfterGainCalculation(GainTable); PartitionSet setOfMaxGain = GainTable.PartitionSet; SetALLQuatretInput(setOfMaxGain._ListQuatrets); var vDiffered = setOfMaxGain._ListQuatrets.FindAll(x => x._PartitionStatus == PartitionStatus.Differed); if (vDiffered != null) { SetDifferedQuatretInput(vDiffered.ToList()); } var vIsolated = setOfMaxGain._ListQuatrets.FindAll(x => x._PartitionStatus == PartitionStatus.Isolated); if (vIsolated != null) { SetIsolatedQuatretInput(vIsolated.ToList()); } var vViolated = setOfMaxGain._ListQuatrets.FindAll(x => x._PartitionStatus == PartitionStatus.Viotated); if (vViolated != null) { SetViolatedQuatretInput(vViolated.ToList()); } OutputProcessing.PrintGainSummary(GainTable); OutputProcessing.WriteCountInformationFromMaxGainTable(GainTable); _VALID_TAXA_LIST = input.Get_SetOfTaxa(); divideAndConquer.Divide(GainTable.PartitionSet, DummyTaxaCharacter, 1, _VALID_TAXA_LIST); List <FinalPartionPair> ll = divideAndConquer.getFinalPartionPair(); OutputProcessing.PrintFinalTableOfDivideAndConquerApproach(ll); loop = 0; foreach (FinalPartionPair pair in ll) { ListDepthOneTreeNode = new List <DepthOneTreeNode>(); data = new ConsistencyDataModel(); data._Differed_Quatret = this._DifferedQuatretListAfterGain; data._Isolated_Quatret = this._IsolatedQuatretListAfterGain; data._Violated_Quatret = this._ViolatedQuatretListAfterGain; foreach (Taxa tx in pair._P.TaxaList) { node = new DepthOneTreeNode(); node._Position = loop; node._Taxa_Value = tx._Taxa_Value; ListDepthOneTreeNode.Add(node); } data._DepthOneChain = ListDepthOneTreeNode; _ListConsistencyDataModel.Add(data); loop++; } #region finding Consistancy Status ConsistencyDataModel dmodel = _ListConsistencyDataModel[0]; string OutputHeader = "======================================================Consistancy Calculation======================================================"; #region ISOLATED dmodel._Isolated_Quatret = GetConsistancyStatusOfQuatret(_ListConsistencyDataModel, dmodel._Isolated_Quatret); var vIsoConsistent = dmodel._Isolated_Quatret.FindAll(x => x._ConsistancyStatus == ConsistencyStatus.Consistent); SetIsolatedQuatretConsistentAfterDevideAndConquer(vIsoConsistent); var vIsoInConsistent = dmodel._Isolated_Quatret.FindAll(x => x._ConsistancyStatus == ConsistencyStatus.InConsistent); SetIsolatedQuatretInConsistentAfterDevideAndConquer(vIsoInConsistent); OutputProcessing.WriteQuatretConsistancy(dmodel._Isolated_Quatret, PartitionStatus.Isolated, OutputHeader); #endregion #region Violated Quatret dmodel._Violated_Quatret = GetConsistancyStatusOfQuatret(_ListConsistencyDataModel, dmodel._Violated_Quatret); var vViolatedConsistent = dmodel._Violated_Quatret.FindAll(x => x._ConsistancyStatus == ConsistencyStatus.Consistent); SetViolatedQuatretConsistentAfterDevideAndConquer(vViolatedConsistent); var vViolatedInConsistent = dmodel._Violated_Quatret.FindAll(x => x._ConsistancyStatus == ConsistencyStatus.InConsistent); SetViolatedQuatretInConsistentAfterDevideAndConquer(vViolatedInConsistent); OutputProcessing.WriteQuatretConsistancy(dmodel._Violated_Quatret, PartitionStatus.Viotated, string.Empty); #endregion #region Differed Quatret dmodel._Differed_Quatret = GetConsistancyStatusOfQuatret(_ListConsistencyDataModel, dmodel._Differed_Quatret); var vDiffConsistent = dmodel._Differed_Quatret.FindAll(x => x._ConsistancyStatus == ConsistencyStatus.Consistent); SetDifferedQuatretConsistentAfterDevideAndConquer(vDiffConsistent); var vDiffInConsistent = dmodel._Differed_Quatret.FindAll(x => x._ConsistancyStatus == ConsistencyStatus.InConsistent); SetDifferedQuatretInConsistentAfterDevideAndConquer(vDiffInConsistent); OutputProcessing.WriteQuatretConsistancy(dmodel._Differed_Quatret, PartitionStatus.Differed, string.Empty); #endregion #endregion #region Random Technique var listOfTaxaRandom = input.getSetOfTaxa(); divideAndConquer.generateDepthOneTreeRandomly(listOfTaxaRandom, DummyTaxaCharacter, 1, _VALID_TAXA_LIST, this._ALLQuatretListAfterGain); List <FinalPartionPair> llRandom = divideAndConquer.getFinalPartionPairRandom(); //OutputProcessing.PrintDepthOneTreeRandom(llRandom, "Random Depth One Tree"); loop = 0; foreach (FinalPartionPair pair in llRandom) { ListDepthOneTreeNodeRandom = new List <DepthOneTreeNode>(); dataRandom = new ConsistencyDataModel(); dataRandom._Differed_Quatret = this._DifferedQuatretListAfterGain; dataRandom._Isolated_Quatret = this._IsolatedQuatretListAfterGain; dataRandom._Violated_Quatret = this._ViolatedQuatretListAfterGain; dataRandom._ALL_Quatret = this._ALLQuatretListAfterGain; foreach (Taxa tx in pair._Root) { nodeRandom = new DepthOneTreeNode(); nodeRandom._Position = loop; nodeRandom._Taxa_Value = tx._Taxa_Value; ListDepthOneTreeNodeRandom.Add(nodeRandom); } dataRandom._DepthOneChain = ListDepthOneTreeNodeRandom; _ListConsistencyDataModelRandom.Add(dataRandom); loop++; } ConsistencyDataModel dmodelRandom = _ListConsistencyDataModelRandom[0]; //string OutputHeaderRandom = "======================================================Consistancy Calculation(Random Technique)======================================================"; dmodelRandom._ALL_Quatret = GetConsistancyStatusOfQuatret(_ListConsistencyDataModelRandom, dmodelRandom._ALL_Quatret); var vConsistentRandom = dmodelRandom._ALL_Quatret.FindAll(x => x._ConsistancyStatus == ConsistencyStatus.Consistent); SetRandomQuatretConsistentAfterDevideAndConquer(vConsistentRandom); var vInConsistentRandom = dmodelRandom._ALL_Quatret.FindAll(x => x._ConsistancyStatus == ConsistencyStatus.InConsistent); SetRandomQuatretInConsistentAfterDevideAndConquer(vInConsistentRandom); //OutputProcessing.WriteQuatretConsistancy(dmodelRandom._ALL_Quatret, PartitionStatus.None, OutputHeaderRandom); #endregion } }