public void FirstPassTests() { Zakaz zak; StatsList actual; zak = new Zakaz(10000, 10000, 20000, 15000, 15000, 10000, 20000, 30000, 10000); actual = Analizer.FirstPass(zak); Assert.AreEqual(1, actual.Count, "FirstPass cannot split zakaz with count <= ETS_ON_SHEET"); Assert.AreEqual(10000, actual[0].Run, "Optimal run for this zakaz is 10000"); Assert.AreEqual(15, actual[0].EtsOnSheetCount, "For run 10000 ets on sheet count is 15"); Assert.AreEqual(5000 + 5000, actual[0].OverprintsSum, "For run 10000 overprint sum is 10000"); Assert.AreEqual(5000 + 5000 + 10000, actual[0].CorrectedOverprintsSum, "For run 10000 corrected overprint sum is 20000"); }
}//end:Main private static void Analyze(Zakaz ets) { Console.WriteLine("============================================"); Console.WriteLine("Given data: "); Console.WriteLine("\t"); foreach (Etyketka et in ets) { Console.Write("{0} ", et.Run); } Console.WriteLine(); Console.WriteLine("Results:"); //StatsList results = Analizer.ImproveStats(Analizer.FirstPass(ets)); //StatsList results2 = Analizer.ImproveStats(Analizer.SplitByGcd(ets)); //StatsList results3 = Analizer.ImproveStats(Analizer.PackIntoSheet(ets)); StatsList results = (Analizer.FirstPass(ets)); StatsList results2 = (Analizer.SplitByGcd(ets)); if (results > results2) { results = results2; } foreach (var r in results) { Console.WriteLine("\n\t{0}", r); foreach (var e in r.Ets) { Console.WriteLine("\t\t{0}", e); } } Console.WriteLine("============================================"); Console.WriteLine(); if (ets.Count <= Constants.ETS_ON_SHEET) { results = Analizer.FindBestRunWithShifting(ets); foreach (var r in results) { Console.WriteLine("\n\t{0}", r); foreach (var e in r.Ets) { Console.WriteLine("\t\t{0}", e); } } Console.WriteLine("============================================"); Console.WriteLine(); } }
}//end:printButton_Click /// <summary> /// Handles the click on the calculateButton. /// Calculates results and shows them in printPreview. /// </summary> private void calculateButton_Click(object sender, EventArgs e) { //Get input data to analize Zakaz z = new Zakaz(); if (!ParseDataTable(ref z)) { ShowErrorMessage("Немає даних для обчислення"); return; } //Analize data Dictionary <String, StatsList> results = new Dictionary <String, StatsList>(); results.Add("SplitFromMinToMax", Analizer.FirstPass(z)); results.Add("SplitByGcd", Analizer.SplitByGcd(z)); results.Add("FindBestRunWithShifting", Analizer.FindBestRunWithShifting(z)); //Setup initial values and text styles Font titleFont = new Font("Calibri", 10, FontStyle.Bold); Font textFont = new Font("Calibri", 10, FontStyle.Regular); Font addedTextFont = new Font("Calibri", 8, FontStyle.Regular); richTextBox.ResetText(); richTextBox.SelectionIndent = 5; richTextBox.SelectionRightIndent = 5; StringBuilder resultString; //Generate title richTextBox.SelectionFont = titleFont; richTextBox.SelectionAlignment = HorizontalAlignment.Center; richTextBox.AppendText("Аналіз замовлення\n"); resultString = new StringBuilder(); resultString.Append(DateTime.Now.ToLongDateString()); resultString.Append(" / "); resultString.Append(DateTime.Now.ToLongTimeString()); resultString.Append("\n"); resultString.Append(string.Format("В замовленні {0} етикеток.", (from et in z select et.Run).Sum())); resultString.Append(" Наклади етикеток: "); foreach (Etyketka et in z) { resultString.Append(string.Format("{0} ", et.Run)); } resultString.Append("\n\n"); richTextBox.SelectionFont = addedTextFont; richTextBox.SelectionAlignment = HorizontalAlignment.Left; richTextBox.AppendText(resultString.ToString()); //Generate results foreach (var item in results) { richTextBox.SelectionFont = titleFont; richTextBox.SelectionAlignment = HorizontalAlignment.Left; richTextBox.AppendText(string.Format("Результати за алгоритмом {0} (спусків {1}, передрук {2} тис. етикеток).\n", item.Key, item.Value.Count, ((float)(item.Value.OverprintsSum)) / 1000)); int spuskCounter = 1; foreach (var r in item.Value) { richTextBox.SelectionFont = textFont; richTextBox.AppendText(string.Format("Спуск №{0}. Зайнято {1} з {2} позицій на спуску. Наклад {3} аркушів. Передрук {4} етикеток.\n", spuskCounter++, r.EtsOnSheetCount, Constants.ETS_ON_SHEET, r.Run, r.OverprintsSum)); resultString = new StringBuilder(); resultString.Append(string.Format("\t№ позицій передрук (наклад) назва\n")); foreach (var et in r.Ets) { resultString.Append(string.Format("\t{1} \t{3} \t{4} \t({2}) \t{0}.\n", et.Name, et.Id, et.Run, et.CountOnSheet, et.Overprint)); } richTextBox.SelectionFont = addedTextFont; richTextBox.AppendText(resultString.ToString()); } richTextBox.AppendText("\n"); } }//end:calculateButton_Click