示例#1
0
        public MainUI(Connector con)
        {
            connector = con;
            activeGraph = connector.GraphInstance;
            activeGraph.ArrangeInCircle();

            //DumpProperties();

            algoTimer = new Timer(150); // при създаване с конектор(т.е. алгоритъм), се създава и таймера за автоматичен
            algoTimer.Elapsed += algoTimer_Elapsed; // ход
            connector.AlgorithmSuspended += connector_AlgorithmSuspended;
            Start();
        }
示例#2
0
        /// <summary>
        /// Чете граф от файл. Формат - списък на съседи
        /// </summary>
        /// <param name="filename"></param>
        /// <param name="graph"></param>
        public static void ReadGraphFile(string filename, ref Graph graph)
        {
            String[] lines = File.ReadAllLines(filename);

            int lineIdx = 0;
            try
            {
                String[] parts = lines[0].Split(' ');
                int n = int.Parse(parts[0]);
                int m = int.Parse(parts[1]);

                Vertex.ResetCounter();
                for (int i = 0; i < n; i++) graph.vertices.Add(new Vertex());

                lineIdx++;
                for(int i = 0; i < m; i++)
                {
                    parts = lines[lineIdx].Split(' ');
                    int src = int.Parse(parts[0]);
                    int dest = int.Parse(parts[1]);

                    Edge e = graph.AddEdge(src, dest);

                    if(parts.Length > 2)
                    { // част за четене на тегла
                        int val = 0;
                        try
                        {
                            val = int.Parse(parts[2]);
                            int propId = Property.GetPropertyId("тегло");
                            Property.SetSpecialProperty(propId, SpecialProperty.EdgeWeight);
                            e.SetProperty(propId, int.Parse(parts[2]));
                        }
                        catch(Exception exc)
                        {
                            Console.WriteLine(String.Format("Line {0}: third part was NaN: {1}", lineIdx, parts[2]));
                        }
                        
                    }

                    lineIdx++;
                }
            }
            catch(Exception e)
            {
                MessageBox.Show(String.Format("An exception occured on line {0}: {1}", lineIdx, e.Message), e.GetType().ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error);
                graph = new Graph();
                Vertex.ResetCounter();
                return;
            }
            graph.ArrangeInCircle();
        }