Exemplo n.º 1
0
        public Graph Clone()
        {
            var nodeDictionary = new Dictionary <GraphNode, GraphNode>();

            var copyOfGraph = new Graph();

            foreach (GraphNode node in Nodes)
            {
                var copyOfNode = new GraphNode(node.Position, node.Name, node.Info, node.Style);
                nodeDictionary[node] = copyOfNode; // соответствие между старой и новой ссылкой

                copyOfGraph.AddNode(copyOfNode);
            }

            foreach (GraphNode markedNode in MarkedNodes)
            {
                copyOfGraph.markedNodes.Add(nodeDictionary[markedNode]);
            }

            foreach (GraphWay way in Ways)
            {
                var copyOfWay = new GraphWay(nodeDictionary[way.From], nodeDictionary[way.To], way.Weight, way.Oriented);
                copyOfWay.WeightIsLen = way.WeightIsLen;
                copyOfWay.Style       = way.Style;

                copyOfGraph.AddWay(copyOfWay);
            }

            return(copyOfGraph);
        }
Exemplo n.º 2
0
        public override object Execute(Graph graph)
        {
            ValidateGraph(graph);

            var sortedWays = new List <GraphWay>(graph.Ways)
                             .OrderBy(w => w.Weight).ToList();

            // delete all ways
            graph.RemoveWay(w => true);

            var listNodesInList = new List <List <GraphNode> >();    // лист компонент связанности

            foreach (GraphWay way in sortedWays)
            {
                if (!InOneComponentsConnectedness(way.From, way.To, listNodesInList))
                {
                    graph.AddWay(way);
                }
            }

            return(graph);
        }