Пример #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];
        }
Пример #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);
                }
            }
        }
Пример #3
0
 static bool Compare(GraphVertice a, GraphVertice b)
 {
     return(a.Weight >= b.Weight);
 }
Пример #4
0
 public GraphEdge(GraphVertice start, GraphVertice end, long value)
 {
     Vertices = new GraphVertice[] { start, end };
     Value    = value;
 }