public bool FillDemandOnTable(ref RSATable table, Graph graph, Demand demand, GraphPath path, List <AvailableSlot> availableSlots, bool protection = false) { List <GraphLink> pathLinks = path.ToLinks(graph.Links); double totalDistance = pathLinks.Sum(r => r.Length); IModulationFormat format = null; int multiplier = 1; do { format = GetModulationFormat(demand, totalDistance, multiplier); multiplier++; } while (format == null); int numberOfSlots = (int)Math.Ceiling(demand.DemandInGBps / table.LinkCapacity); List <List <int> > emptySlots = new List <List <int> >(); foreach (var column in table.Table.Keys) { var reference = availableSlots.FirstOrDefault(r => r.Link.GetLinkId() == column); if (reference != null) { emptySlots.Add(new List <int>(reference.Availables)); } } List <int> intersection = emptySlots.First(); foreach (var list in emptySlots.Skip(1)) { intersection = intersection.Intersect(list).ToList(); } List <int> indexesToFill = GetIndexesToFill(intersection, numberOfSlots); if (indexesToFill == null) { return(false); } foreach (GraphLink link in pathLinks) { foreach (var slot in indexesToFill) { table.Table[link.GetLinkId()][slot].IsProtectionDemand = protection; table.Table[link.GetLinkId()][slot].Values.Add(demand.Id.ToString()); table.Table[link.GetLinkId()][slot].ModulationFormat = format; } } return(true); }
protected virtual List <AvailableSlot> GetAvailableTableSlots(Graph graph, GraphPath path, RSATable table) { List <AvailableSlot> availableSlots = new List <AvailableSlot>(); List <GraphLink> pathLinks = path.ToLinks(graph.Links); foreach (GraphLink link in pathLinks) { AvailableSlot element = new AvailableSlot(); element.Link = link; element.Availables = new List <int>(table.Table[link.GetLinkId()].Where(r => r.Value.Values.Count == 0).Select(r => r.Key).ToList()); availableSlots.Add(element); } return(availableSlots); }
public bool FillDemandOnTable(ref RSATable table, Graph graph, Demand demand, GraphPath path, List <AvailableSlot> availableSlots, bool protection = false) { List <GraphLink> pathLinks = path.ToLinks(graph.Links); List <List <int> > emptySlots = new List <List <int> >(); foreach (var column in table.Table.Keys) { var reference = availableSlots.FirstOrDefault(r => r.Link.GetLinkId() == column); if (reference != null) { emptySlots.Add(new List <int>(reference.Availables)); } } List <int> intersection = emptySlots.First(); foreach (var list in emptySlots.Skip(1)) { intersection = intersection.Intersect(list).ToList(); } List <int> indexesToFill = GetIndexesToFill(intersection, demand.Slots); if (indexesToFill == null) { return(false); } foreach (GraphLink link in pathLinks) { foreach (var slot in indexesToFill) { table.Table[link.GetLinkId()][slot].IsProtectionDemand = protection; table.Table[link.GetLinkId()][slot].Values.Add(demand.Id.ToString()); } } return(true); }