Exemple #1
0
        /// <summary>
        /// SHow Asignment Problem data in grid
        /// </summary>
        /// <param name="data"></param>
        private void FillGridWithAPData(double[][] data)
        {
            //clear the list first
            listView1.Clear();
            listView1.GridLines     = true;
            listView1.HideSelection = false;

            int numCol = data[0].Length;
            int numRow = data.Length;

            ColumnHeader colHeader = new ColumnHeader();

            colHeader.Text  = "Pos";
            colHeader.Width = 50;
            listView1.Columns.Add(colHeader);
            AlphaCharEnum alphaEnum = new AlphaCharEnum();

            for (int i = 0; i < numCol; i++)
            {
                colHeader      = new ColumnHeader();
                colHeader.Text = alphaEnum.AlphabetFromIndex(i + 1);

                colHeader.Width = 50;
                listView1.Columns.Add(colHeader);
            }

            for (int j = 0; j < numRow; j++)
            {
                ListViewItem LVI = listView1.Items.Add("A" + (j + 1).ToString());

                for (int i = 0; i < numCol; i++)
                {
                    if (data[j][i] == double.MaxValue)
                    {
                        LVI.SubItems.Add("M");
                    }
                    else if (data[j][i] == double.MinValue)
                    {
                        LVI.SubItems.Add("L");
                    }
                    else
                    {
                        LVI.SubItems.Add(data[j][i].ToString());
                    }
                }
            }
        }
        public static void Export(List <List <string> > dataTrain, List <List <string> > dataTest, string strFilePath, string excelFormula, bool autoheader)
        {
            try
            {
                //
                var ace = new AlphaCharEnum();
                var wb  = new XLWorkbook();
                var ws1 = wb.Worksheets.Add("TRAINING DATA");
                var ws2 = wb.Worksheets.Add("VALIDATION DATA");
                ws1.Cell(1, 1).Value = "Training Data";
                if (dataTest != null)
                {
                    ws2.Cell(1, 1).Value = "Validation Data";
                }

                writeDataToExcel(dataTrain, ws1, autoheader);

                if (dataTest != null)
                {
                    writeDataToExcel(dataTest, ws2, autoheader);
                }

                var ind = ace.AlphabetFromIndex(dataTrain[0].Count - 1) + "3";

                //column name for model output
                var colCount    = dataTrain[0].Count;
                var ouputColumn = dataTrain[0][colCount - 1].Replace("_actual", "_predicted");
                ws1.Cell(2, dataTrain[0].Count + 1).Value = ouputColumn;
                ws1.Cell(3, dataTrain[0].Count + 1).Value = string.Format(excelFormula, "A3", ind);
                if (dataTest != null)
                {
                    ws1.Cell(2, dataTrain[0].Count + 1).Value = ouputColumn;
                    ws2.Cell(3, dataTrain[0].Count + 1).Value = string.Format(excelFormula, "A3", ind);
                }

                //
                wb.SaveAs(strFilePath, false);
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemple #3
0
        public static void Export(List <List <string> > dataTrain, List <List <string> > dataValid, List <List <string> > dataTest, string strFilePath, string excelFormula, bool autoheader, List <string> outputClasses = null)
        {
            try
            {
                //
                var          ace = new AlphaCharEnum();
                var          wb  = new XLWorkbook();
                var          ws1 = wb.Worksheets.Add("Training");
                IXLWorksheet ws2 = null;
                //IXLWorksheet ws3 = null;
                ws1.Cell(1, 1).Value = "Training Data";

                if (dataValid != null && dataValid.Count > 0)
                {
                    ws2 = wb.Worksheets.Add("Validation");
                    ws2.Cell(1, 1).Value = "Validation Data";
                }
                //if (dataTest != null && dataTest.Count > 0)
                //{
                //    ws3 = wb.Worksheets.Add("Test");
                //    ws3.Cell(1, 1).Value = "Test Data";
                //}


                writeDataToExcel(dataTrain, ws1, autoheader);

                if (dataValid != null && dataValid.Count > 0)
                {
                    writeDataToExcel(dataValid, ws2, autoheader);
                }

                //if (dataTest != null && dataTest.Count > 0)
                //    writeDataToExcel(dataTest, ws3, autoheader);


                var ind = ace.AlphabetFromIndex(dataTrain[0].Count - 1) + "3";

                //column name for model output
                var colCount    = dataTrain[0].Count;
                var ouputColumn = dataTrain[0][colCount - 1].Replace("_actual", "_predicted");

                //write output column for training sheet
                ws1.Cell(2, dataTrain[0].Count + 1).Value = ouputColumn;
                ws1.Cell(3, dataTrain[0].Count + 1).Value = string.Format(excelFormula, "A3", ind);
                //write output classes on training sheet
                if (outputClasses != null && outputClasses.Count > 1)
                {
                    writeOutputClasses(ws1, dataTrain[0].Count, outputClasses);
                }


                if (dataValid != null && dataValid.Count > 0)
                {
                    //write output column name for validation sheet
                    ws2.Cell(2, dataValid[0].Count + 1).Value = ouputColumn;
                    //write formula
                    ws2.Cell(3, dataValid[0].Count + 1).Value = string.Format(excelFormula, "A3", ind);

                    //write output classes on validation sheet
                    if (outputClasses != null && outputClasses.Count > 1)
                    {
                        writeOutputClasses(ws2, dataValid[0].Count, outputClasses);
                    }
                }

                //if (dataTest != null && dataTest.Count > 0)
                //{
                //    //write output column name for validation sheet
                //    ws3.Cell(2, dataTest[0].Count + 1).Value = ouputColumn;
                //    //write formula
                //    ws3.Cell(3, dataTest[0].Count + 1).Value = string.Format(excelFormula, "A3", ind);

                //    //write output classes on validation sheet
                //    if (outputClasses != null && outputClasses.Count > 1)
                //        writeOutputClasses(ws3, dataTest[0].Count, outputClasses);
                //}
                //
                wb.SaveAs(strFilePath, false);
            }
            catch (Exception)
            {
                throw;
            }
        }