public FlowEvent(Flow flow) { Flow = flow; // time // TODO: jitter! Time = Simulation.Time + 1.0 / Flow.Speed; }
/// <summary> /// Pick a random flow from the array according to their priorities /// </summary> /// <param name="flows">Flow array</param> /// <returns></returns> public static Flow PickWithPriority(Flow[] flows) { // check improbable version if (flows.Length == 0) return null; // pick a random flow according to it's priority var rnd = Extenders.MathExtender.Random(); double delta = 1.0 / (double)flows.Sum(flow => flow.QoS); var probability = 0.0; foreach(var curr in flows) { probability += (double)curr.QoS * delta; if (rnd <= probability) return curr; } throw new ArithmeticException("Impossible!"); }
/// <summary> /// Register a new flow in the system /// </summary> /// <param name="flow">Flow to add</param> public static void AddFlow(Flow flow) { Array.Resize(ref Flows, Flows.Length + 1); Flows[Flows.Length - 1] = flow; Simulation.RegisterEvent(new FlowEvent(flow)); }
/// <summary> /// The planner action /// </summary> public abstract Symbol Action(Flow[] flows, Symbol lastSymbol);
/// <summary> /// Mark the block as used and request N blocks from flow queue /// </summary> /// <param name="flow">Flow to use</param> public void Use(Flow flow) { Use(flow, Modulation.Bpsk()); }
/// <summary> /// Mark the block as used, update the modulation type /// and request N blocks from flow queue /// </summary> /// <param name="flow"></param> /// <param name="modulation"></param> public void Use(Flow flow, Modulation modulation) { if (Used) throw new Exception("The block is already used!"); Modulation = modulation; Used = true; Flow = flow; if (flow == null) throw new Exception("No flow!"); if (flow.Data == null) throw new Exception("no data!"); Data = flow.Data.GetSlice(Size()); }