public Vertex FAttr(Vertex p1, Vertex p2)
 {
     var kof_f =Graph.Distance(p1,p2)/l;
     var p1p2 = p2.Sub(p1);
     p1p2.Mul(kof_f);
     return p1p2;
 }
Ejemplo n.º 2
0
 // сила отталкивания
 public Vertex FRep(Vertex p1, Vertex p2)
 {
     var kof_f = l * l / Graph.SqDistance(p1, p2);
     var p2p1 = p1.Sub(p2);
     p2p1.Mul(kof_f);
     return p2p1;
 }
Ejemplo n.º 3
0
 public double CosAngle(Vertex p1, Vertex p2)
 {
     double coord = p1.x * p2.x + p1.y * p2.y;
     double norma_p1 = Math.Sqrt(p1.x*p1.x +p1.y*p1.y);
     double norma_p2 = Math.Sqrt(p2.x * p2.x + p2.y * p2.y);
     return coord / (norma_p1 * norma_p2);
 }
Ejemplo n.º 4
0
 public Vertex GetCetnreGravity()
 {
     Vertex p = new Vertex();
     for (int i = 0; i < g.vertexs.Length; i++) {
         p.Add(g.vertexs[i]);
     }
     p.Div(g.vertexs.Length*1.0);
     return p;
 }
Ejemplo n.º 5
0
 public Graph(int number, Vertex[] my_vertexs,int[,] my_edges,int[] my_degs)
 {
     n = number;
     vertexs = new Vertex[n];
     edges = new int[n, n];
     degs = new int[n];
     Array.Copy(my_edges, edges, n * n);
     Array.Copy(my_degs, degs, n);
     vertexs = my_vertexs.Select(l => l.Clone()).ToArray();
 }
Ejemplo n.º 6
0
        public Graph ReadInput()
        {
            String s;
            Graph new_graph;
            var sep = new Char[] { ' ' };
            int[,] matrix;
            System.IO.StreamReader file = new System.IO.StreamReader(@"C:\Users\pavel\documents\visual studio 2013\Projects\visualizacia\input.txt");
            s = s = file.ReadLine();
            var split = s.Split(sep);
            int n = Int16.Parse(split[0]);
            matrix = new int[n, n];
            int[] degs = new int[n];
            Vertex[] V = new Vertex[n];
            V[0] = new Vertex(5.0, 5.0);
            V[1] = new Vertex(5.0, 30.0);
            V[2] = new Vertex(100.0, 5.0);
            int deg = 0;
            double distance = 1;
            double l = 1;
            int[] length = new int[2];
              for(int i = 0; i<n; i++){
                s = file.ReadLine();
                split = s.Split(sep);
                int m = split.Length;
                deg = 0;
                for (int j = 0; j < m;j++ )
                {
                    matrix[i, j] = Int16.Parse(split[j]);
                    if (matrix[i, j] == 1)
                    {
                        //distance = Math.Sqrt((V[i].x - V[j].x) * (V[i].x - V[j].x) + (V[i].y - V[j].y) * (V[i].y - V[j].y));
                        if (distance > l)
                        {
                            //l = distance;
                            //length[0] = i;
                           // length[1] = j;
                        }
                        deg++;

                    }
                }
                degs[i] = deg;
            }
            new_graph = new Graph(n,matrix,degs);
            new_graph.SetSizeEdge(length);
            file.Close();
            return new_graph;
        }
        public void getNextPosition()
        {
            Vertex[] shift;
            int length = g.n;
            shift = new Vertex[length];
            for (int r = iterator; r < iterator + step; r++)
            {
                if (r > m)
                {
                    optimumPosition = true;
                    return;
                }
                for (int i = 0; i < length; i++)
                {
                    Vertex f = new Vertex(0, 0); ;
                    for (int j = 0; j < length; j++)
                    {
                        if (i != j)
                        {
                            f.Add(FRep(g.vertexs[i], g.vertexs[j]));
                            if (g.edges[i, j] == 1)
                                f.Add(FAttr(g.vertexs[i], g.vertexs[j]));

                        }
                    }
                    shift[i] = f;
                    double t = Delta(r);
                    double d = Graph.Distance(shift[i]);
                    t = Math.Min(d, t);
                    shift[i].Mul(t / d);
                }
                if (isOptimumPosition(shift)) return;
                for (int i = 0; i < length; i++)
                {
                    g.vertexs[i].Add(shift[i]);
                    g.vertexs[i].x = Math.Min(w / 2, Math.Max(-w / 2, g.vertexs[i].x));
                    g.vertexs[i].y = Math.Min(h / 2, Math.Max(-h / 2, g.vertexs[i].y));
                }

            }
            iterator+=step;
        }
        public void getNextPosition()
        {
            Vertex[] shift;
            int length = g.vertexs.Length;
            shift = new Vertex[length];
            for (int r = iterator; r < iterator + step; r++)
            {
                if (r > m)
                {
                    optimumPosition = true;
                    return;

                }
                for (int i = 0; i < length; i++)
                {
                    Vertex f = new Vertex(0, 0); ;
                    for (int j = 0; j < length; j++)
                    {
                        if (g.edges[i, j] == 1 && i != j)
                        {
                            f.Add(FSprings(g.vertexs[i], g.vertexs[j]));
                        }
                        else
                        {
                            if (i != j)
                                f.Add(FRep(g.vertexs[i], g.vertexs[j]));
                        }
                    }
                    shift[i] = f;
                }
                if (isOptimumPosition(shift)) return;
                for (int i = 0; i < length; i++)
                {
                    shift[i].Mul(k);
                    g.vertexs[i].Add(shift[i]);
                }

            }
            iterator += step;
        }
 private Vertex FSprings(Vertex p1, Vertex p2)
 {
     var kof_f = c1 * Math.Log(Graph.Distance(p1, p2) / l) / Graph.Distance(p1, p2);
     var p1p2 = p2.Sub(p1);
     p1p2.Mul(kof_f);
     return p1p2;
 }
