private void DrawEdges(Graphics g) { if (_Nodes.Count > 1) { List <Node> painted = new List <Node>(); foreach (Node node in _Nodes) { foreach (Node target in _Nodes) { if (!painted.Contains(target) && node != target) { Point p1 = new Point(node.Left + node.Width / 2, node.Top + node.Height / 2); Point p2 = new Point(target.Left + target.Width / 2, target.Top + target.Height / 2); ACODistance dist = (ACODistance)node.City.GetDistanceTo(target.City); float phromoneLineStrokeWidth = (float)((dist.Pheromone / GetMaxPheromoneValue())); Color c = Color.Black; if (dist.IsSelected) { c = Color.Blue; } c = Color.FromArgb((int)((c.A / 2) * phromoneLineStrokeWidth) + c.A / 2, c); g.DrawLine(new Pen(c, phromoneLineStrokeWidth * 3), p1, p2); } painted.Add(node); } } } }
protected void UpdateLengthData(object sender, EventArgs e) { int k = distanceLengthView.CurrentCell.RowIndex; int n = distanceLengthView.CurrentCell.ColumnIndex; if (k != n) { ACODistance dist = GetDistance(k, n); dist.Length = Convert.ToDecimal(distanceLengthView.CurrentCell.Value); } List <Node> nodes = graphView1.Nodes; for (int i = 0; i < nodes.Count; i++) { for (int j = 0; j < nodes.Count; j++) { if (nodes[i] == nodes[j]) { distanceLengthView[i, j].ReadOnly = true; distanceLengthView[i, j].Style.BackColor = Color.Gray; } else { DataGridViewTextBoxCell textBoxCell = new DataGridViewTextBoxCell(); ACODistance dist = (ACODistance)nodes[i].City.GetDistanceTo(nodes[j].City); distanceLengthView[i, j].Value = dist.Length; } } } }
private void importPheromonetButton_Click(object sender, EventArgs e) { List <List <decimal> > data = LoadFromFile(Convert.ToDecimal(.5d)); if (data.Count > 0 && data.Count == data[0].Count) { int nodesToAdd = data.Count - graphView1.Nodes.Count; for (int i = 0; i < nodesToAdd; i++) { graphView1.AddNewNode(); graphView1.PlaceNodesAround(); } List <Node> nodes = graphView1.Nodes; for (int i = 0; i < data.Count; i++) { for (int j = 0; j < data.Count; j++) { if (nodes[i] != nodes[j]) { ACODistance dist = (ACODistance)nodes[i].City.GetDistanceTo(nodes[j].City); dist.Pheromone = Convert.ToDouble(data[i][j]); } } } Refresh(); } }
private NumericUpDown InitNumericUpDown(ACODistance dist) { NumericUpDown numeric = new NumericUpDown(); numeric.Minimum = 1; numeric.Maximum = 10000; numeric.DecimalPlaces = 0; numeric.Increment = 10; numeric.DataBindings.Add("Value", dist, "Length"); return(numeric); }
public override void Refresh() { distanceLengthView.Rows.Clear(); distanceLengthView.Columns.Clear(); distancePheromoneView.Rows.Clear(); distancePheromoneView.Columns.Clear(); List <Node> nodes = graphView1.Nodes; foreach (Node node in nodes) { string colName = node.Text; distanceLengthView.Columns.Add(colName, colName); distanceLengthView.Columns[colName].Width = 35; distancePheromoneView.Columns.Add(colName, colName); distancePheromoneView.Columns[colName].Width = 35; } for (int i = 0; i < nodes.Count; i++) { string rowName = nodes[i].Text; distanceLengthView.Rows.Add(); distanceLengthView.Rows[i].HeaderCell.Value = rowName; distancePheromoneView.Rows.Add(); distancePheromoneView.Rows[i].HeaderCell.Value = rowName; } for (int i = 0; i < nodes.Count; i++) { for (int j = 0; j < nodes.Count; j++) { if (nodes[i] == nodes[j]) { distanceLengthView[i, j].ReadOnly = true; distanceLengthView[i, j].Style.BackColor = Color.Gray; distancePheromoneView[i, j].ReadOnly = true; distancePheromoneView[i, j].Style.BackColor = Color.Gray; } else { DataGridViewTextBoxCell textBoxCell = new DataGridViewTextBoxCell(); ACODistance dist = (ACODistance)nodes[i].City.GetDistanceTo(nodes[j].City); distanceLengthView[i, j].Value = dist.LengthDouble; distancePheromoneView[i, j].Value = dist.Pheromone; } } } base.Refresh(); }
protected void UpdateLengthSelection(object sender, EventArgs e) { int i = distanceLengthView.CurrentCell.RowIndex; int j = distanceLengthView.CurrentCell.ColumnIndex; if (i != j) { ACODistance dist = GetDistance(i, j); dist.IsSelected = true; graphView1.Refresh(); //dist.Length = Convert.ToDecimal(distanceLengthView.CurrentCell.Value); dist.IsSelected = false; } else { graphView1.Refresh(); } }
public double GetMaxPheromoneValue() { double max = 0; foreach (ACOCity city in _Graph.GetCities()) { foreach (ACOCity target in _Graph.GetCities()) { if (city != target) { ACODistance dist = (ACODistance)city.GetDistanceTo(target); if (dist.Pheromone > max) { max = dist.Pheromone; } } } } return(max); }