private int getRrAlohaAccess() { int access = -1; if (this.Access > 0) //maintains the transmission region { access = this.Access; } else { List <int> availableRegions = this.getFreeRegions(); if (availableRegions.Count <= 0) { access = 0; //no available regions } else { Random randomNumber = new Random(int.Parse(Guid.NewGuid().ToString().Substring(0, 8), System.Globalization.NumberStyles.HexNumber)); int accessIndex = randomNumber.Next(0, availableRegions.Count - 1); access = availableRegions[accessIndex]; } } if (this.Access > 0) // information frame updating { KeyValuePair <int, int> accessIndexes = Spectrum.GetIndexesFromAccess(access, this.frequencySegments); this.FrameInformation[accessIndexes.Key, accessIndexes.Value] = this.Id; } return(access); }
protected override void checkMinimums(double modifier) { KeyValuePair <int, int> indexes = Spectrum.GetIndexesFromAccess(this.Access, this.frequencySegments); double currentValue = this.EstimationMatrix[indexes.Key, indexes.Value]; double modifiedValue = this.EstimationMatrix[indexes.Key, indexes.Value] * modifier; if (modifiedValue < this.MinimumValue) { modifiedValue = this.MinimumValue; } this.EstimationMatrix[indexes.Key, indexes.Value] = modifiedValue; }
private List <int> getFreeRegions() { List <int> freeRegions = new List <int>(); int totalRegions = this.frequencySegments * this.timeSegments; for (int idx = 1; idx <= totalRegions; idx++) { KeyValuePair <int, int> indexes = Spectrum.GetIndexesFromAccess(idx, this.frequencySegments); if (this.FrameInformation[indexes.Key, indexes.Value] == 0) { freeRegions.Add(idx); } } return(freeRegions); }
private void applyBonusAndPenalties(BonusAndPenalties bonusOrPenalty, ExplorationType explorationType, int access) { double bonusOrPenaltyValue = 0; if (bonusOrPenalty == BonusAndPenalties.ALFA) { bonusOrPenaltyValue = this.Alfa; } else if (bonusOrPenalty == BonusAndPenalties.BETA) { bonusOrPenaltyValue = this.Beta; } else if (bonusOrPenalty == BonusAndPenalties.RHO) { bonusOrPenaltyValue = this.Rho; } else if (bonusOrPenalty == BonusAndPenalties.SIGMA) { bonusOrPenaltyValue = this.Sigma; } KeyValuePair <int, int> indices = Spectrum.GetIndexesFromAccess(access, this.frequencySegments); double modifiedValue = this.EstimationMatrix[indices.Key, indices.Value] * bonusOrPenaltyValue; double specificMaximum; if (explorationType == ExplorationType.ACCESS) { specificMaximum = this.MaximumValue; } else { specificMaximum = this.NonAccessMaximumValue; } if (modifiedValue < specificMaximum && modifiedValue > this.MinimumValue) { this.EstimationMatrix[indices.Key, indices.Value] = modifiedValue; } else if (modifiedValue < this.MinimumValue) { this.EstimationMatrix[indices.Key, indices.Value] = this.MinimumValue; } if (modifiedValue > specificMaximum) { this.EstimationMatrix[indices.Key, indices.Value] = specificMaximum; } }
protected override void processMessage(Message rxMessage) { if (rxMessage.Destination == this.Id) { this.PendingPositionX = (rxMessage.Content as FrameInfoMessage).PositionX; this.PendingPositionY = (rxMessage.Content as FrameInfoMessage).PositionY; } int[,] messageFrameInformation = (rxMessage.Content as FrameInfoMessage).FrameInformation; int totalRegions = this.frequencySegments * this.timeSegments; for (int idx = 1; idx <= totalRegions; idx++) { KeyValuePair <int, int> indexes = Spectrum.GetIndexesFromAccess(idx, this.frequencySegments); int incomingValue = messageFrameInformation[indexes.Key, indexes.Value]; if (incomingValue == 0) { if (this.FrameInformation[indexes.Key, indexes.Value] == rxMessage.Source) { //vehicle that has released the region this.FrameInformation[indexes.Key, indexes.Value] = incomingValue; } } else //(incomingValue != 0) { if (this.FrameInformation[indexes.Key, indexes.Value] == this.Id) //selected region for this vehicle { if (incomingValue != this.Id) { //This vehicle must select a new region because a previous collision this.Access = 0; //force the selection of a new region this.IsMacPending = true; } } this.FrameInformation[indexes.Key, indexes.Value] = incomingValue; } } }