public void initial() { try { solver = (ISolver)(Activator.CreateInstance(Type.GetType("LP.Solver" + this.solverType))); if (this.solverType == "GLPK") { prob = new ProblemGLPK(this.directedGraph1, this.directedGraph2); } else { if (this.graph1.IsDirected == true) { prob = new ProblemCPLEX(this.directedGraph1, this.directedGraph2); } else { prob = new ProblemCPLEXUndirected(this.directedGraph1, this.directedGraph2); } // prob = new ProblemCPLEX(this.directedGraph1, this.directedGraph2); } matchingResult = new MatchingResult(); } catch (Exception e) { Console.Write(e.ToString()); } }
/// <summary> /// print the result to the richText of the mainWindow /// And return le matchingResult /// </summary> /// <param name="MatchingNodes"></param> /// <param name="ResultText"></param> public bool getMatchingResult(MatchingResult matchingResult) { matchingResult.TimeUse = this.timeUse; if (simplexOK) { Console.Out.WriteLine("Simplex Ok"); } else { Console.Out.WriteLine("Simplex failed"); } if (mipOK) { Console.Out.WriteLine("Mip ok"); } else { Console.Out.WriteLine("Mip failed"); } if (simplexTimeOverflow == true || mipTimeOverflow == true) { matchingResult.TimeOverFlow = true; Console.Out.WriteLine("time over"); } if (mipMemoryOverflow == true) { matchingResult.MemoryOverFlow = true; Console.Out.WriteLine("memory outflow"); } if (this.memUse != 0) { double MemUseMB = (double)this.memUse / 1048576.0; matchingResult.MemoryUse = MemUseMB; Console.Out.WriteLine("memory : " + MemUseMB + "Mb"); } matchingResult.MaxTreeNodes = this.n_cnt_max; matchingResult.NbNodes = this.t_cnt; int status1 = glp_mip_status(lp); if (status1 == GLP_OPT || status1 == GLP_FEAS) { matchingResult.Feasible = true; if (status1 == GLP_OPT) { matchingResult.Optimal = true; } } if ((simplexOK == true) && (mipOK == true)) { return(getMatchingResultMip(matchingResult)); } else { return(false);//getMatchingResultSimplex(matchingResult); } }
/// <summary> /// Cette méthode est la méthode "editPath" de matching.dll. Son corretement est à voir. /// pour l'instant, on utilise pas ça. /// on utilse la méthode branch and bound de code java que Monsieur Raveaux fournis. /// </summary> /// <param name="graph1"></param> /// <param name="graph2"></param> public void runEditGraph(Graph graph1, Graph graph2) { if (graph1 != null && graph2 != null) { GraphEditDistance graphEditDistance = new GraphEditDistance(); EditPath Result; TimeSpan start = new TimeSpan(DateTime.Now.Ticks); Result = graphEditDistance.EditDistance(graph1, graph2); TimeSpan end = new TimeSpan(DateTime.Now.Ticks); TimeSpan usingtime = end.Subtract(start).Duration(); matchingResult.TimeUse = usingtime.TotalMilliseconds; matchingResult = new MatchingResult(); matchingResult.NodeMatchingDictionary = new Dictionary <string, string>(); matchingResult.EdgeMatchingDictionary = new Dictionary <string, string>(); getNodeOperations(Result); getEdgeOperations(Result); matchingResult.Distance = Result.Cost; matchingResult.Optimal = true; matchingResult.Feasible = true; } }
public bool matchingEqual(MatchingResult res, RichTextBox ResultText) { if ((res == null) || (this == null)) { return(false); } foreach (KeyValuePair <string, string> kvp in this.nodeMatchingDictionary) { string value = null; res.nodeMatchingDictionary.TryGetValue(kvp.Key, out value); if (value != null) { if (value != kvp.Value) { return(false); } else { ResultText.AppendText("\n" + kvp.Key + "--->" + kvp.Value + " OK"); } } } foreach (KeyValuePair <string, string> kvp in this.edgeMatchingDictionary) { string value = null; res.edgeMatchingDictionary.TryGetValue(kvp.Key, out value); if (value != null) { if (value != kvp.Value) { return(false); } else { ResultText.AppendText("\n" + kvp.Key + "--->" + kvp.Value + " OK"); } } } return(true); }
public bool matchingEqual(MatchingResult res) { if ((res == null) || (this == null)) { return(false); } /* foreach (KeyValuePair<string, string> kvp in this.nodeMatchingDictionary) * { * string value=null; * res.nodeMatchingDictionary.TryGetValue(kvp.Key, out value); * if (value != null) * { * if (value != kvp.Value) return false; * * } * } * foreach (KeyValuePair<string, string> kvp in this.edgeMatchingDictionary) * { * string value = null; * res.edgeMatchingDictionary.TryGetValue(kvp.Key, out value); * if (value != null) * { * if (value != kvp.Value) return false; * * } * }*/ if (Math.Abs(res.distance - this.distance) < 0.0001) { return(true); } else { return(false); } }
public bool getMatchingResultMip(MatchingResult matchingResult) { double distance; double ress; double minimum = -1; minimum = glp_mip_obj_val(lp); string valName; //double distance = -1.0; for (int i = 1; i <= (glp_get_num_cols(lp)); i++) { ress = glp_mip_col_val(lp, i); valName = System.Runtime.InteropServices.Marshal.PtrToStringAnsi(glp_get_col_name(lp, i)); if ((ress - 1 < 0.0001) && (ress - 1 > -0.0001)) { if (valName.StartsWith("x_")) { KeyValuePair <string, string> pair = seperateValName(valName); distance = glp_get_obj_coef(lp, i); matchingResult.NodeMatchingDictionary.Add(pair.Key, pair.Value); // Console.Out.WriteLine(pair.Key + "->" + pair.Value + ": distance: " + distance.ToString() + "\n\n"); distance = -1.0; } else if (valName.StartsWith("y_")) { KeyValuePair <string, string> pair = seperateValName(valName); distance = glp_get_obj_coef(lp, i); //Console.Out.WriteLine(pair.Key + "->" + pair.Value + ": distance: " + distance.ToString() + "\n\n"); if (!pair.Key.StartsWith("copy_")) { if (pair.Value.StartsWith("copy_")) { matchingResult.EdgeMatchingDictionary.Add(pair.Key, pair.Value.Substring(5)); } else { matchingResult.EdgeMatchingDictionary.Add(pair.Key, pair.Value); } } } else if (valName.StartsWith("u_")) { KeyValuePair <string, string> pair = seperateValName(valName); //new KeyValuePair<string, string>(valName.Substring(2), "NUL"); distance = glp_get_obj_coef(lp, i); matchingResult.NodeMatchingDictionary.Add(pair.Key, pair.Value); // Console.Out.WriteLine(pair.Key + "->" + pair.Value + ": distance: " + distance.ToString() + "\n\n"); } else if (valName.StartsWith("e_")) { KeyValuePair <string, string> pair = seperateValName(valName); //new KeyValuePair<string, string>(valName.Substring(2), "NUL"); distance = glp_get_obj_coef(lp, i); //Console.Out.WriteLine(pair.Key + "->" + pair.Value + ": distance: " + distance.ToString() + "\n\n"); if (!pair.Key.StartsWith("copy_")) { matchingResult.EdgeMatchingDictionary.Add(pair.Key, pair.Value); } } else if (valName.StartsWith("v_")) { KeyValuePair <string, string> pair = seperateValName(valName); //new KeyValuePair<string, string>(valName.Substring(2), "NUL"); distance = glp_get_obj_coef(lp, i); //Console.Out.WriteLine(pair.Key+"->"+pair.Value+ ": distance: " + distance.ToString() + "\n\n"); matchingResult.NodeMatchingDictionary.Add(pair.Key, pair.Value); //ResultText.AppendText("Nodes: " + this.g1.Name + "#" + res[0] + " is lonely..\n"); } else if (valName.StartsWith("f_")) { KeyValuePair <string, string> pair = seperateValName(valName); //new KeyValuePair<string, string>(valName.Substring(2), "NUL"); distance = glp_get_obj_coef(lp, i); //Console.Out.WriteLine(pair.Key + "->" + pair.Value + ": distance: " + distance.ToString() + "\n\n"); if (!pair.Key.StartsWith("Del_copy_")) { matchingResult.EdgeMatchingDictionary.Add(pair.Key, pair.Value); } } } } if (minimum < 0.000001 && minimum > -0.000001) { minimum = 0; } matchingResult.Distance = minimum; return(true); }
/// <summary> /// get the matchingResult /// </summary> /// <param name="MatchingNodes"></param> /// <param name="ResultText"></param> public bool getMatchingResult(MatchingResult matchingResult) { matchingResult.cplx = this.cplex; matchingResult.Feasible = true; matchingResult.TimeUse = this.timeUse; //System.Console.WriteLine("Solution status = " + cplex.GetCplexStatus()); //System.Console.WriteLine("Solution value = " + cplex.ObjValue); //string[] te = cplex.GetCplexStatus().ToString().Split(new string[] { "Best Bound" }, StringSplitOptions.None);//[1].Split(new string[] { " " }, StringSplitOptions.None)[6]; int nbCols = this.ilpMatrix.NumVars.Count(); //this.SaveProb2File("./prob.txt"); //this.solutionSave("./sol.txt"); Cplex.CplexStatus status = cplex.GetCplexStatus(); matchingResult.NbNodes = cplex.Nnodes; matchingResult.MaxTreeNodes = treeNode; if (status.Equals(Cplex.CplexStatus.MemLimFeas) || status.Equals(Cplex.CplexStatus.MemLimInfeas)) { matchingResult.MemoryOverFlow = true; //Console.Out.WriteLine("Feasible"); } if (status.Equals(Cplex.CplexStatus.AbortTimeLim)) { matchingResult.TimeOverFlow = true; } Cplex.Status status2 = cplex.GetStatus(); if (status2.Equals(Cplex.Status.Optimal)) { matchingResult.Optimal = true; //Console.Out.WriteLine("optimal"); } if (status2.Equals(Cplex.Status.Feasible)) { matchingResult.Feasible = true; //Console.Out.WriteLine("Feasible"); } if (status2.Equals(Cplex.Status.Infeasible)) { matchingResult.Feasible = false; // Console.Out.WriteLine("no Feasible solution"); //jamais ici } double ress; if (relaxationcontinue == true) { matchingResult.Optimal = false; matchingResult.Feasible = false; } if (flagsolveur == false) { bestsol = cplex.ObjValue; } double[] sol = cplex.GetValues(ilpMatrix); string valName; for (int i = 0; i < nbCols; i++) { ress = sol[i]; valName = ilpMatrix.NumVars[i].Name; // System.Console.WriteLine("LB = " + this.ilpMatrix.NumVars[i].LB); if ((ress - 1 < 0.0001) && (ress - 1 > -0.0001)) { if (valName.StartsWith("x_")) { KeyValuePair <string, string> pair = seperateValName(valName); matchingResult.NodeMatchingDictionary.Add(pair.Key, pair.Value); } else if (valName.StartsWith("y_")) { KeyValuePair <string, string> pair = seperateValName(valName); if (!pair.Key.StartsWith("copy_")) { if (pair.Value.StartsWith("copy_")) { matchingResult.EdgeMatchingDictionary.Add(pair.Key, pair.Value.Substring(5)); } else { matchingResult.EdgeMatchingDictionary.Add(pair.Key, pair.Value); } } } else if (valName.StartsWith("u_")) { KeyValuePair <string, string> pair = seperateValName(valName); matchingResult.NodeMatchingDictionary.Add(pair.Key, pair.Value); } else if (valName.StartsWith("e_")) { KeyValuePair <string, string> pair = seperateValName(valName); if (!pair.Key.StartsWith("copy_")) { matchingResult.EdgeMatchingDictionary.Add(pair.Key, pair.Value); } } else if (valName.StartsWith("v_")) { KeyValuePair <string, string> pair = seperateValName(valName); matchingResult.NodeMatchingDictionary.Add(pair.Key, pair.Value); } else if (valName.StartsWith("f_")) { KeyValuePair <string, string> pair = seperateValName(valName); if (!pair.Key.StartsWith("Del_copy_")) { matchingResult.EdgeMatchingDictionary.Add(pair.Key, pair.Value); } } } } if (bestsol < 0.000001 && bestsol > -0.000001) { bestsol = 0; } matchingResult.Distance = bestsol; return(true); }