private void CreateInterClusterEdges(Cluster cluster) { foreach (var point1 in cluster.EntrancePoints) foreach (var point2 in cluster.EntrancePoints) { if (point1 == point2) continue; if (cluster.AreConnected(point1, point2)) { var absTilingEdgeInfo1 = new AbsTilingEdgeInfo(cluster.GetDistance(point1.EntranceLocalIdx, point2.EntranceLocalIdx), 1, false); HierarchicalMap.AbstractGraph.AddEdge( point1.AbsNodeId, point2.AbsNodeId, absTilingEdgeInfo1); } } }
private void CreateEntrancesAndClusters(out List<Entrance> entrances, out List<Cluster> clusters) { var clusterId = 0; var entranceId = 0; entrances = new List<Entrance>(); clusters = new List<Cluster>(); // NOTE: Here we create bottom-level cluster instances. Maybe I could deal here with the levels // And create multi-level clusters for (int top = 0, clusterY = 0; top < ConcreteMap.Height; top += ClusterSize, clusterY++) for (int left = 0, clusterX = 0; left < ConcreteMap.Width; left += ClusterSize, clusterX++) { var horizSize = Math.Min(ClusterSize, ConcreteMap.Width - left); var vertSize = Math.Min(ClusterSize, ConcreteMap.Height - top); var cluster = new Cluster(ConcreteMap, clusterId++, clusterX, clusterY, new Position(left, top), new Size(horizSize, vertSize)); clusters.Add(cluster); // add inter-cluster entrances. Obviously we should not add entrances on leftmost clusters when adding vertical entrances // nor on topmost clusters when adding horizontal entrances. if (top > 0) { // We know getting the cluster above works because since we are generating // them from top to bottom, left to right, we know there must be some // cluster above. If we could not guarantee this at this point, we could // have null/out of bounds exceptions var clusterAbove = GetCluster(clusters, clusterX, clusterY - 1); int lastEntranceId; var hEntrances = CreateHorizEntrances( left, left + horizSize - 1, top - 1, clusterAbove.Id, cluster.Id, entranceId, out lastEntranceId); entranceId = lastEntranceId; entrances.AddRange(hEntrances); } if (left > 0) { int lastEntranceId; var clusterOnLeft = GetCluster(clusters, clusterX - 1, clusterY); var vEntrances = CreateVertEntrances( top, top + vertSize - 1, left - 1, clusterOnLeft.Id, cluster.Id, entranceId, out lastEntranceId); entranceId = lastEntranceId; entrances.AddRange(vEntrances); } } }