// 求解成功回调函数 private void OnSolveFinish(int[][] paths, double[] load, double[] mileage) { Application.Current.Dispatcher.BeginInvoke(new Action(delegate { Record.Paths.Clear(); // 保存路径 for (int i = 0; i < paths.Length; ++i) { Record.Paths.Add(new ObservableCollection <int>()); for (int j = 0; j < paths[i].Length; ++j) { Record.Paths[i].Add(paths[i][j]); } } // 生成路径 Record.GenerateSegments(); // 绘制路径 //Segments.Clear(); //for (int i = 0; i < paths.Length; ++i) //{ // Record.Paths.Add(new ObservableCollection<int>()); // if (paths[i].Length > 0) // { // Brush brush = Util.RandomColorBrush(); // Point last = new Point(Record.Nodes[0].X, Record.Nodes[0].Y); // for (int j = 0; j < paths[i].Length; ++j) // { // Record.Paths[i].Add(paths[i][j]); // Segments.Add(new Segment { X1 = last.X, Y1 = last.Y, X2 = Record.Nodes[paths[i][j]].X, Y2 = Record.Nodes[paths[i][j]].Y, Stroke = brush }); // last = new Point(Record.Nodes[paths[i][j]].X, Record.Nodes[paths[i][j]].Y); // } // Segments.Add(new Segment { X1 = last.X, Y1 = last.Y, X2 = Record.Nodes[0].X, Y2 = Record.Nodes[0].Y, Stroke = brush }); // } //} // 保存结果 try { Record.CreateTime = DateTime.Now; Record.Name = Record.CreateTime.ToString("yyyy-MM-dd-HH-mm-ss"); GlobalData.AddRecord(Record); } catch (Exception e) { MsgBox.Show("保存求解记录失败!\n" + e.Message); } })); }