Пример #1
0
 public LayoutOperationsWithCorridors(
     IConfigurationSpaces <TNode, TShapeContainer, TConfiguration, ConfigurationSpace> configurationSpaces,
     ICorridorMapDescription <TNode> mapDescription,
     IConfigurationSpaces <TNode, TShapeContainer, TConfiguration, ConfigurationSpace> corridorConfigurationSpaces,
     int averageSize
     ) : base(configurationSpaces, averageSize)
 {
     MapDescription = mapDescription;
     CorridorConfigurationSpaces = corridorConfigurationSpaces;
     GraphWithoutCorridors       = mapDescription.GetGraphWithoutCorrridors();
 }
        /// <inheritdoc />
        public List <List <TNode> > GetChains(IGraph <TNode> graph)
        {
            if (!mapDescription.IsWithCorridors)
            {
                throw new InvalidOperationException("Map description must be with corridors to use this decomposition.");
            }

            var graphWithoutCorridors = mapDescription.GetGraphWithoutCorrridors();
            var faces = decomposition.GetChains(graphWithoutCorridors);

            var usedVertices = new HashSet <TNode>();
            var corridors    = graph.Vertices.Where(x => mapDescription.IsCorridorRoom(x)).ToList();

            foreach (var face in faces)
            {
                face.ForEach(x => usedVertices.Add(x));

                var corridorsToRemove = new List <TNode>();
                foreach (var corridor in corridors)
                {
                    var neighbours = graph.GetNeighbours(corridor).ToList();

                    if (neighbours.Count != 2)
                    {
                        throw new ArgumentException("Every corridor must have exactly two neighbours");
                    }

                    if (usedVertices.Contains(neighbours[0]) && usedVertices.Contains(neighbours[1]))
                    {
                        corridorsToRemove.Add(corridor);
                        face.Add(corridor);
                    }
                }
                corridorsToRemove.ForEach(x => corridors.Remove(x));
            }

            if (corridors.Count != 0)
            {
                throw new ArgumentException();
            }

            return(faces);
        }