Exemplo n.º 1
0
        private void MDS_Click(object sender, EventArgs e)
        {
            label1.Text = "Start MDS";
            label1.Update();

            DialogResult  result       = OpenPropDialog();
            List <string> prop_files   = new List <string>();
            List <string> filter_files = new List <string>();
            List <int>    k_values     = new List <int>();

            if (result == DialogResult.OK)
            {
                prop_files.Clear();
                filter_files.Clear();

                int counter = 0;
                foreach (String file in openFileDialog1.FileNames)
                {
                    string idk            = file.Split('\\').Last().Split('_').Last().Split('.').First();
                    string prop           = file.Split('\\').Last().Split('_').First();
                    int    splitted_paths = file.Split('\\').Last().Length;

                    string path = file.Substring(0, file.Length - splitted_paths);
                    path = path + prop.ToString() + '\\' + "k_" + idk.ToString() + ".filter";

                    prop_files.Add(file);

                    filter_files.Add(path);
                    k_values.Add(Int32.Parse(idk));

                    counter++;
                }

                CppWrapper.CppDistanceProp distance_prop_eval = new CppWrapper.CppDistanceProp();
                distance_prop_eval.SetMapSize(model_size[0], model_size[1]);
                input_property = distance_prop_eval.SetInputFilePaths(prop_files.ToArray(), filter_files.ToArray(), k_values.ToArray());

                double[,] array = distance_prop_eval.GetDistances();

                CppWrapper.CppMDSWrapper eval_MDS = new CppWrapper.CppMDSWrapper(array, counter);
                double[,] arrayMDS = eval_MDS.GetMDS();

                Chart chart = new Chart();
                chart = chart1;
                chart.Series[0].Points.Clear();
                //chart.Series[2].Points.Clear();

                for (int i = 0; i < counter; i++)
                {
                    string name = prop_files[i].Split('\\').Last();
                    chart.Series[0].Points.AddXY(Math.Round(arrayMDS[i, 0], 5), Math.Round(arrayMDS[i, 1], 5));
                    chart.Series[0].Points[i].LegendToolTip = name;
                    chart.Series[0].Points[i].Tag           = prop_files[i];
                    chart.Series[0].Points[i].ToolTip       = name + "\n X= " + arrayMDS[i, 0] + " Y = " + arrayMDS[i, 1];
                }
            }

            label1.Text = "Finished MDS";
            label1.Update();
        }
