Ejemplo n.º 1
0
        public Graph(string InputText)
        {
            Vertices = new List <VertexGraph>();
            Edges    = new List <EdgeGraph>();
            if (InputText != String.Empty)
            {
                InputText = InputText.Replace(" ", "");
                InputText = InputText.Replace("\r", "");

                int      k = 0; string[] col;
                string[] text = InputText.Split('\n');
                foreach (var row  in text)
                {
                    col = row.Split(',');
                    VertexGraph from = new VertexGraph(k);
                    Vertices.Add(from);
                    for (int i = 0; i < col.Length; i++)
                    {
                        if (col[i] != "0" && col[i] != "")
                        {
                            VertexGraph to = new VertexGraph(i);
                            EdgeGraph   edge;
                            if (col[i] != "1")
                            {
                                int weight = int.Parse(col[i]);
                                edge = new EdgeGraph(from, to, weight);
                            }
                            else
                            {
                                edge = new EdgeGraph(from, to);
                            }
                            Edges.Add(edge);
                        }
                    }
                    k++;
                }
            }
        }
Ejemplo n.º 2
0
        public void AddEdge(VertexGraph from, VertexGraph to, int weight)
        {
            var edge = new EdgeGraph(from, to, weight);

            Edges.Add(edge);
        }
Ejemplo n.º 3
0
        public void AddEdge(VertexGraph from, VertexGraph to)
        {
            var edge = new EdgeGraph(from, to);

            Edges.Add(edge);
        }