Esempio n. 1
0
 public MainWindow()
 {
     InitializeComponent();
     this.isoLP = new IsomorphismLP();
     init();
 }
Esempio n. 2
0
        private bool runTestByMethode(int graphType, int methode, int noOfNodes)
        {
            string methodeName = "", solverType = "", formulaType = "";
            int    mode = 0;

            switch (methode)
            {
            case 1:
                methodeName = "F1bCplexUnCoeur";
                solverType  = "CPLEX";
                formulaType = "IsoGraphInexactF1b";
                mode        = 0;
                break;

            case 2:
                methodeName = "F1bCplexPlusieursCoeurs";
                solverType  = "CPLEX";
                formulaType = "IsoGraphInexactF1b";
                mode        = 1;
                break;

            case 3:
                methodeName = "F2bCPLEXUnCoeur";
                solverType  = "CPLEX";
                formulaType = "IsoGraphInexactF2b";
                mode        = 0;
                break;

            case 4:
                methodeName = "F2bCplexPlusieursCoeurs";
                solverType  = "CPLEX";
                formulaType = "IsoGraphInexactF2b";
                mode        = 1;
                break;

            case 5:
                methodeName = "F1bGlpkUnCoeur";
                solverType  = "GLPK";
                formulaType = "IsoGraphInexactF1b";
                mode        = 0;
                break;

            case 6:
                methodeName = "F2bGlpkUnCoeur";
                solverType  = "GLPK";
                formulaType = "IsoGraphInexactF2b";
                mode        = 0;
                break;

            case 7:
                methodeName = "BranchAndBound";
                solverType  = "GLPK";
                formulaType = "EditPath";
                mode        = 0;
                break;

            case 10:
                methodeName = "GEDBLPjusticehero";
                solverType  = "CPLEX";
                formulaType = "BLPjusticehero";
                mode        = 0;
                break;

            case 11:
                methodeName = "BLPjusticeheroQuadratic";
                solverType  = "CPLEX";
                formulaType = "BLPjusticeheroQuadratic";
                mode        = 0;
                break;

            case 12:
                methodeName = "QAPGMGED";
                solverType  = "CPLEX";
                formulaType = "QAPGMGED";
                mode        = 0;
                break;
            }

            string strToWrite = "";

            for (int i = 0; i < classMap.Count; i++)
            {
                for (int j = 0; j < classMap.Count; j++)
                {
                    try
                    {
                        this.graph1 = GraphLibManager.LoadGraph((classMap[i][0]), graphType);    //LoadGraph(this.richTextGraph, this.toolStripStatusTestLabel);
                        this.graph2 = GraphLibManager.LoadGraph(classMap[j][0], graphType);
                        Console.Out.WriteLine("i:" + i + "---> j : " + j);
                        Console.Out.WriteLine(graph1.Id + "--->" + graph2.Id);
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show("Ne peut pas charger les graphes." + e);
                        return(false);
                    }

                    if ((graph1 == null) || (graph2 == null))
                    {
                        j++;                                          //jump the wrong .gxl if exist
                    }
                    else if (this.graph1.IsDirected ^ this.graph2.IsDirected)
                    {
                        j++;
                    }
                    else
                    {
                        /* if (!(this.graph1.IsDirected) && !(this.graph2.IsDirected))
                         * {
                         *   GraphLibManager.transToDirectedGraph(this.graph1,false);
                         *   GraphLibManager.transToDirectedGraph(this.graph2,false);
                         *   this.flagTransform = true;
                         * }*/
                        this.flagTransform = false;
                        this.iso           = new IsomorphismLP();

                        iso.Graph1 = this.graph1;
                        iso.Graph2 = this.graph2;

                        iso.DirectedGraph1 = this.graph1;
                        iso.DirectedGraph2 = this.graph2;

                        this.iso.SolverType  = solverType;   //this.comboBoxSolveur2.SelectedIndex == 0 ? "CPLEX" : "GLPK";
                        this.iso.FormulaType = formulaType;  // Program.formulas[formulaTypeIndice];//Program.formulas[this.comboBoxProblem2.SelectedIndex];

                        this.iso.initial();
                        Program.nbCoeursCplex = int.Parse(textBoxnbthread.Text);
                        this.iso.Solver.setThreadNumber(Program.nbCoeursCplex);

                        /*if (mode == 0)
                         *  this.iso.Solver.setThreadNumber(1);
                         * else if (mode == 1)
                         *  this.iso.Solver.setThreadNumber(Program.nbCoeursCplex);*/

                        iso.run();
                        try
                        {
                            fs         = new FileStream(csvPath + "\\result" + this.graphTypeStr + noOfNodes + "nodes.csv", System.IO.FileMode.Append, System.IO.FileAccess.Write);
                            monStream  = new StreamWriter(fs, this.outputEncoding);
                            strToWrite = methodeName + ";rien;" + classMap[i][0] + ";" + classMap[j][0] + ";";
                            // strToWrite = methodeName + ";rien;" + graph1.Id + ";" + graph2.Id + ";";
                            strToWrite += iso.Graph1.ListNodes.Count + ";" + iso.Graph2.ListNodes.Count + ";";
                            if (this.flagTransform)
                            {
                                strToWrite += iso.Graph1.ListEdges.Count / 2 + ";" + iso.Graph2.ListEdges.Count / 2 + ";";
                            }
                            else
                            {
                                strToWrite += iso.Graph1.ListEdges.Count + ";" + iso.Graph2.ListEdges.Count + ";";
                            }
                            this.flagTransform = false;
                            //strToWrite += (iso.MatchingResult.Distance.ToString()).Replace(',','.') + ";";
                            strToWrite += iso.MatchingResult.Distance + ";";
                            strToWrite += iso.MatchingResult.NbNodes + ";";
                            strToWrite += "-1;";
                            strToWrite += iso.MatchingResult.TimeUse + ";";
                            if (iso.MatchingResult.Feasible)
                            {
                                strToWrite += "true;";
                            }
                            else
                            {
                                strToWrite += "false;";
                            }
                            if (iso.MatchingResult.Optimal)
                            {
                                strToWrite += "true;";
                            }
                            else
                            {
                                strToWrite += "false;";
                            }
                            if (iso.MatchingResult.MemoryOverFlow)
                            {
                                strToWrite += "true;";
                            }
                            else
                            {
                                strToWrite += "false;";
                            }
                            if (iso.MatchingResult.TimeOverFlow)
                            {
                                strToWrite += "true;";
                            }
                            else
                            {
                                strToWrite += "false;";
                            }
                            strToWrite += classMap[i][1] + ";";
                            strToWrite += classMap[j][1] + ";";
                            strToWrite += MakeMatchingToString(iso.MatchingResult.NodeMatchingDictionary);
                            monStream.WriteLine(strToWrite);
                        }
                        catch (Exception)
                        {
                            throw;
                        }
                        finally
                        {
                            if (monStream != null)
                            {
                                monStream.Close();
                            }
                            iso.Solver.closeSolver();
                        }
                    }
                }
            }
            return(true);
        }
        private static string onecomparisonwithres(string g1file, string g2file)
        {
            string result = "" + g1file + ";" + g2file;
            Graph  g1     = new Graph();

            g1.loadGXL(g1file);


            Graph g2 = new Graph();

            g2.loadGXL(g2file);


            g1.DynamicCastLabel(new LabelNodeGrecConstest(), new LabelEdgeGrecContest());
            g2.DynamicCastLabel(new LabelNodeGrecConstest(), new LabelEdgeGrecContest());

            IsomorphismLP iso = new IsomorphismLP();

            iso.Graph1 = g1;
            iso.Graph2 = g2;

            iso.DirectedGraph1 = g1;
            iso.DirectedGraph2 = g2;

            iso.SolverType  = "CPLEX";    //this.comboBoxSolveur2.SelectedIndex == 0 ? "CPLEX" : "GLPK";
            iso.FormulaType = "QAPGMGED"; //"IsoGraphInexactF2b";//"BLPjusticehero";//"IsoGraphInexactF1b";// Program.formulas[formulaTypeIndice];//Program.formulas[this.comboBoxProblem2.SelectedIndex];

            TimeSpan start = new TimeSpan(DateTime.Now.Ticks);

            iso.initial();
            //Program.nbCoeursCplex = int.Parse(textBoxnbthread.Text);
            iso.Solver.setThreadNumber(1);
            //SolverCPLEX.UBrootnode = true;
            iso.run();
            TimeSpan end       = new TimeSpan(DateTime.Now.Ticks);
            TimeSpan usingtime = end.Subtract(start).Duration();
            double   timeUse   = usingtime.TotalSeconds;
            int      optsol    = 2;

            if (iso.MatchingResult.Optimal)
            {
                optsol = 1;
            }
            if (iso.MatchingResult.Optimal == false)
            {
                optsol = 0;
            }

            Console.Write(optsol + ";");
            result += optsol + ";";
            Console.Write(timeUse.ToString("N8") + ";");
            result += timeUse.ToString("N8") + ";";
            Dictionary <string, string> NM = iso.MatchingResult.NodeMatchingDictionary;

            foreach (Node n in g1.ListNodes)
            {
                if (NM.ContainsKey("" + n.Id) == true)
                {
                    Console.Write(NM["" + n.Id] + " ");
                    result += NM["" + n.Id] + " ";
                }
                else
                {
                    Console.Write("-1 ");
                    result += "-1 ";
                }
            }
            Console.Write(";" + iso.MatchingResult.Distance);
            Console.WriteLine();
            result += ";" + iso.MatchingResult.Distance;
            return(result);
        }