Exemplo n.º 2
0
        private void CallMDSWithMultiPropAndCFG(object sender, EventArgs e)
        {
            Chart chart = chart1;

            label1.Text = "Start CFG MultiProp MDS";
            label1.Update();
            DialogResult result = OpenCFGMultiPropDialog();

            if (result == DialogResult.OK)
            {
                String file_path_name = openFileDialog1.FileName;

                // Get filename path
                int    splitted_paths = file_path_name.Split('\\').Last().Length;
                string filename_path  = file_path_name.Substring(0, file_path_name.Length - splitted_paths);

                // Get lines
                var lines = File.ReadAllLines(openFileDialog1.FileName);

                model_path = file_path_name;

                // Get "Model Name" and "Model Sizes"
                System.IO.StreamReader file = new System.IO.StreamReader(model_path);

                input_prop_type = int.Parse(lines[0]);

                model_name  = lines[1];
                label2.Text = model_name;
                label2.Update();

                model_size[0] = int.Parse(lines[2]);
                model_size[1] = int.Parse(lines[3]);
                model_size[2] = int.Parse(lines[4]);

                label3.Text = model_size[0] + " " + model_size[1] + " " + model_size[2];
                label3.Update();

                file.Close();

                // Get number of properties
                number_of_properties = int.Parse(lines[5]);

                label4.Text = number_of_properties + " properties:";

                min_max_property = null;
                min_max_property = new double[number_of_properties, 2];

                loaded_properties = null;
                loaded_properties = new string[number_of_properties];

                // Get number of cases
                int number_of_cases = int.Parse(lines[6]);
                global_n_of_cases = number_of_cases;

                original_xy_cases = null;
                original_xy_cases = new double[global_n_of_cases, 2];

                // Get path properties
                string multiprop_path = lines[7];

                // Distance Prop Class
                CppWrapper.CppDistanceProp distance_prop_eval = new CppWrapper.CppDistanceProp();
                distance_prop_eval.SetEnvironmentType(1);
                distance_prop_eval.SetNumberOfPropertiesAndCases(number_of_properties, number_of_cases);
                distance_prop_eval.SetMapSize(model_size[0], model_size[1]);

                List <string> prop_files = new List <string>();
                for (int i = 0; i < number_of_properties; i++)
                {
                    string prop = lines[8 + i * 3];
                    double min  = double.Parse(lines[8 + i * 3 + 1]);
                    double max  = double.Parse(lines[8 + i * 3 + 2]);

                    Console.Out.WriteLine("Propriedade " + (i + 1) + ":\n - " + prop + " between [" + min + ", " + max + "]");
                    label4.Text          = label4.Text + " \"" + prop + "\"";
                    loaded_properties[i] = prop;

                    prop_files.Clear();
                    for (int cases_files = 0; cases_files < number_of_cases; cases_files++)
                    {
                        prop_files.Add(filename_path + multiprop_path + "\\" + prop + "\\" + prop + "_" + (cases_files + 1) + ".prop");
                    }

                    // Return Property
                    double[] ret_input = distance_prop_eval.SetMultiProjectionInputFilePaths(
                        input_prop_type
                        , i
                        , prop_files.ToArray()
                        , min
                        , max
                        );

                    min_max_property[i, 0] = ret_input[0];
                    min_max_property[i, 1] = ret_input[1];

                    Console.Out.WriteLine(" - Min: " + min_max_property[i, 0] + ", Max: " + min_max_property[i, 1]);
                }

                model_path = filename_path + multiprop_path;

                double[,] array = distance_prop_eval.GetDistances();

                CppWrapper.CppMDSWrapper eval_MDS = new CppWrapper.CppMDSWrapper(array, number_of_cases);
                double[,] arrayMDS = eval_MDS.GetMDS();

                chart.Series[0].Points.Clear();

                double[] min_max_axis_limits = new Double[4];
                min_max_axis_limits[0] = Double.MaxValue;
                min_max_axis_limits[1] = Double.MinValue;
                min_max_axis_limits[2] = Double.MaxValue;
                min_max_axis_limits[3] = Double.MinValue;

                double expand_limtis = 1.2;

                for (int i = 0; i < number_of_cases; i++)
                {
                    string name = prop_files[i].Split('\\').Last();

                    double mm_x = arrayMDS[i, 0]; //Math.Round(arrayMDS[i, 0], 5);
                    double mm_y = arrayMDS[i, 1]; //Math.Round(arrayMDS[i, 1], 5);

                    chart.Series[0].Points.AddXY(mm_x, mm_y);
                    original_xy_cases[i, 0] = mm_x;
                    original_xy_cases[i, 1] = mm_y;


                    chart.Series[0].Points[i].LegendToolTip = "loadedpoint";
                    chart.Series[0].Points[i].Tag           = (i + 1).ToString();
                    chart.Series[0].Points[i].ToolTip       = "Case " + (i + 1) + "\n X= " + arrayMDS[i, 0] + " Y = " + arrayMDS[i, 1];
                    if (this.controlpoints_state.Checked)
                    {
                        chart.Series[0].Points[i].Color = Color.Red;
                    }
                    else
                    {
                        chart.Series[0].Points[i].Color = Color.Blue;
                    }

                    min_max_axis_limits[0] = Math.Min(min_max_axis_limits[0], mm_x);
                    min_max_axis_limits[1] = Math.Max(min_max_axis_limits[1], mm_x);

                    min_max_axis_limits[2] = Math.Min(min_max_axis_limits[2], mm_y);
                    min_max_axis_limits[3] = Math.Max(min_max_axis_limits[3], mm_y);
                }

                min_max_axis_limits[0] *= expand_limtis;
                min_max_axis_limits[1] *= expand_limtis;

                min_max_axis_limits[2] *= expand_limtis;
                min_max_axis_limits[3] *= expand_limtis;

                chart.ChartAreas[0].AxisX.Minimum = min_max_axis_limits[0];
                chart.ChartAreas[0].AxisX.Maximum = min_max_axis_limits[1];

                chart.ChartAreas[0].AxisY.Minimum = min_max_axis_limits[2];
                chart.ChartAreas[0].AxisY.Maximum = min_max_axis_limits[3];
            }

            label4.Update();

            label1.Text = "Finished CFG MultiProp MDS";
            label1.Update();
        }
