Example #1
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);
        }
Example #2
0
        /// <summary>
        /// Создание нового экземлпяра списка смежности на основе указанного графа.
        /// </summary>
        /// <param name="graph">Исходный граф.</param>
        /// <returns>Новый экземпляр графа, задаваемого списком смежности.</returns>
        public static AdjacencyList GenerateList(MainGraph graph)
        {
            var list = new AdjacencyList(graph.VertexCount);

            var vertices = graph.Vertices.ToList();

            foreach (var edge in graph.Edges)
            {
                int source = vertices.IndexOf(edge.Source);
                int target = vertices.IndexOf(edge.Target);
                list.AddEdge(source, target);
            }
            PrintGraph(list);
            return(list);
        }