public void RemoveConnection(Carpools.Carpooler Pooler) { /* Remove all CConnections and Connections related the deleted Pooler */ foreach (long id in Pooler.networkIdCCList) { bool removedFromCConnection = false; bool removedFromConnection = false; if (CConnections.ContainsKey(id)) { CConnections.Remove(id); //log.Info("Pooler=" + Pooler.Id + ": removed connection id=" + id + " from CConnections"); removedFromCConnection = true; } if (Connections.ContainsKey(id)) { Connections.Remove(id); //log.Info("Pooler=" + Pooler.Id + ": removed connection id=" + id + " from Connections"); removedFromConnection = true; } if (!removedFromCConnection) { throw new Exception("Removing Carpooler ride from the CConnection network: ride not found (should be there!)"); } if (!removedFromConnection) { throw new Exception("Removing Carpooler ride from the Connection network: ride not found (should be there!)"); } /* Update the index */ __NumCCDeleted++; /* Remove all Connections related the Pooler ride from all CNodes (and delete the CNode if no more connections are available) */ List <long> CNodesKeyToRemove = new List <long> { }; foreach (KeyValuePair <long, CNode> CN in CNodes) { List <Connection> connToRemove = new List <Connection> { }; foreach (Connection C in CN.Value.Connections) { if (Pooler.networkIdCCList.Contains(C.Id)) { connToRemove.Add(C); } } if (connToRemove.Count > 0) { foreach (Connection C in connToRemove) { CN.Value.Connections.Remove(C); //log.Info("Pooler=" + Pooler.Id + ": removed Connection id=" + C.Id + " from Cnode key=" + CN.Key); } if ((CN.Value.Connections.Count == 0) || ((CN.Value.Connections.Count == 1) && (CN.Value.Connections[0] is LConnection))) { /* Add the CNode to remove into a list (will be removed below) */ CNodesKeyToRemove.Add(CN.Key); /* Remove the LConnection node from the Connections */ if (CN.Value.Connections[0] is LConnection) { if (Connections.ContainsKey(CN.Key)) { Connections.Remove(CN.Key); //log.Info("Pooler=" + Pooler.Id + ": removed CNode key=" + CN.Key + " from Connection"); __NumCCDeleted++; } } } } } foreach (long cnodekey in CNodesKeyToRemove) { if (CNodes.ContainsKey(cnodekey)) { CNodes.Remove(cnodekey); //log.Info("Removed CNode key=" + cnodekey); } } } /* Remove the Pooler Connection */ if (Carpoolers.Contains(Pooler)) { Carpoolers.Remove(Pooler); log.Info("Carpooler id:" + Pooler.Id + " Name:" + Pooler.Name + " Provider:" + Pooler.Provider + " Departure:" + Pooler.WayPointsOrig.First().Latitude + "," + Pooler.WayPointsOrig.First().Longitude + " Destination:" + Pooler.WayPointsOrig.Last().Latitude + "," + Pooler.WayPointsOrig.Last().Longitude + " TripDate:" + Pooler.TripDate + " TripStartTime:" + Pooler.TripStartTime + " removed from the network"); } else { throw new Exception("Removing Carpooler Carpoolers list: pooler not found (should be there!)"); } }
public CConnection AddConnection(CNode src, CNode dst, int srcArrivalTime, int dstArrivalTime, ref Carpools.Carpooler Pooler, Dictionary <string, string> tags) { __MaxArcID = Connections.Count + __NumCCDeleted + 1; CConnection C = new CConnection(__MaxArcID, src, dst, srcArrivalTime, dstArrivalTime, Pooler, tags); src.Connections.Add(C); Connections.Add(__MaxArcID, C); CConnections.Add(__MaxArcID, C); Pooler.networkIdCCList.Add(__MaxArcID); ++(__MaxArcID); return(C); }
public void AddCarpooler(Carpools.Carpooler Pooler) { this.Carpoolers.Add(Pooler); }
public void RemoveCarpooler(Carpools.Carpooler Pooler) { this.Carpoolers.Remove(Pooler); }
public CConnection(long id, CNode src, CNode dst, int srcArrivalTime, int dstArrivalTime, Carpools.Carpooler Pooler, Dictionary <string, string> tags) : base(id) { this.Source = src; this.Destination = dst; this.Distance = Source.Point.DistanceFrom(Destination.Point); this.DepartureTime = srcArrivalTime; this.SrcArrivalTime = srcArrivalTime; this.DstArrivalTime = dstArrivalTime; this.ResidualCapacity = Pooler.Capacity; this.Carpooler = Pooler; this.Tags = new Dictionary <string, string>(tags); ValidityDayTableEntry entry = new ValidityDayTableEntry(Pooler.Id, Pooler.TripDate, Pooler.Activated); CCValidityStartDayTable.Entries.Add(entry); }