public void MergeList(R1pnList rlist1) { foreach (R1pn r1 in rlist1.rList) { Add(r1); } }
public Mid_2(ref RawData r, ref Mid_1 m1) { rd = r; mid1 = m1; mid2 = new int[rd.Cols]; MaxStep = r.tpsn; rlist = new R1pnList(); FirstMakeR1PN(); sw = new StreamWriter(Common.debugpath + "\\" + "MID2.txt"); printRList(); }
public Mid_4_3(ref RawData r, ref Mid_4_1 md41, ref Mid_4_2 m42) { rd = r; md42 = m42; mid4_3 = new int[rd.Cols]; Array.Clear(mid4_3, 0, mid4_3.Length); sw = new StreamWriter(Common.debugpath + "\\" + "MID4_3.txt"); // test ++++++++++++++++++++++++++++++++++++++++++++++++ // md42.digit[0] = 1; // md42.digit[1] = 1; // make SPN Combination FROM Mid_4_2 // make that each array in md41.rlist has multiple elements of digit[i]. R1pnList rFrom, rTo; rFrom = md41.rlist.Clone(); for (int i = 0; i < md42.digit.Length; i++) { if (md42.digit[i] <= 1) { continue; } rFrom.rList[i].MakeMultiple(md42.digit[i]); } // make SPN Combination R1pnList rTarget = new R1pnList(); rTo = new R1pnList(); for (int i = 0; i < md42.digit.Length; i++) //for (int i = md42.digit.Length-1; i>=0 ; i--) { if (md42.digit[i] <= 0) { continue; } rTarget = new R1pnList(); for (int j = 0; j < rFrom.rList[i].cp / md42.digit[i]; j++) { R1pnList rToTo = rTo.Clone(); rToTo.AddAllList(rFrom.rList[i].r1pn, j * md42.digit[i], md42.digit[i]); rTarget.MergeList(rToTo); rToTo = null; } rTo = rTarget; GC.Collect(); } rTo = null; rTarget.print(ref sw); // count each pn how many times it comes in the SPN Combination table. rTarget.getCountEachPN(ref mid4_3); Common.printArray("MID4_3 :MID4_3", mid4_3, ref sw); }
public void printListPercent(R1pnList rlist) { try { rlist.printPercentToExcel(this); } catch (Exception ex) { Console.WriteLine("ExcelWrapper:printLine, ERROR: " + ex.Message); } }
public R1pnList Clone() { R1pnList r = new R1pnList(); foreach (R1pn r1 in rList) { R1pn newr = r1.Clone(); r.Add(newr); } return(r); }
public Mid_3_4(ref Mid_3_3 m) { m33 = m.mid3_3_table; rd = m.rd; mid3_4 = new int[rd.Cols]; Array.Clear(mid3_4, 0, mid3_4.Length); sw = new StreamWriter(Common.debugpath + "\\" + "MID3_4.txt"); cplistcount = 0; cpnlist = new Cpnlist[m33.Cols]; MaxStep = rd.tpsn; rlist = new R1pnList(); FirstMakeR1PN(); Run(); }
// Make subset list from the R1pn. // for example, (11,25, 39, 20) => {(11,25,39,20), (25,39,20), (39,20), (20)} private void MakeSubsetofR1pn(ref R1pnList rsubset, int indexofbaseR1pn, R1pn r1) { int count = r1.cp; R1pn r2 = new R1pn(r1.r1pn.Length); r2.CopyFrom(r1); for (int i = 0; i < count; i++) { if (!rsubset.IsExist(ref r2)) //check if rsubset already has the r2. { R1pn new1 = new R1pn(r1.r1pn.Length); new1.CopyFrom(r2); new1.indexofbaseR1pn = indexofbaseR1pn; rsubset.Add(new1); } r2.ShiftLeft_1(); if (r2.cp <= 0) { break; } } }
public void Close() { sw.Close(); rlist = rnext = null; }
public void Run() { Array.Clear(mid3_4, 0, mid3_4.Length); for (Step = 0; Step < MaxStep; Step++) { rnext = null; rnext = new R1pnList(); R1pnList rsubset = new R1pnList(); sw.WriteLine(""); sw.WriteLine("NEW R1PN Start: step:" + Step + " 's R1pn List "); // make subset of the R1PN_X step. int indexofbaseR1pn = 0; foreach (R1pn r1 in rlist.rList) { r1.printPercent(ref sw); MakeSubsetofR1pn(ref rsubset, indexofbaseR1pn, r1); indexofbaseR1pn++; } sw.WriteLine(""); sw.WriteLine("rsubset's List "); rsubset.printPercent(ref sw); // process each subset. foreach (R1pn r1 in rsubset.rList) { Find_Next_R1pn_Set(r1); } sw.WriteLine(""); sw.WriteLine("rnext's List "); rnext.printPercent(ref sw); if (rnext.Count == 0) { sw.WriteLine("rnext's List is empty "); sw.WriteLine("exit this stage and go to final processing "); rnext = null; rsubset = null; GC.Collect(); break; } // Remove Current R1pn_X List // Set Next R1pn_X1 List rlist.rList = null; rlist.rList = rnext.rList; //Common.printArray("MID3_4 :(" + Step.ToString() + ") ", mid2, ref sw); rnext = null; rsubset = null; GC.Collect(); } // count each pn how many times it comes in all of rlist temp = new int[m33.Cols]; rlist.FinalProcessing_PNS(ref temp); // then, sort the count by pn // choose highest pn count as much as tspn number. int[] temp2 = new int[m33.Cols]; Array.Copy(temp, temp2, temp.Length); Array.Sort(temp2); Common.printArrayPercent("MID3-4 : %SP values (this means how many times does each %SP appear in the List)", temp, ref sw); //Common.printArrayPercent("Temp2 :(temp2) ", temp2, ref sw); #if false int[] perTemp = new int[m33.Cols]; Array.Clear(perTemp, 0, perTemp.Length); int val = 0, flag = 0, count = 0; for (int i = temp2.Length - 1; i >= 0; i--) { if (flag == 1 || temp2[i] == 0) { break; } if (temp2[i] != val) { val = temp2[i]; } else { continue; } for (int j = 0; j < temp.Length; j++) { if (temp[j] == val) { perTemp[j] = 1; count++; } if (count == rd.tpsn + 2) { flag = 1; break; } } } #else perTemp = new int[m33.Cols]; Array.Clear(perTemp, 0, perTemp.Length); for (int i = 0; i < temp.Length; i++) { if (temp[i] == temp2[temp2.Length - 1]) { perTemp[i] = 1; } } maxSpcCount = temp2[temp2.Length - 1]; #endif sw.WriteLine(); sw.WriteLine("max %SP value : " + maxSpcCount.ToString()); sw.WriteLine(); Common.printArrayPercent("MID3-4 :(Choose %SPs' that have max %SP value) ", perTemp, ref sw); // make mid3_4 sw.WriteLine(); //Common.printArray("RawData %SP: ", rd.PerSP, ref sw); //sw.WriteLine(); cplistcount = 0; Array.Clear(mid3_4, 0, mid3_4.Length); for (int i = 0; i < perTemp.Length; i++) { if (perTemp[i] > 0) { // get interval double intmin, intmax; intmax = (i + 1) * Common.GpspInterval; intmin = intmax - Common.GpspInterval; string pns = ""; pns = "Interval(%SP): " + (intmin).ToString("###0.0") + "% ~ " + intmax.ToString("###0.0") + "% , "; pns += " PN's : "; cpnlist[cplistcount] = new Cpnlist(rd.Cols); // get PNs between intmax and intmin for (int j = 0; j < rd.Cols; j++) { double persp = rd.PerSP[j]; if (persp > intmin && persp <= intmax) { //mid3_4[j] = 1; cpnlist[cplistcount].Add(j); pns += ((j + 1).ToString() + " "); } } cplistcount++; sw.WriteLine(pns); } } sw.WriteLine(); // find max list in cpnlist[] int index = cpnlist.Length, cmax = 0; for (int i = 0; i < cplistcount; i++) { if (cpnlist[i] == null) { continue; } if (cpnlist[i].count > cmax) { cmax = cpnlist[i].count; index = i; } } if (index < cpnlist.Length) { for (int i = 0; i < cpnlist[index].count; i++) { mid3_4[cpnlist[index].pns[i]] = 1; } } Common.printArray("MID3_4 :(LAST) ", mid3_4, ref sw); //Common.printIndex("MID3_4 INDEX Print :(LAST) ", mid3_4, ref sw); // make rank // temp: %sp values that is already counted // temp2 : sorted array of temp as an order of ascent Common.printArray("MID3_4 :(temp) ", temp, ref sw); Common.printArray("MID3_4 :(temp2) ", temp2, ref sw); rank3_4 = new int[rd.Cols]; Array.Clear(rank3_4, 0, rank3_4.Length); int rank = 1, prank = 1; int idx = 0, val; while (temp2[temp2.Length - 1 - idx] > 0) { val = temp2[temp2.Length - 1 - idx]; if (idx > 0 && temp2[temp2.Length - 1 - idx] == temp2[temp2.Length - 1 - (idx - 1)]) { idx++; continue; } prank = rank; for (int i = 0; i < temp.Length; i++) { if (temp[i] == val) { // i: index of %sp , double intmin, intmax; intmax = (i + 1) * Common.GpspInterval; intmin = intmax - Common.GpspInterval; for (int k = 0; k < rd.Cols; k++) { if (rd.PerSP[k] > intmin && rd.PerSP[k] <= intmax) { rank3_4[k] = prank; rank++; } } } } idx++; } Common.printArray("MID3_4 :(RANK) ", rank3_4, ref sw); }
public Mid_3_1(ref RawData r) { rd = r; rlist = new R1pnList(); mid3_1 = new int[max_mid31_Count, rd.Cols]; mid3_1_Count = 0; for (int i = 0; i < max_mid31_Count; i++) { for (int j = 0; j < rd.Cols; j++) { mid3_1[i, j] = 0; } } sw = new StreamWriter(Common.debugpath + "\\" + "MID3_1.txt"); int count = (int)(100 / Common.GpspInterval); for (int i = 0; i < count; i++) { R1pn r1 = new R1pn(5); rlist.Add(r1); } // make G%SP table int index; for (Int16 i = 0; i < r.Cols; i++) { index = (int)(r.PerSP[i] / Common.GpspInterval); rlist.rList[index].Add(i); } // test code // rlist.rList[3].Add(5); // rlist.rList[3].Add(9); // rlist.rList[3].Add(28); // rlist.rList[3].Add(45); // rlist.rList[3].Add(34); //Get Max index of a R1pn count = rlist.GetMaxCount(); index = 0; for (int i = 0; i < rlist.rList.Count; i++) { if (rlist.rList[i].cp == count) { for (int j = 0; j < rlist.rList[i].cp; j++) { mid3_1[index, rlist.rList[i].r1pn[j]] = 1; } index++; } } mid3_1_Count = index; rlist.print(ref sw, 10); int[] temp = new int[rd.Cols]; if (mid3_1_Count == 1) { for (int i = 0; i < rd.Cols; i++) { temp[i] = mid3_1[0, i]; } Common.printArray("Mid-3-1: Result: ", temp, ref sw); } else { for (int k = 0; k < mid3_1_Count; k++) { for (int i = 0; i < rd.Cols; i++) { temp[i] = mid3_1[k, i]; } Common.printArray("Mid-3-1-" + (k + 1).ToString() + ": Result: ", temp, ref sw); } } rank = new int[rd.Cols]; rlist.makeRankArray(ref rank); }
public Mid_4_1(ref RawData r) { rd = r; mid4_1 = new int[rd.Cols]; mx_mn = new double[rd.Cols]; rlist = new R1pnList(); Array.Clear(mid4_1, 0, mid4_1.Length); sw = new StreamWriter(Common.debugpath + "\\" + "MID4_1.txt"); Common.printArray("MID4_1 :Rawdata %SP ", rd.PerSP, ref sw); sw.WriteLine("MID4_1: Average %SP : " + rd.APerSP.ToString("#####0.00")); // make mx_mn array for (int i = 0; i < rd.Cols; i++) { mx_mn[i] = rd.APerSP - rd.PerSP[i]; } // get the most number out of + values. int index = Common.MaxIndex(ref mx_mn); double val = mx_mn[index]; R1pn r1 = new R1pn(10); for (Int16 i = 0; i < rd.Cols; i++) { if (mx_mn[i] == val) { mid4_1[i] = 1; r1.Add(i); } } rlist.Add(r1); Common.printArray("MID4_1 :first", mid4_1, ref sw); // get the least number out of - values; index = Common.MinIndex(ref mx_mn); val = mx_mn[index]; r1 = new R1pn(10); for (Int16 i = 0; i < rd.Cols; i++) { if (mx_mn[i] == val) { mid4_1[i] = 1; r1.Add(i); } } rlist.Add(r1); Common.printArray("MID4_1 :second", mid4_1, ref sw); // get the least number out of + values; index = Common.MinIndexOutofPlus(ref mx_mn); val = mx_mn[index]; r1 = new R1pn(10); for (Int16 i = 0; i < rd.Cols; i++) { if (mx_mn[i] == val) { mid4_1[i] = 1; r1.Add(i); } } rlist.Add(r1); Common.printArray("MID4_1 :third", mid4_1, ref sw); // get the most number out of - values; index = Common.MaxIndexOutofMinus(ref mx_mn); val = mx_mn[index]; r1 = new R1pn(10); for (Int16 i = 0; i < rd.Cols; i++) { if (mx_mn[i] == val) { mid4_1[i] = 1; r1.Add(i); } } rlist.Add(r1); Common.printArray("MID4_1 :MX/MN", mx_mn, ref sw); Common.printArray("MID4_1 :MID4_1", mid4_1, ref sw); rlist.print(ref sw); }
public void Run() { Array.Clear(mid2, 0, mid2.Length); for (Step = 0; Step < MaxStep; Step++) { Console.WriteLine("maxstep: {0}, current step:{1}", MaxStep, Step); rnext = null; rnext = new R1pnList(); R1pnList rsubset = new R1pnList(); sw.WriteLine(""); sw.WriteLine("NEW R1PN Start: step:" + Step + " 's R1pn List "); // make subset of the R1PN_X step. int indexofbaseR1pn = 0; foreach (R1pn r1 in rlist.rList) { r1.print(ref sw); MakeSubsetofR1pn(ref rsubset, indexofbaseR1pn, r1); indexofbaseR1pn++; } GC.Collect(); //sw.WriteLine(""); //sw.WriteLine("rsubset's List "); //rsubset.print(ref sw); // process each subset. int ccc = 0; foreach (R1pn r1 in rsubset.rList) { Find_Next_R1pn_Set(r1); ccc++; if (ccc < 0) { ccc = 0; } if (ccc % 100000 == 0) { Console.WriteLine("ccc: {0}", ccc); GC.Collect(); } } //sw.WriteLine(""); //sw.WriteLine("rnext's List "); //rnext.print(ref sw); // Remove Current R1pn_X List // Set Next R1pn_X1 List rlist.rList = null; rlist.rList = rnext.rList; //Common.printArray("MID2 :("+Step.ToString()+") ", mid2, ref sw); rnext = null; rsubset = null; GC.Collect(); } // count each pn how many times it comes in all of rlist temp = new int[mid2.Length]; rlist.FinalProcessing_PNS(ref temp); Common.printArray2("Temp :(temp,PN's count that is appeared in the List.) ", temp, ref sw); // then, sort the count by pn // choose highest pn count as much as tspn number. int[] temp2 = new int[mid2.Length]; Array.Copy(temp, temp2, temp.Length); Array.Sort(temp2); // Common.printArray2("Temp2 :(temp2, sort) ", temp2, ref sw); Array.Clear(mid2, 0, mid2.Length); int val = 0, flag = 0, count = 0; for (int i = temp2.Length - 1; i >= 0; i--) { if (flag == 1 || temp2[i] == 0) { break; } if (temp2[i] != val) { val = temp2[i]; } else { continue; } for (int j = 0; j < temp.Length; j++) { if (temp[j] == val) { mid2[j] = 1; count++; } if (count == rd.tpsn + 2) { flag = 1; break; } } } sw.WriteLine("Choose " + (rd.tpsn + 2).ToString("######0") + " PN's"); sw.WriteLine("Threshold Count: " + (val).ToString("######0")); Common.printArray("MID2 :(LAST) ", mid2, ref sw); Common.printIndex("MID2 INDEX Print :(LAST) ", mid2, ref sw); }