Exemple #1
0
        /// <summary>
        /// Создание нового экземлпяра графа на основе указанного списка смежности.
        /// </summary>
        /// <param name="list">Исходный список смежности.</param>
        /// <returns>Новый экземпляр графа.</returns>
        public static MainGraph GenerateGraph(AdjacencyList list, int medCount, int villCount)
        {
            if (list == null)
            {
                return(null);
            }
            AdjacencyList.PrintGraph(list);
            MainGraph graph = new MainGraph();

            for (int i = 0; i < villCount; i++)
            {
                graph.AddVertex(new DataVertex());
            }
            for (int i = villCount; i < list.VertexCount; i++)
            {
                graph.AddVertex(new DataVertex(VertexColor.Unmarked, VertexType.Unmarket, Utility.Rand.Next(999) + 1));
            }
            for (int i = 0; i < list.VertexCount; i++)
            {
                foreach (int j in list.GetAdjacent(i))
                {
                    if (list.IsDirected || !list.IsDirected && j > i)
                    {
                        var source = graph.Vertices.ElementAt(i);
                        var target = graph.Vertices.ElementAt(j);

                        graph.AddEdge(new DataEdge(source, target, Utility.Rand.Next(9) + 1));
                    }
                }
            }

            return(graph);
        }
Exemple #2
0
        public static AdjacencyList GenerateList(Chromosome chromosome, Cost costt)
        {
            if (chromosome == null)
            {
                return(null);
            }
            cost = costt;
            var list       = new AdjacencyList(cost.vertexCount);
            var costList   = cost.CostList;
            var chromArray = chromosome.chromosomeArray;
            int c          = 0;

            for (int i = 0; i < list.VertexCount; i++)
            {
                if (costList[i].Count == 0)
                {
                    continue;
                }
                for (int j = 0, ich = c; j < costList[i].Count; j++, c++, ich++)
                {
                    if (costList[i][j] * chromArray[ich] != 0)
                    {
                        list.AddEdge(i, costList[i][j]);
                    }
                }
            }
            AdjacencyList.PrintGraph(list);
            return(list);
        }