private void InitializeAssignment() { // Get all of the initial ground truth data List <TransitLine> truthList = new List <TransitLine>(); // On the first pass go through all of the data and store the records of the TTS boardings using (StreamReader reader = new StreamReader(TruthFile)) { string line; while ((line = reader.ReadLine()) != null) { var split = line.Split(Comma, StringSplitOptions.RemoveEmptyEntries); TransitLine current = new TransitLine(); string currentName; current.Id = new[] { (currentName = split[1]) }; current.Bordings = float.Parse(split[0]); if (split.Length > 2) { current.Mode = split[2][0]; } else { current.Mode = 'b'; } // Check to make sure that there isn't another ID with this name already int count = truthList.Count; for (int j = 0; j < count; j++) { if (truthList[j].Id[0] == currentName) { throw new XTMFRuntimeException(this, $"The TTS record {currentName} at line {j + 1} has a duplicate entry on line {count + 1}"); } } truthList.Add(current); } } // now on the second pass go through and find all of the EMME Links that connect to the TTS data var truthEntries = truthList.Count; List <string>[] nameLinks = new List <string> [truthEntries]; using (StreamReader reader = new StreamReader(EmmetoTtsFile)) { string line; while ((line = reader.ReadLine()) != null) { var split = line.Split(Comma, StringSplitOptions.RemoveEmptyEntries); string ttsName = split[0]; string emmeName = split[1]; for (int i = 0; i < truthEntries; i++) { if (truthList[i].Id[0] == ttsName) { List <string> ourList; if ((ourList = nameLinks[i]) == null) { nameLinks[i] = ourList = new List <string>(); } ourList.Add(emmeName); break; } } } } // Now on the third pass we go through and apply all of the EMME ID's for (int i = 0; i < truthEntries; i++) { List <string> nameList; if ((nameList = nameLinks[i]) == null) { throw new XTMFRuntimeException(this, $"The TTS record {truthList[i].Id[0]} has no EMME Links associated with it. Aborting."); } var temp = truthList[i]; temp.Id = nameList.ToArray(); truthList[i] = temp; } Truth = truthList.ToArray(); }
public int BuildNetwork() { log("Retrieving Rooms"); List <Room> rooms = getRooms(); if ((rooms == null) || (rooms.Count == 0)) { return(0); // no rooms } Dictionary <ElementId, Models.RoomWithTransitLines> transitRooms = getRoomsWithTransitLines(); log("Determining Room Nodes"); // we need to find all of the connection between rooms, as determined by doors and room boundary lines. List <Node> roomNodes = getRoomNodes(rooms, transitRooms); log("Retrieving related doors"); List <ConnectionNode> relatedDoors = getRelatedDoors(rooms, transitRooms); List <ConnectionNode> relatedRoomSep = getRoomSeparations(rooms, transitRooms); List <ConnectionNode> allConnections = new List <ConnectionNode>(); allConnections.AddRange(relatedDoors); allConnections.AddRange(relatedRoomSep); //temp cleanup. foreach (var n in allConnections) { if (_allNodes.Count(a => a.Id == n.Id) > 0) { continue; } _allNodes.Add(n); } //_allNodes.AddRange(allConnections); foreach (Node room in roomNodes) { List <ConnectionNode> relevantDoors = allConnections.Where(d => (d.RoomId == room.RevitId) || (d.Room2 == room.RevitId)).ToList(); addNode(room); foreach (ConnectionNode node in relevantDoors) { addNode(node); makeEdge(room, node); } } // now we need to go through any transit rooms and connect those to any doors/separation lines... foreach (KeyValuePair <ElementId, RoomWithTransitLines> pair in transitRooms) { List <ConnectionNode> relevantDoors = allConnections.Where(d => (d.RoomId == pair.Key) || (d.Room2 == pair.Key)).ToList(); foreach (ConnectionNode node in relevantDoors) { // connect the node to the nearest way to attach to a transit line... Node connectNode = null; TransitLine tl = null; XYZ projection = pair.Value.GetNearestProjection(node.Location, out tl); if (projection == null) { // get the nearest endpoint connectNode = pair.Value.GetNearestEndPoint(node.Location); // see if the node already exists. var existing = lookupByXYZ(connectNode.Location); if (existing != null) { connectNode = existing; } } else { // make a new node for the projection connectNode = new Node() { LevelId = node.LevelId, Location = projection, NodeType = Node.NodeTypeEnum.TransitPoint, RoomId = pair.Key }; // see if the node already exists. var existing = lookupByXYZ(connectNode.Location); if (existing != null) { connectNode = existing; } } addNode(connectNode); makeEdge(connectNode, node); // we need to add edges to the two nodes on the ends of the line. if (tl != null) { if (connectNode.Location.DistanceTo(tl.End1.Location) > _doc.Application.ShortCurveTolerance) { makeEdge(connectNode, tl.End1); } if (connectNode.Location.DistanceTo(tl.End2.Location) > _doc.Application.ShortCurveTolerance) { makeEdge(connectNode, tl.End2); } } } } // final processing of rooms with transit lines. processRoomsWithTransit(transitRooms); drawAllConnections(allConnections.Cast <Node>().ToList()); //createLines(_allEdges); return(_allEdges.Count); }