示例#1
0
        public void AddEdge(int index_from, int index_to, string weight, bool generate)
        {
            node_view from_node = TopList[index_from];
            node_view to_node   = TopList[index_to];
            bool      isExist   = false;

            foreach (edge_view line0 in edgeList)
            {
                if ((line0.From == from_node && line0.To == to_node) || (line0.To == from_node && line0.From == to_node))
                {
                    if (!generate)
                    {
                        MessageBox.Show("Дуга вже існує");
                    }

                    else
                    {
                        line0.Weight = line0.Weight + int.Parse(weight);
                    }
                    isExist = true;
                }
            }
            if (!isExist)
            {
                if (weight == "0")
                {
                    weight = "1";
                }
                edge_view line = new edge_view(this, from_node, to_node, weight);
                edgeList.Add(line);
                FirstTop = null;
                EndAddEdge();
            }
        }
示例#2
0
 public void DeleteEdge(edge_view line)
 {
     if (edgeList.Contains(line))
     {
         edgeList.Remove(line);
         foreach (Shape shape in line.Edge)
         {
             canvas.Children.Remove(shape);
         }
         canvas.Children.Remove(line.TxtBox);
     }
 }
示例#3
0
        public void AddEdge(node_view from_node, node_view to_node)
        {
            bool isExist = false;

            foreach (edge_view line0 in edgeList)
            {
                if ((line0.From == from_node && line0.To == to_node) || (line0.To == from_node && line0.From == to_node))
                {
                    MessageBox.Show("Дуга вже існує");
                    isExist = true;
                }
            }
            if (!isExist)
            {
                edge_view line = new edge_view(this, from_node, to_node, "1");
                edgeList.Add(line);
                FirstTop = null;
                EndAddEdge();
            }
        }
示例#4
0
 public void AddEdge(int index_from, int index_to, string weight, bool generate)
 {
     node_view from_node = TopList[index_from];
     node_view to_node = TopList[index_to];
     bool isExist = false;
     foreach (edge_view line0 in edgeList)
     {
         if ((line0.From == from_node && line0.To == to_node) || (line0.To == from_node && line0.From == to_node))
         {
             if (!generate)
                 MessageBox.Show("Дуга вже існує");
                 
             else
                 line0.Weight = line0.Weight + int.Parse(weight);
             isExist = true;
         }
     }
     if (!isExist)
     {
         if (weight == "0")
             weight = "1";
         edge_view line = new edge_view(this, from_node, to_node, weight);
         edgeList.Add(line);
         FirstTop = null;
         EndAddEdge();
     }
 }
示例#5
0
 public void AddEdge(node_view from_node, node_view to_node)
 {
     bool isExist = false;
     foreach (edge_view line0 in edgeList)
         if ((line0.From == from_node && line0.To == to_node) || (line0.To == from_node && line0.From == to_node))
         {
             MessageBox.Show("Дуга вже існує");
             isExist = true;
         }
     if (!isExist)
     {
         edge_view line = new edge_view(this, from_node, to_node, "1");
         edgeList.Add(line);
         FirstTop = null;
         EndAddEdge();
     }
 }
示例#6
0
 public void DeleteEdge(edge_view line)
 {
     if (edgeList.Contains(line))
     {
         edgeList.Remove(line);
         foreach (Shape shape in line.Edge)
             canvas.Children.Remove(shape);
         canvas.Children.Remove(line.TxtBox);
     }
 }
示例#7
0
        public void GenerateGraph(int count, int min_weight, int max_weight, double coherence)
        {
            int    sum_NodeWeights = 0;
            int    sum_EdgeWeights;
            Random rnd = new Random();

            for (int i = 0; i < count; i++)
            {
                AddTop(rnd.Next(50, 650), rnd.Next(50, 500), rnd.Next(min_weight, max_weight).ToString());
            }

            foreach (node_view node in TopList)
            {
                sum_NodeWeights += node.weight;
            }

            sum_EdgeWeights = Convert.ToInt32(Convert.ToDouble(sum_NodeWeights) / coherence) - sum_NodeWeights;

            do
            {
                int from   = rnd.Next(count);
                int to     = rnd.Next(count);
                int weight = Convert.ToInt32(sum_EdgeWeights / rnd.Next(5, 10));
                if (from != to)
                {
                    if (weight == 0)
                    {
                        weight++;
                    }
                    if (sum_EdgeWeights - weight > 0)
                    {
                        AddEdge(from, to, weight.ToString(), true);
                        sum_EdgeWeights -= weight;
                    }
                    else if (sum_EdgeWeights - weight <= 0)
                    {
                        AddEdge(from, to, (sum_EdgeWeights).ToString(), true);
                        sum_EdgeWeights = 0;
                    }
                }
            } while (sum_EdgeWeights != 0);

            for (int i = 0; i < TopList.Count; i++)
            {
                while (!NodeIsAcyclic(i, 3, false))
                {
                    for (int j = edgeList.Count - 1; j >= 0; j--)
                    {
                        if (edgeList[j].To.id == TopList[i].id)
                        {
                            int weight = edgeList[j].Weight;
                            DeleteEdge(edgeList[j]);
                            edge_view e_w = edgeList[rnd.Next(edgeList.Count)];

                            e_w.Weight += weight;

                            e_w.OnPointPositionChanged(e_w.To);
                            e_w.OnPointPositionChanged(e_w.From);
                        }
                    }
                }
            }
        }