Ejemplo n.º 10
0
 private Vertex FRep(Vertex p1, Vertex p2)
 {
     var kof_f = c2 / (Graph.Distance(p1, p2) * Graph.Distance(p1, p2));
     var p2p1 = p1.Sub(p2);
     p2p1.Mul(kof_f);
     return p2p1;
 }
Ejemplo n.º 11
0
 public Point toPoint(Vertex p)
 {
     int xx = Convert.ToInt32(((Xmax - Xmin) * ((p.x - xmin) / (xmax - xmin))) * kx) + Xmin;
     int yy = Convert.ToInt32((Ymax-Ymin) * (1 - ((p.y - ymin) / (ymax - ymin)))*ky) + Ymin;
     return new Point(xx, yy);
 }
Ejemplo n.º 12
0
 public void Find(Vertex[] v)
 {
     foreach(Vertex p in v)
     {
         if (p.x < xmin) xmin = p.x;
         if (p.x > xmax) xmax = p.x;
         if (p.y < ymin) ymin = p.y;
         if (p.y > ymax) ymax = p.y;
     }
 }
Ejemplo n.º 13
0
 public Vertex Clone()
 {
     Vertex v = new Vertex(x, y);
     return v;
 }
Ejemplo n.º 14
0
 public static double Distance(Vertex p1)
 {
     return Math.Sqrt((p1.x) * (p1.x) + (p1.y) * (p1.y));
 }
Ejemplo n.º 15
0
 private void springEmbedder()
 {
     Vertex[] shift;
     int length = g.n;
     shift = new Vertex[length];
     used = new bool[g.n];
     List<int> random_vertex= new List<int>();
     for (int r = 0; r < 100; r++)
     {
         toFalse();
         random_vertex = GenNumberVertex();
         for (int i = 0; i < length; i++)
         {
             Vertex f = new Vertex(0, 0);
             f.Add(FGravity(random_vertex[i]));
             for (int j = 0; j < length; j++)
             {
                 if (g.edges[random_vertex[i], j] == 1 && random_vertex[i] != j)
                 {
                     f.Add(FAttr(random_vertex[i], j));
                 }
                 else
                 {
                     if (i != j)
                         f.Add(FRep(g.vertexs[random_vertex[i]], g.vertexs[j]));
                 }
             }
             f.Mul(eps);
             g.vertexs[random_vertex[i]].Add(f);
         }
     }
 }
Ejemplo n.º 16
0
 public Vertex Sub(Vertex p2)
 {
     return new Vertex(x - p2.x, y - p2.y);
 }
 private bool isOptimumPosition(Vertex[] forces)
 {
     optimumPosition = true;
     foreach (Vertex p in forces)
     {
         if (Graph.Distance(p) > 0.5) optimumPosition = false;
     }
     return optimumPosition;
 }
Ejemplo n.º 18
0
 public static double SqDistance(Vertex p1, Vertex p2)
 {
     return((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y));
 }
Ejemplo n.º 19
0
 public void GenerateVertexsPosition(int rangeX,int rangeY)
 {
     vertexs = new Vertex[n];
     Random rand = new Random();
     bool[,] usedVertex = new bool[rangeX, rangeY];
     int i = 0;
     while (i < n)
     {
         int x = rand.Next(rangeX-1);
         int y = rand.Next(rangeY-1);
         if (!usedVertex[x, y])
         {
             vertexs[i] = new Vertex(x , y);
             for (int k = Math.Max(0, x - rangeX / 20); k < Math.Min(rangeX, x+ rangeX / 20); k++)
                 for (int j = Math.Max(0, y - rangeY / 20); j <= Math.Min(rangeY, y + rangeY / 20); j++) usedVertex[k, j] = true;
             i++;
         }
     }
 }
Ejemplo n.º 20
0
 public void Add(Vertex p1)
 {
     x = x + p1.x;
     y = y + p1.y;
 }