// Returns the Force of a stab public static String getForce(Stab2 s, VariableCollection2 col) { String force = ""; foreach (Variable2 va in col.var) { String name = "F(" + s.node1 + "," + s.node2 + ")"; if (va.name.Contains(name)) { force = va.value; } } return(force); }
// Returns a Stab Object as result of a name input S(diameter, node1, node2) public static Stab2 nameToStab(String name) { Stab2 st = new Stab2(); int index1 = name.IndexOf("("); int index2 = name.IndexOf(")"); String stab = name.Substring((index1) + 1, (index2) - 2); String[] werte = stab.Split(','); st.node1 = werte[1]; st.node2 = werte[2]; st.diameter = werte[0]; return(st); }
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { // Get the BackgroundWorker that raised this event. BackgroundWorker worker = sender as BackgroundWorker; //bar.limit = tmlim; //bar.backgroundWorker1.RunWorkerAsync(); //bar.StartPosition = FormStartPosition.CenterScreen; //bar.Show(); // Assign the result of the computation // to the Result property of the DoWorkEventArgs // object. This is will be available to the // RunWorkerCompleted eventhandler. try { progressBar1.Value = 0; DateTime now = DateTime.Now; string datum = now.ToString("dd-MM-yyy"); datum = datum.Replace("-", ""); string csv = directory + "\\CSV\\" + projectName + "_csv1_" + datum + ".csv"; csv1Path = csv; Settings set = Settings.Default; set.csv1Path = csv; set.Save(); // Parse chosen .sol File to csv File XmlRootAttribute root = new XmlRootAttribute(); root.ElementName = "CPLEXSolution"; VariableCollection2 col = null; XmlSerializer s = new XmlSerializer(typeof(VariableCollection2), root); StreamReader reader = new StreamReader(solPath); col = (VariableCollection2)s.Deserialize(reader); reader.Close(); // Write deserialized data in csv file. int count = col.var.Count(); using (System.IO.StreamWriter file = new System.IO.StreamWriter(csv)) { int i = 1; // counter for number of stabs foreach (Variable2 va in col.var) { decimal dwert = 0; if (!va.value.Contains("e")) { string temp = va.value.Replace(".", ","); dwert = Convert.ToDecimal(temp); } if ((dwert > 0.85m) && (dwert < 1.15m)) // only stabs with value near 1 written in csv file { if (va.name.Contains("S(")) { Stab2 stab = nameToStab(va.name); String force = getForce(stab, col); file.WriteLine(stab.node1 + ";" + stab.node2 + ";" + stab.diameter + ";" + force); if (int.Parse(stab.diameter) > diameterNumber) // Get highest value of diameter { diameterNumber = int.Parse(stab.diameter); } i++; } } int percentComplete = (int)((float)i / (float)count * 100); worker.ReportProgress(percentComplete); //int pro = (int)((float)i / (float)count); //worker.ReportProgress(pro*100); } //file.WriteLine("Stabs: " + i); // To check if every Stab is represented } } catch (System.Exception ex) { MessageBox.Show("The solution file has the wrong format!", "Info"); } }