Ejemplo n.º 1
0
            //            public bool Available { get; set; }
            //            public bool IsChosen { get; set; }

            public override void Initialize(DestinationSampler destinationSampler, int destinationParcelId, int destinationParcelSequence, SegmentZone destinationSegmentZone)
            {
                _weightFromOrigin      = destinationSampler._originSegmentZone.GetWeight(destinationSegmentZone.Id);
                _totalWeightFromOrigin = destinationSampler._originSegmentZone.TotalWeight;

                TotalWeightFromDestination = destinationSegmentZone.TotalWeight;

                ParcelId = destinationParcelId;

                //if (Global.Configuration.DestinationScale == Constants.DestinationScale.ZONE) {
                //	return;
                //}

                SizeFromDestination      = destinationSegmentZone.GetSize(destinationParcelSequence);
                TotalSizeFromDestination = destinationSegmentZone.TotalSize;
            }
Ejemplo n.º 2
0
        private TSampleItem GetDestination <TSampleItem>(RandomUniform01 randomUniform01, IParcel originParcel, SegmentZone originSegmentZone, IParcel excludedParcel, SegmentZone excludedSegmentZone) where TSampleItem : ISampleItem, new()
        {
            var         destinationZoneId      = 0;
            SegmentZone destinationSegmentZone = null;

            var destinationParcelSequence = 0;
            var destinationParcelId       = 0;
            var destinationParcelIsValid  = false;

            var random = randomUniform01.Uniform01() * originSegmentZone.TotalWeight;

            if (random > .001)
            {
                var total = 0D;

                // draw the zone
                foreach (var weight in originSegmentZone.RankedWeights)
                {
                    total += weight.Value;

                    if (total <= random)
                    {
                        continue;
                    }

                    destinationZoneId      = weight.Id;
                    destinationSegmentZone = _segmentZones[weight.Id];

                    break;
                }
            }

            if (destinationSegmentZone != null && destinationSegmentZone.Key == 0)
            {
            }

            if (destinationSegmentZone == null)
            {
                destinationZoneId      = originParcel.ZoneId;
                destinationSegmentZone = originSegmentZone;
            }

            var excludedSize = 0D;

            if (Global.Settings.DestinationScale == Global.Settings.DestinationScales.Parcel)
            {
                if (destinationZoneId == originParcel.ZoneId)
                {
                    excludedSize += originSegmentZone.GetSize(originParcel.Sequence);
                }

                if (excludedParcel != null && destinationZoneId == excludedParcel.ZoneId)
                {
                    excludedSize += excludedSegmentZone.GetSize(excludedParcel.Sequence);
                }
            }
            if (Global.Settings.DestinationScale == Global.Settings.DestinationScales.Zone)
            {
                if (destinationSegmentZone.Key == 0)
                {
                }
                destinationParcelId       = destinationSegmentZone.Key;
                destinationParcelSequence = 0;
                destinationParcelIsValid  = true;
            }
            else
            {
                //				if (destinationSegmentZone.TotalSize - excludedSize < Constants.EPSILON) {
                //					Console.WriteLine(originSegmentZone.Id);
                //					Console.WriteLine(originSegmentZone.TotalWeight);
                //					Console.WriteLine(originSegmentZone.TotalSize);
                //					Console.WriteLine(destinationSegmentZone.Id);
                //					Console.WriteLine(destinationSegmentZone.TotalWeight);
                //					Console.WriteLine(destinationSegmentZone.TotalSize);
                //					Console.WriteLine(excludedSize);
                //				}

                random = randomUniform01.Uniform01() * (destinationSegmentZone.TotalSize - excludedSize);

                if (random > .001)
                {
                    var total = 0D;

                    // draw the parcel within zone
                    foreach (var size in destinationSegmentZone.RankedSizes)
                    {
                        if (Global.Settings.DestinationScale == Global.Settings.DestinationScales.MicroZone ||
                            (originParcel.Id != size.Id && (excludedParcel == null || excludedParcel.Id != size.Id)))
                        {
                            total += size.Value;
                        }

                        if (total <= random)
                        {
                            continue;
                        }

                        // don't include the drawn parcel if the parcel has no size
                        if (size.Value >= Global.Configuration.MinParcelSize)
                        {
                            destinationParcelId       = size.Id;
                            destinationParcelSequence = size.Sequence;
                            destinationParcelIsValid  = true;
                        }

                        break;
                    }
                }
            }

            if (Global.Settings.DestinationScale != Global.Settings.DestinationScales.Zone && !destinationParcelIsValid)
            {
                return(default(TSampleItem));
            }

            var sampleItem = new TSampleItem();

            sampleItem.Initialize(this, destinationParcelId, destinationParcelSequence, destinationSegmentZone);

            if (destinationParcelIsValid)
            {
                sampleItem.ExcludedSize = excludedSize;
            }

            return(sampleItem);
        }