Пример #1
0
        /// <summary>
        /// Създава първоначален граф
        /// </summary>
        void MakeGraph()
        {
            // ИЗВЪН ЕКСПЛОАТАЦИЯ
            //Property.GetPropertyId("цвят")
            Property.GetPropertyId("име");
            Property.GetPropertyId("цена");
            Property.GetPropertyId("поток");
            Property.GetPropertyId("обратен поток");

            activeGraph = new Graph();
            
            Vertex v = new Vertex(0, 0);
            v.SetProperty(0, "Варна");

            Vertex v1 = new Vertex(100, 0);
            v1.SetProperty(0, "София");
            v1.SetProperty(1, 512.25f);

            Vertex v2 = new Vertex(100, 0);
            v2.SetProperty(0, "Шумен");
            v2.SetProperty(2, 112.125f);

            Vertex v3 = new Vertex(100, 0);
            v3.SetProperty(0, "Стара Загора");
            v3.SetProperty(3, 12.725f);

            activeGraph.AddVertex(v);
            activeGraph.AddVertex(v1);
            activeGraph.AddVertex(v2);
            activeGraph.AddVertex(v3);

            Edge e1 = activeGraph.AddEdge(0, 3);
            e1.SetProperty(2, 200);

        }
Пример #2
0
        void menu_Generate(UiComponent sender, Object arg)
        {
            Vertex.ResetCounter();
            Graph g = new Graph();
            int n = random.Next(50);
            int m = random.Next(100);
            for (int i = 0; i < n; i++)
            {
                Vertex v = new Vertex((float)random.NextDouble() * 1000 - 500.0f, (float)random.NextDouble() * 600 - 300.0f);
                g.AddVertex(v);
                if (i == 0) continue;

                int connections = random.Next(1, (int)Math.Min(i, 3));
                for(int j = 0; j < connections; j++)
                {
                    int vo = random.Next(0, i);

                    bool contains = false;
                    foreach(Edge e in v.edges)
                    {
                        if(e.source.id == vo || e.destination.id == vo)
                        {
                            contains = true;
                            break;
                        }
                    }
                    if (contains) j--;
                    else g.AddEdge(v.id, vo);
                }
            }

            

            fs.SetForce(50);

            activeGraph = g;
            fs.SetGraph(g);
        }
Пример #3
0
        /// <summary>
        /// Чете данните за графа и го създава
        /// </summary>
        /// <param name="graphDataPtr">указател към буфера</param>
        void ReadGraphData(IntPtr graphDataPtr)
        {
            GraphicScheme.LoadFont();

            byte[] gdBuff = new byte[9]; // информация за графа: [брой върхове] [брой ребра] [насочен]

            int nRead;

            bool result = NativeMethods.ReadProcessMemory(processHandle, graphDataPtr, gdBuff, 9, out nRead);

            int[] count = new int[2];
            Buffer.BlockCopy(gdBuff, 0, count, 0, 8);

            //MessageBox.Show(String.Format("Vertices: {0}, Edges: {1}", count[0], count[1]));

            graph = new Graph(gdBuff[8]!=0);
            graph.vertices = new List<Vertex>(count[0]);


            Vertex.ResetCounter(); // better safe than sorry
            Edge.ResetCounter();

            for(int i = 0; i < count[0]; i++)
            {
                graph.AddVertex(new Vertex());
            }

            int[] edges = new int[count[1] * 2];

            byte[] edgeBuff = new byte[count[1] * 8];
            result = NativeMethods.ReadProcessMemory(processHandle, graphDataPtr + 9, edgeBuff, count[1] * 8, out nRead);

            Buffer.BlockCopy(edgeBuff, 0, edges, 0, count[1] * 8);

            for(int i = 0; i < count[1]; i++)
            {
                graph.AddEdge(edges[2 * i], edges[2 * i + 1]);
            }
        }