Exemplo n.º 1
0
        public Graph(int verticesNum, int edgesNum)
        {
            Vertices = new GraphVertice[verticesNum];
            for (int i = 0; i < verticesNum; ++i)
            {
                Vertices[i] = new GraphVertice();
            }

            Edges = new GraphEdge[edgesNum];
        }
Exemplo n.º 2
0
        static void AddVerticeToMST(GraphVertice vertice)
        {
            vertice.IsInMST = true;
            mstVertices.Add(vertice);
            mstValue       += vertice.Weight;
            vertice.IsInMST = true;

            foreach (var edge in vertice.Edges)
            {
                var vert = Array.Find(edge.Vertices, v => !v.IsInMST);
                if (vert != null)
                {
                    if (vert.Weight > edge.Value)
                    {
                        vert.Weight = edge.Value;
                    }
                    //TODO: need to optimise heap validation at this moment
                    heap.Add(vert);
                }
            }
        }
Exemplo n.º 3
0
 static bool Compare(GraphVertice a, GraphVertice b)
 {
     return(a.Weight >= b.Weight);
 }
Exemplo n.º 4
0
 public GraphEdge(GraphVertice start, GraphVertice end, long value)
 {
     Vertices = new GraphVertice[] { start, end };
     Value    = value;
 }