public Mid_4_2(ref RawData raw, ref Mid_4_1 mid4_1) { rd = raw; this.md41 = mid4_1; sw = new StreamWriter(Common.debugpath + "\\" + "MID4_2.txt"); //Make Count MX/MN Table Count_MxMn = new int[rd.Rows, 4]; Sumval = new int[4]; Avg = new double[4]; Array.Clear(Avg, 0, Avg.Length); digit = new int[4]; Array.Clear(digit, 0, digit.Length); for (int i = 0; i < rd.Rows; i++) { for (int j = 0; j < 4; j++) { Count_MxMn[i, j] = 0; } } int Cols = 0, pn; foreach (R1pn r1 in md41.rlist.rList) { for (int i = 0; i < r1.cp; i++) { pn = r1.r1pn[i]; for (int j = 0; j < rd.Rows; j++) { if (rd.rawdata[j, pn] > 0) { Count_MxMn[j, Cols]++; } } } Cols++; } // Make Average double sum; for (int i = 0; i < 4; i++) { sum = 0; for (int j = 0; j < rd.Rows; j++) { sum += Count_MxMn[j, i]; } Sumval[i] = (int)sum; Avg[i] = sum / rd.Rows; } // get Digits for (int i = 0; i < 4; i++) { digit[i] = (int)(Avg[i] + 0.5); } printTable(ref sw); }
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); }
private void timer1_Tick(object sender, EventArgs e) { if (step == 0) //Mid-1 { timer1.Enabled = false; // make SPC data. rd.makeSPC_PerSP_APerSP(); rd.printSPC_PerSP_APerSP(); // make Mid-1 md1 = new Mid_1(ref rd); md1.printMid1(); string str = txtCurDir.Text + "\\" + cmbJoblist.SelectedItem.ToString(); if (File.Exists(str)) { md1.printToExcel(str, "Mid-1"); } md1.Close(); timer1.Enabled = true; GC.Collect(); StatusProgress.Value = 1 * 100 / 10; statusLabel1.Text = "Mid-2 Start..............."; } else if (step == 1) //Mid-2 { timer1.Enabled = false; md2 = new Mid_2(ref rd, ref md1); md2.Run(); string str = txtCurDir.Text + "\\" + cmbJoblist.SelectedItem.ToString(); if (File.Exists(str)) { md2.printToExcel(str, "Mid-2"); } md2.Close(); timer1.Enabled = true; GC.Collect(); StatusProgress.Value = 2 * 100 / 10; statusLabel1.Text = "Mid3-1 Start..............."; } else if (step == 2) //Mid3-1 { timer1.Enabled = false; md3_1 = new Mid_3_1(ref rd); string str = txtCurDir.Text + "\\" + cmbJoblist.SelectedItem.ToString(); if (File.Exists(str)) { md3_1.printToExcel(str, "Mid3-1"); } md3_1.Close(); timer1.Enabled = true; GC.Collect(); StatusProgress.Value = 3 * 100 / 10; statusLabel1.Text = "Mid3-2 Start..............."; } else if (step == 3)//Mid3-2 { timer1.Enabled = false; md3_2 = new Mid_3_2(ref rd); string str = txtCurDir.Text + "\\" + cmbJoblist.SelectedItem.ToString(); if (File.Exists(str)) { md3_2.printToExcel(str, "Mid3-2"); } md3_2.Close(); timer1.Enabled = true; GC.Collect(); StatusProgress.Value = 4 * 100 / 10; statusLabel1.Text = "Mid3-3 Start..............."; } else if (step == 4) //Mid3-3 { timer1.Enabled = false; md3_3 = new Mid_3_3(ref rd); string str = txtCurDir.Text + "\\" + cmbJoblist.SelectedItem.ToString(); if (File.Exists(str)) { md3_3.printToExcel(str, "Mid3-3"); } md3_3.Close(); timer1.Enabled = true; GC.Collect(); StatusProgress.Value = 5 * 100 / 10; statusLabel1.Text = "Mid3-4 Start..............."; } else if (step == 5) //Mid3-4 { timer1.Enabled = false; md3_4 = new Mid_3_4(ref md3_3); string str = txtCurDir.Text + "\\" + cmbJoblist.SelectedItem.ToString(); if (File.Exists(str)) { md3_4.printToExcel(str, "Mid3-4"); } md3_4.Close(); timer1.Enabled = true; GC.Collect(); StatusProgress.Value = 6 * 100 / 10; statusLabel1.Text = "Mid4-1 Start..............."; } else if (step == 6)//Mid4-1 { timer1.Enabled = false; md4_1 = new Mid_4_1(ref rd); string str = txtCurDir.Text + "\\" + cmbJoblist.SelectedItem.ToString(); if (File.Exists(str)) { md4_1.printToExcel(str, "Mid4-1"); } md4_1.Close(); timer1.Enabled = true; GC.Collect(); StatusProgress.Value = 7 * 100 / 10; statusLabel1.Text = "Mid4-2 Start..............."; } else if (step == 7)//Mid4-2 { timer1.Enabled = false; md4_2 = new Mid_4_2(ref rd, ref md4_1); string str = txtCurDir.Text + "\\" + cmbJoblist.SelectedItem.ToString(); if (File.Exists(str)) { md4_2.printToExcel(str, "Mid4-2"); } md4_2.Close(); timer1.Enabled = true; GC.Collect(); StatusProgress.Value = 8 * 100 / 10; statusLabel1.Text = "Mid4-3 Start..............."; } else if (step == 8)//Mid4-3 { timer1.Enabled = false; md4_3 = new Mid_4_3_new1(ref rd, ref md4_1, ref md4_2); string str = txtCurDir.Text + "\\" + cmbJoblist.SelectedItem.ToString(); if (File.Exists(str)) { md4_3.printToExcel(str, "Mid4-3"); } md4_3.Close(); timer1.Enabled = true; GC.Collect(); StatusProgress.Value = 9 * 100 / 10; statusLabel1.Text = "ResultDB Start..............."; } else if (step == 9)//Result DB { timer1.Enabled = false; resDB = new ResultDB(this); string str = txtCurDir.Text + "\\" + cmbJoblist.SelectedItem.ToString(); if (File.Exists(str)) { resDB.printToExcel(str, "Result DB"); } resDB.Close(); timer1.Enabled = true; GC.Collect(); StatusProgress.Value = 10 * 100 / 10; } else if (step == 10) { StatusProgress.Value = 100; statusLabel1.Text = "Completion"; timer1.Enabled = false; GOSTOP = false; btnCalc.Text = "GO"; cmbJoblist.Enabled = true; button1.Enabled = true; btnReload.Enabled = true; step = 0; GC.Collect(); } step++; }
public Mid_4_3_new1(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"); MXPlus = new double[rd.Cols]; MXMinus = new double[rd.Cols]; MXPlusPN = new int[rd.Cols]; MXMinusPN = new int[rd.Cols]; MXPlusCount = 0; MXMinusCount = 0; MXavg = 0; MNAvg = 0; for (int i = 0; i < md41.mx_mn.Length; i++) { if (md41.mx_mn[i] > 0) { MXPlusPN[MXPlusCount] = i; MXPlus[MXPlusCount++] = md41.mx_mn[i]; MXavg += md41.mx_mn[i]; } else if (md41.mx_mn[i] < 0) { MXMinusPN[MXMinusCount] = i; MXMinus[MXMinusCount++] = Math.Abs(md41.mx_mn[i]); MNAvg += Math.Abs(md41.mx_mn[i]); } } MXavg = MXavg / MXPlusCount; MNAvg = MNAvg / MXMinusCount; MXselectCount = 0; MNselectCount = 0; MXselectPN = new int[MXPlusCount]; MNselectPN = new int[MXMinusCount]; MXPlusDiff = new double[MXPlusCount]; MXMinusDiff = new double[MXMinusCount]; for (int i = 0; i < MXPlusCount; i++) { MXPlusDiff[i] = Math.Abs(MXPlus[i] - MXavg); } for (int i = 0; i < MXMinusCount; i++) { MXMinusDiff[i] = Math.Abs(MXMinus[i] - MNAvg); } double min1 = Double.MaxValue, min2 = Double.MaxValue; for (int i = 0; i < MXPlusCount; i++) { if (MXPlusDiff[i] < min1) { min1 = MXPlusDiff[i]; } } for (int i = 0; i < MXMinusCount; i++) { if (MXMinusDiff[i] < min2) { min2 = MXMinusDiff[i]; } } for (int i = 0; i < MXPlusCount; i++) { if (MXPlusDiff[i] == min1) { MXselectPN[MXselectCount] = MXPlusPN[i]; MXselectCount++; mid4_3[MXPlusPN[i]] = 1; } } for (int i = 0; i < MXMinusCount; i++) { if (MXMinusDiff[i] == min2) { MNselectPN[MNselectCount] = MXMinusPN[i]; MNselectCount++; mid4_3[MXMinusPN[i]] = 1; } } /* * // MX%SP * lower1 = MXavg * (1 - variation); * upper1 = MXavg * (1 + variation); * for (int i = 0; i < MXPlusCount; i++) * { * if (MXPlus[i] >= lower1 && MXPlus[i] <= upper1) * { * MXselectPN[MXselectCount] = MXPlusPN[i]; MXselectCount++; * mid4_3[MXPlusPN[i]] = 1; * } * } * // MN%SP * lower2 = MNAvg * (1 - variation); * upper2 = MNAvg * (1 + variation); * for (int i = 0; i < MXMinusCount; i++) * { * if (MXMinus[i] >= lower2 && MXMinus[i] <= upper2) * { * MNselectPN[MNselectCount] = MXMinusPN[i]; MNselectCount++; * mid4_3[MXMinusPN[i]] = 1; * } * } */ // Print Data // MX List string one = ""; sw.WriteLine("MX PN List : (PN, %SP) , Count: " + MXPlusCount.ToString()); for (int i = 0; i < MXPlusCount; i++) { one = one + "(" + (MXPlusPN[i] + 1).ToString() + ":" + MXPlus[i].ToString("#####0.00") + ") "; if (i > 0 && i % 5 == 0) { sw.WriteLine(one); one = ""; } } if (one != "") { sw.WriteLine(one); } // MN List sw.WriteLine(); one = ""; sw.WriteLine("MN PN List : (PN, %SP), Count: " + MXMinusCount.ToString()); for (int i = 0; i < MXMinusCount; i++) { one = one + "(" + (MXMinusPN[i] + 1).ToString() + ":" + (MXMinus[i] * -1).ToString("#####0.00") + ") "; if (i > 0 && i % 5 == 0) { sw.WriteLine(one); one = ""; } } if (one != "") { sw.WriteLine(one); } sw.WriteLine(); // average //sw.WriteLine("AveMX%SP =" + MXavg.ToString("#######0.00") + " Range:+/-" + (variation*100).ToString() + "% (" + lower1.ToString("######0.00") + "~" + upper1.ToString("######0.00") + ")"); //sw.WriteLine("AveMN%SP =" + (MNAvg * -1).ToString("#######0.00") + " Range:+/-" + (variation * 100).ToString() + "% (" + (lower2*-1).ToString("######0.00") + "~" + (upper2*-1).ToString("######0.00") + ")"); sw.WriteLine("AveMX%SP =" + MXavg.ToString("#######0.00")); sw.WriteLine("AveMN%SP =" + (MNAvg * -1).ToString("#######0.00")); sw.WriteLine(); // Difference table one = ""; sw.WriteLine("MX PN List : Difference Table , Count: " + MXPlusCount.ToString()); for (int i = 0; i < MXPlusCount; i++) { one = one + "(" + (MXPlusPN[i] + 1).ToString() + ":" + (MXPlus[i] - MXavg).ToString("#####0.00") + ") "; if (Math.Abs(MXPlus[i] - MXavg) == min1) { one = one + "** "; } if (i > 0 && i % 5 == 0) { sw.WriteLine(one); one = ""; } } if (one != "") { sw.WriteLine(one); } // MN List sw.WriteLine(); one = ""; sw.WriteLine("MN PN List : Difference Table , Count: " + MXMinusCount.ToString()); for (int i = 0; i < MXMinusCount; i++) { one = one + "(" + (MXMinusPN[i] + 1).ToString() + ":" + (MXMinus[i] - MNAvg).ToString("#####0.00") + ") "; if (Math.Abs(MXMinus[i] - MNAvg) == min2) { one = one + "** "; } if (i > 0 && i % 5 == 0) { sw.WriteLine(one); one = ""; } } if (one != "") { sw.WriteLine(one); } sw.WriteLine(); // pn list sw.WriteLine(); sw.Write("MX%SP Selected PNs' List : "); one = ""; for (int i = 0; i < MXselectCount; i++) { one = one + (MXselectPN[i] + 1).ToString() + " "; } sw.WriteLine(one); sw.Write("MN%SP Selected PNs' List : "); one = ""; for (int i = 0; i < MNselectCount; i++) { one = one + (MNselectPN[i] + 1).ToString() + " "; } sw.WriteLine(one); sw.WriteLine(); Common.printArray("MID4_3 :MID4_3", mid4_3, ref sw); }