Exemplo n.º 3
0
        private void BuildMDSToChart(Chart chart, int chart_index)
        {
            label1.Text = "Start MDS";
            label1.Update();

            DialogResult  result       = OpenPropDialog();
            List <string> prop_files   = new List <string>();
            List <string> filter_files = new List <string>();
            List <int>    k_values     = new List <int>();

            if (result == DialogResult.OK)
            {
                prop_files.Clear();
                filter_files.Clear();

                int counter = 0;
                foreach (String file in openFileDialog1.FileNames)
                {
                    string idk            = file.Split('\\').Last().Split('_').Last().Split('.').First();
                    string prop           = file.Split('\\').Last().Split('_').First();
                    int    splitted_paths = file.Split('\\').Last().Length;

                    string path = file.Substring(0, file.Length - splitted_paths);
                    path = path + prop.ToString() + '\\' + "k_" + idk.ToString() + ".filter";

                    prop_files.Add(file);

                    filter_files.Add(path);
                    k_values.Add(Int32.Parse(idk));

                    counter++;
                }

                CppWrapper.CppDistanceProp distance_prop_eval = new CppWrapper.CppDistanceProp();
                distance_prop_eval.SetMapSize(model_size[0], model_size[1]);

                double[] ret_property = distance_prop_eval.SetInputFilePaths(prop_files.ToArray(), filter_files.ToArray(), k_values.ToArray());

                input_property[chart_index, 0] = ret_property[0];
                input_property[chart_index, 1] = ret_property[1];

                double[,] array = distance_prop_eval.GetDistances();

                CppWrapper.CppMDSWrapper eval_MDS = new CppWrapper.CppMDSWrapper(array, counter);
                double[,] arrayMDS = eval_MDS.GetMDS();

                chart.Series[0].Points.Clear();
                //chart.Series[2].Points.Clear();

                double[] min_max_axis_limits = new Double[4];
                min_max_axis_limits[0] = Double.MaxValue;
                min_max_axis_limits[1] = Double.MinValue;
                min_max_axis_limits[2] = Double.MaxValue;
                min_max_axis_limits[3] = Double.MinValue;

                double expand_limtis = 1.2;

                for (int i = 0; i < counter; i++)
                {
                    string name = prop_files[i].Split('\\').Last();

                    double mm_x = Math.Round(arrayMDS[i, 0], 5);
                    double mm_y = Math.Round(arrayMDS[i, 1], 5);

                    chart.Series[0].Points.AddXY(mm_x, mm_y);

                    chart.Series[0].Points[i].LegendToolTip = name;
                    chart.Series[0].Points[i].Tag           = prop_files[i];
                    chart.Series[0].Points[i].ToolTip       = name + "\n X= " + arrayMDS[i, 0] + " Y = " + arrayMDS[i, 1];
                    chart.Series[0].Points[i].Color         = Color.Blue;

                    min_max_axis_limits[0] = Math.Min(min_max_axis_limits[0], mm_x);
                    min_max_axis_limits[1] = Math.Max(min_max_axis_limits[1], mm_x);

                    min_max_axis_limits[2] = Math.Min(min_max_axis_limits[2], mm_y);
                    min_max_axis_limits[3] = Math.Max(min_max_axis_limits[3], mm_y);
                }

                min_max_axis_limits[0] *= expand_limtis;
                min_max_axis_limits[1] *= expand_limtis;

                min_max_axis_limits[2] *= expand_limtis;
                min_max_axis_limits[3] *= expand_limtis;

                chart.ChartAreas[0].AxisX.Minimum = min_max_axis_limits[0];
                chart.ChartAreas[0].AxisX.Maximum = min_max_axis_limits[1];

                chart.ChartAreas[0].AxisY.Minimum = min_max_axis_limits[2];
                chart.ChartAreas[0].AxisY.Maximum = min_max_axis_limits[3];
            }

            label1.Text = "Finished MDS";
            label1.Update();
        }