public TouchingConstraints(IMapDescription <TNode> mapDescription, IPolygonOverlap <TShapeContainer> polygonOverlap)
 {
     this.mapDescription = mapDescription;
     this.polygonOverlap = polygonOverlap;
     stageOneGraph       = mapDescription.GetStageOneGraph();
     graph = mapDescription.GetGraph();
 }
        private void DoMapping()
        {
            var graph         = mapDescription.GetGraph();
            var stageOneGraph = mapDescription.GetStageOneGraph();

            foreach (var vertex in graph.Vertices)
            {
                // Create vertices mapping
                nodeToIntMapping.Add(vertex, nodeToIntMapping.Count);
                mappedGraph.AddVertex(nodeToIntMapping[vertex]);

                // Store room description
                roomDescriptions[nodeToIntMapping[vertex]] = mapDescription.GetRoomDescription(vertex);
            }

            // Handle main graph edges
            foreach (var edge in graph.Edges)
            {
                mappedGraph.AddEdge(nodeToIntMapping[edge.From], nodeToIntMapping[edge.To]);
            }

            // Handle stage one graph vertices
            foreach (var vertex in stageOneGraph.Vertices)
            {
                mappedStageOneGraph.AddVertex(nodeToIntMapping[vertex]);
            }

            // Handle stage one graph edges
            foreach (var edge in stageOneGraph.Edges)
            {
                mappedStageOneGraph.AddEdge(nodeToIntMapping[edge.From], nodeToIntMapping[edge.To]);
            }
        }
Example #3
0
 public CorridorConstraints(IMapDescription <TNode> mapDescription, float averageSize, IConfigurationSpaces <TNode, TShapeContainer, TConfiguration, ConfigurationSpace> configurationSpaces)
 {
     this.mapDescription      = mapDescription;
     this.energySigma         = 10 * averageSize;     // TODO: should it be like this?
     this.configurationSpaces = configurationSpaces;
     stageOneGraph            = mapDescription.GetStageOneGraph();
     graph = mapDescription.GetGraph();
 }
Example #4
0
 protected AbstractLayoutOperations(IConfigurationSpaces <TNode, TShapeContainer, TConfiguration, ConfigurationSpace> configurationSpaces, int averageSize, IMapDescription <TNode> mapDescription, IRoomShapesHandler <TLayout, TNode, TShapeContainer> roomShapesHandler)
 {
     ConfigurationSpaces = configurationSpaces;
     AverageSize         = averageSize;
     MapDescription      = mapDescription;
     RoomShapesHandler   = roomShapesHandler;
     StageOneGraph       = mapDescription.GetStageOneGraph();
 }
        public RoomShapesHandler(
            IConfigurationSpaces <TNode, IntAlias <PolygonGrid2D>, TConfiguration, ConfigurationSpace> configurationSpaces,
            TwoWayDictionary <RoomTemplateInstance, IntAlias <PolygonGrid2D> > intAliasMapping,
            IMapDescription <TNode> mapDescription,
            RoomTemplateRepeatMode?repeatModeOverride = null)
        {
            this.configurationSpaces = configurationSpaces;
            this.intAliasMapping     = intAliasMapping;
            this.mapDescription      = mapDescription;
            this.repeatModeOverride  = repeatModeOverride;
            stageOneGraph            = mapDescription.GetStageOneGraph();

            Initialize();
        }
Example #6
0
        /// <inheritdoc />
        public List <Chain <TNode> > GetChains(IGraph <TNode> graph)
        {
            // Get all the faces from the stage one graph
            var stageOneGraph = mapDescription.GetStageOneGraph();
            var faces         = decomposition.GetChains(stageOneGraph);

            var usedVertices         = new HashSet <TNode>();
            var notUsedStageTwoRooms = graph.Vertices.Where(x => mapDescription.GetRoomDescription(x).Stage == 2).ToList();

            // Iterate through all the faces, marking all the seen vertices
            // As soon as all the neighbors of a stage two room are used, add the stage two room to the current face
            foreach (var face in faces)
            {
                // TODO: weird ForEach
                face.Nodes.ToList().ForEach(x => usedVertices.Add(x));

                foreach (var stageTwoRoom in notUsedStageTwoRooms.ToList())
                {
                    var neighbors = graph.GetNeighbours(stageTwoRoom).ToList();

                    if (neighbors.TrueForAll(x => usedVertices.Contains(x)))
                    {
                        notUsedStageTwoRooms.Remove(stageTwoRoom);
                        face.Nodes.Add(stageTwoRoom);
                    }
                }
            }

            // It must not happen that a stage two room is not in the decomposition
            if (notUsedStageTwoRooms.Count != 0)
            {
                throw new ArgumentException();
            }

            return(faces);
        }