// button recalculate private void button7_Click(object sender, EventArgs e) { var watch = System.Diagnostics.Stopwatch.StartNew(); List <List <int> > LinkToCut = new List <List <int> >(); List <int> sublist = new List <int>(); string str1, str2, str3; char [] chr; FlagColor = 0; for (int i = 0; i < listBox3.Items.Count; i++) { str1 = listBox3.Items[i].ToString().Substring(0, listBox3.Items[i].ToString().IndexOf("-")).Replace(" ", "");; str2 = Regex.Replace(listBox3.Items[i].ToString(), "-", string.Empty); chr = str1.ToCharArray(); str3 = str2.Remove(0, chr.Length); sublist.Add(Convert.ToInt32(str1)); sublist.Add(Convert.ToInt32(str3)); LinkToCut.Add(sublist.ToList()); sublist.Clear(); } GAModuleDiv.TransferMatrixToSym(WeightMatrix, out SymmWeightMatrix); if (Flag == 1) { CPCCD.CPCCDAllRules(LinkToCut, Alfa, Modules, Communities, Modularity, SubGraphs, SubVerticeMs, SubRelativeMs, SizeLimit, CFTypeCode, MaterialList, out WMNode, out TroubleNodeList, out TroubleCode, out NodeGroups); } else if (Flag == 2) { MPCCD.MPCCDAllRules(LinkToCut, Modules, SymmWeightMatrix, VerticeMatrix, RelativeMotionMatrix, SizeLimit, CFTypeCode, MaterialList, out WMNode, out TroubleNodeList, out TroubleCode, out NodeGroups); } else { // List<int> Module = new List<int>(); //MPCCD.MPCCDGenerateModule(SymmWeightMatrix.GetLength(0), out Module); NPCCD.NPCCDAllRules(LinkToCut, SymmWeightMatrix, VerticeMatrix, SizeLimit, MaterialList, RelativeMotionMatrix, CFTypeCode, out WMNode, out TroubleNodeList, out TroubleCode, out NodeGroups); } richTextBox1.Clear(); richTextBox1.AppendText("Node Groups:\n"); foreach (List <int> x in NodeGroups) { x.Sort(); foreach (int xx in x) { richTextBox1.AppendText(" "); richTextBox1.AppendText(string.Join(" ", xx.ToString())); } richTextBox1.AppendText("\n"); } richTextBox2.Clear(); richTextBox2.AppendText("\nConflict Info:\n"); int Index = 0; foreach (List <int> x in TroubleNodeList) { foreach (int xx in x) { richTextBox2.AppendText(" "); richTextBox2.AppendText(string.Join(" ", xx.ToString())); } richTextBox2.AppendText("\t"); richTextBox2.AppendText(TroubleCode[Index].ToString()); Index++; richTextBox2.AppendText("\n"); } watch.Stop(); var elapsedMs = watch.ElapsedMilliseconds; label14.Show(); label14.Text = elapsedMs.ToString(); }
// calculate button private void button3_Click(object sender, EventArgs e) { var watch = System.Diagnostics.Stopwatch.StartNew(); richTextBox1.Text = ""; string str = comboBox2.SelectedItem.ToString(); int NumOfNode = currProduct.parts.Count; WeightMatrix = new double[NumOfNode, NumOfNode]; VerticeMatrix = new List <ComponentStruct>(); RelativeMotionMatrix = new int [NumOfNode, NumOfNode]; NumOfPopulation = (int)(NumOfNode / 2) + 3; NumOfGeneration = 10 * NumOfNode; double[] BestFitness = new double[NumOfGeneration]; Alfa = Convert.ToDouble(textBox1.Text); Modules = new List <List <int> >(); FlagColor = 0; // assemble xml info into a weight matrix for (int i = 0; i < NumOfNode; i++) { Part part = currProduct.parts[i]; WeightMatrix[i, i] = 1; if (part.JointComponent.Count != 0) { for (int j = 0; j < part.JointComponent.Count; j++) { WeightMatrix[i, part.JointComponent[j] - 1] = part.Weight[j]; // Get relative motion matrix RelativeMotionMatrix[i, part.JointComponent[j] - 1] = part.RelativeMotion[j]; } } } // retrieve vertice matrix for (int i = 0; i < NumOfNode; i++) { Part part = currProduct.parts[i]; ComponentStruct CMPS = new ComponentStruct(); switch (part.material) { case "Steel": CMPS.material = 1; break; case "Plastic": CMPS.material = 2; break; case "Rubber": CMPS.material = 3; break; case "Aluminium": CMPS.material = 4; break; case "Ceramic": CMPS.material = 5; break; } CMPS.bdBox = part.bdBox; switch (part.IsStandard) { case "Y": CMPS.IsStandard = 1; break; case "N": CMPS.IsStandard = 0; break; } switch (part.MaintenanceFreq) { case "High": CMPS.MaintenanceFreq = 1; break; case "Low": CMPS.MaintenanceFreq = 0; break; } VerticeMatrix.Add(CMPS); } // get size limit SizeLimit[0] = vlm[0]; SizeLimit[1] = vlm[1]; SizeLimit[2] = vlm[2]; // get material list MaterialList = new int[Materials.Count]; for (int i = 0; i < Materials.Count; i++) { switch (Materials[i]) { case "Steel": MaterialList[i] = 1; break; case "Plastic": MaterialList[i] = 2;; break; case "Rubber": MaterialList[i] = 3;; break; case "Aluminum": MaterialList[i] = 4;; break; case "Ceramics": MaterialList[i] = 5;; break; } } GAModuleDiv.TransferMatrixToSym(WeightMatrix, out SymmWeightMatrix); if (str == "Product") { // module division GAModuleDiv.FindBestSolution_Multiple(SymmWeightMatrix, NumOfPopulation, NumOfGeneration, CrossOverRatio, MutationRatio, out Modules, out BestFitness); CPCCD.FindCommunity(Alfa, Modules, SymmWeightMatrix, VerticeMatrix, RelativeMotionMatrix, out Communities, out Modularity, out SubGraphs, out SubVerticeMs, out SubRelativeMs); CPCCD.CPCCDAllRules_R3(Alfa, Modules, Communities, Modularity, SubGraphs, SubVerticeMs, SubRelativeMs, SizeLimit, CFTypeCode, MaterialList, out WMNode, out TroubleNodeList, out TroubleCode, out NodeGroups); richTextBox1.AppendText("\nModule Info:\n"); foreach (List <int> x in Modules) { x.Sort(); foreach (int xx in x) { richTextBox1.AppendText(" "); richTextBox1.AppendText(string.Join(" ", xx.ToString())); } // Console.WriteLine("\n"); richTextBox1.AppendText("\n"); } richTextBox1.AppendText(string.Format("{0:0.000}", BestFitness.Max()) + "\n"); /*foreach (List<List<int>> X0 in Communities) * { * foreach (List<int> x in X0) * { * foreach (int xx in x) * { * richTextBox1.AppendText(" "); * richTextBox1.AppendText(string.Join(" ", xx.ToString())); * } * richTextBox1.AppendText("\n"); * } * richTextBox1.AppendText("\n\n"); * }*/ /* List<List<double>> StackUpSize; * // List<int> Module = new List<int>(); * // MPCCD.MPCCDGenerateModule(SymmWeightMatrix.GetLength(0), out Module); * * NPCCD.PCCDStackUpSize(NodeGroups, VerticeMatrix, out StackUpSize); * foreach (List<double> x in StackUpSize) * { * foreach (double xx in x) * { * richTextBox1.AppendText(" "); * richTextBox1.AppendText(string.Join(" ", string.Format("{0:0.0}", xx))); * } * richTextBox1.AppendText("\n"); * } */ Flag = 1; textBox2.Text = "CPCCD"; } else { // module division GAModuleDiv.FindBestSolution_Multiple(SymmWeightMatrix, NumOfPopulation, NumOfGeneration, CrossOverRatio, MutationRatio, out Modules, out BestFitness); if (BestFitness.Max() > Alfa) { Flag = 2; MPCCD.MPCCDAllRules_R3(Modules, SymmWeightMatrix, VerticeMatrix, RelativeMotionMatrix, SizeLimit, CFTypeCode, MaterialList, out WMNode, out TroubleNodeList, out TroubleCode, out NodeGroups); // List<List<double>> StackUpSize; // List<int> Module = new List<int>(); // MPCCD.MPCCDGenerateModule(SymmWeightMatrix.GetLength(0), out Module); /* NPCCD.PCCDStackUpSize(NodeGroups, VerticeMatrix, out StackUpSize); * foreach (List<double> x in StackUpSize) * { * foreach (double xx in x) * { * richTextBox1.AppendText(" "); * richTextBox1.AppendText(string.Join(" ", string.Format("{0:0.0}", xx))); * } * richTextBox1.AppendText("\n"); * }*/ richTextBox1.AppendText("\nModule Info:\n"); foreach (List <int> x in Modules) { x.Sort(); foreach (int xx in x) { richTextBox1.AppendText(" "); richTextBox1.AppendText(string.Join(" ", xx.ToString())); } // Console.WriteLine("\n"); richTextBox1.AppendText("\n"); } richTextBox1.AppendText(string.Format("{0:0.000}", BestFitness.Max())); textBox2.Text = "CPCCD"; } else { Flag = 3; // List<int> Module = new List<int>(); // MPCCD.MPCCDGenerateModule(SymmWeightMatrix.GetLength(0), out Module); NPCCD.NPCCDAllRules_R3(SymmWeightMatrix, VerticeMatrix, SizeLimit, MaterialList, RelativeMotionMatrix, CFTypeCode, out WMNode, out TroubleNodeList, out TroubleCode, out NodeGroups); /* List<List<double>> StackUpSize; * NPCCD.PCCDStackUpSize(NodeGroups, VerticeMatrix, out StackUpSize); * * foreach (List<double> x in StackUpSize) * { * foreach (double xx in x) * { * richTextBox1.AppendText(" "); * richTextBox1.AppendText(string.Join(" ", string.Format("{0:0.0}", xx))); * } * richTextBox1.AppendText("\n"); * }*/ textBox2.Text = "NPCCD"; } } richTextBox1.AppendText("\nNode Groups:\n"); foreach (List <int> x in NodeGroups) { x.Sort(); foreach (int xx in x) { richTextBox1.AppendText(" "); richTextBox1.AppendText(string.Join(" ", xx.ToString())); } richTextBox1.AppendText("\n"); } richTextBox2.Clear(); richTextBox2.AppendText("\nConflict Info:\n"); int Index = 0; foreach (List <int> x in TroubleNodeList) { foreach (int xx in x) { richTextBox2.AppendText(" "); richTextBox2.AppendText(string.Join(" ", xx.ToString())); } richTextBox2.AppendText("\t"); richTextBox2.AppendText(TroubleCode[Index].ToString()); Index++; richTextBox2.AppendText("\n"); } watch.Stop(); var elapsedMs = watch.ElapsedMilliseconds; label14.Show(); label14.Text = elapsedMs.ToString(); }