Esempio n. 1
0
        private static void RunExport(string path)
        {
            string directory = Path.GetDirectoryName(path);
            string filename  = Path.GetFileNameWithoutExtension(path);
            string extension = Path.GetExtension(path);
            int    zoneCount = Global.AggregateLogsums.GetLength(0);

            Framework.DomainModels.Persisters.IPersisterReader <IZone> zoneReader =
                Global
                .ContainerDaySim.GetInstance <IPersistenceFactory <IZone> >()
                .Reader;

            for (int purpose = Global.Settings.Purposes.HomeBasedComposite; purpose <= Global.Settings.Purposes.Social; purpose++)
            {
                if (directory == null)
                {
                    throw new DirectoryNotFoundException();
                }

                FileInfo file = new FileInfo(Path.Combine(directory, string.Format("{0}.{1}{2}", filename, purpose, extension)));

                using (StreamWriter writer = new StreamWriter(file.Open(FileMode.Create, FileAccess.Write, FileShare.Read))) {
                    writer.WriteLine("ZONE\tCHILD/SHO\tCHILD/LON\tCHILD/NAV\tNOCAR/SHO\tNOCAR/LON\tNOCAR/NAV\tCCOMP/SHO\tCCOMP/LON\tCCOMP/NAV\tCFULL/SHO\tCFULL/LON\tCFULL/NAV");

                    for (int id = 0; id < zoneCount; id++)
                    {
                        IZone zone = zoneReader.Seek(id);

                        writer.Write(string.Format("{0,4:0}", zone.Key));
                        writer.Write("\t");

                        double[][][] carOwnerships = Global.AggregateLogsums[id][purpose];

                        for (int carOwnership = Global.Settings.CarOwnerships.Child; carOwnership < Global.Settings.CarOwnerships.TotalCarOwnerships; carOwnership++)
                        {
                            double[][] votALSegments = carOwnerships[carOwnership];

                            for (int votALSegment = Global.Settings.VotALSegments.Low; votALSegment < Global.Settings.VotALSegments.TotalVotALSegments; votALSegment++)
                            {
                                double[] transitAccesses = votALSegments[votALSegment];

                                for (int transitAccess = Global.Settings.TransitAccesses.Gt0AndLteQtrMi; transitAccess < Global.Settings.TransitAccesses.TotalTransitAccesses; transitAccess++)
                                {
                                    writer.Write(string.Format("{0,9:f5}", transitAccesses[transitAccess]));

                                    if ((carOwnership + 1) * (transitAccess + 1) != Global.Settings.CarOwnerships.TotalCarOwnerships * Global.Settings.TransitAccesses.TotalTransitAccesses)
                                    {
                                        writer.Write("\t");
                                    }
                                }
                            }
                        }

                        writer.WriteLine();
                    }
                }

                Global.PrintFile.WriteFileInfo(file, true);
            }
        }
Esempio n. 2
0
        public ParkAndRideNodeDao()
        {
            Framework.DomainModels.Persisters.IPersisterReader <IParkAndRideNode> reader =
                Global
                .ContainerDaySim.GetInstance <IPersistenceFactory <IParkAndRideNode> >()
                .Reader;

            IParkAndRideNodeCreator creator =
                Global
                .ContainerDaySim
                .GetInstance <IWrapperFactory <IParkAndRideNodeCreator> >()
                .Creator;

            Dictionary <int, HashSet <int> > zoneIdKeys   = new Dictionary <int, HashSet <int> >();
            Dictionary <int, HashSet <int> > parcelIdKeys = new Dictionary <int, HashSet <int> >();

            Dictionary <int, Framework.ShadowPricing.IParkAndRideShadowPriceNode> parkAndRideShadowPrices = ParkAndRideShadowPriceReader.ReadParkAndRideShadowPrices();

            foreach (IParkAndRideNode parkAndRideNode in reader)
            {
                IParkAndRideNodeWrapper node = creator.CreateWrapper(parkAndRideNode);
                int id = node.Id;

                _nodes.Add(id, node);

                int zoneId = node.ZoneId;

                if (!zoneIdKeys.TryGetValue(zoneId, out HashSet <int> zoneIdKey))
                {
                    zoneIdKey = new HashSet <int>();

                    zoneIdKeys.Add(zoneId, zoneIdKey);
                }

                zoneIdKey.Add(id);

                int parcelId = node.NearestParcelId;

                if (!parcelIdKeys.TryGetValue(parcelId, out HashSet <int> parcelIdKey))
                {
                    parcelIdKey = new HashSet <int>();

                    parcelIdKeys.Add(parcelId, parcelIdKey);
                }

                node.SetParkAndRideShadowPricing(parkAndRideShadowPrices);

                parcelIdKey.Add(id);
            }

            foreach (KeyValuePair <int, HashSet <int> > entry in zoneIdKeys)
            {
                _zoneIdKeys.Add(entry.Key, entry.Value.ToArray());
            }

            foreach (KeyValuePair <int, HashSet <int> > entry in parcelIdKeys)
            {
                _parcelIdKeys.Add(entry.Key, entry.Value.ToArray());
            }
        }
        private SamplingWeightsCalculator(string variableName, int mode, int pathType, double vot, int minute)
        {
            Framework.DomainModels.Persisters.IPersisterReader <IZone> zoneReader =
                Global
                .ContainerDaySim.GetInstance <IPersistenceFactory <IZone> >()
                .Reader;

            Framework.DomainModels.Persisters.IPersisterReader <IParcel> parcelReader =
                Global
                .ContainerDaySim
                .GetInstance <IPersistenceFactory <IParcel> >()
                .Reader;

            IParcelCreator parcelCreator =
                Global
                .ContainerDaySim
                .GetInstance <IWrapperFactory <IParcelCreator> >()
                .Creator;

            _eligibleZones =
                zoneReader
                .Where(z => z.DestinationEligible)
                .ToDictionary(z => z.Id, z => z);

            foreach (IParcel parcel in parcelReader)
            {
                if (_eligibleZones.TryGetValue(parcel.ZoneId, out IZone zone))
                {
                    _eligibleParcels.Add(parcelCreator.CreateWrapper(parcel));
                }

                if (_parcelCounts.ContainsKey(parcel.ZoneId))
                {
                    _parcelCounts[parcel.ZoneId]++;
                }
                else
                {
                    _parcelCounts.Add(parcel.ZoneId, 1);
                }
            }

            _zoneCount    = zoneReader.Count;
            _segmentCount = Global.ContainerDaySim.GetInstance <SamplingWeightsSettingsFactory>().SamplingWeightsSettings.SizeFactors.GetLength(0);
            _variableName = variableName;
            _mode         = mode;
            _pathType     = pathType;
            _vot          = vot;
            _minute       = minute;
        }
        public AggregateLogsumsCalculator_Actum()
        {
            FileInfo file = Global.AggregateLogsumsPath.ToFile();

            //if (Global.Configuration.ShouldLoadAggregateLogsumsFromFile && file.Exists) {
            //  return;
            //}

            Framework.DomainModels.Persisters.IPersisterReader <IZone> zoneReader =
                Global
                .ContainerDaySim.GetInstance <IPersistenceFactory <IZone> >()
                .Reader;

            _eligibleZones     = zoneReader.Where(z => z.DestinationEligible).ToDictionary(z => z.Id, z => z);
            _zoneCount         = zoneReader.Count;
            _zoneSubzones      = CalculateZoneSubzones();
            _middayStartMinute = DayPeriod.BigDayPeriods[DayPeriod.MIDDAY].Start;
        }
        private ISubzone[][] CalculateZoneSubzones()
        {
            SubzoneFactory subzoneFactory = new SubzoneFactory(Global.Configuration);

            ISubzone[][] zoneSubzones = new ISubzone[_zoneCount][];

            for (int id = 0; id < _zoneCount; id++)
            {
                ISubzone[] subzones = new ISubzone[TOTAL_SUBZONES];

                zoneSubzones[id] = subzones;

                for (int subzone = 0; subzone < TOTAL_SUBZONES; subzone++)
                {
                    subzones[subzone] = subzoneFactory.Create(subzone);
                }
            }

            Framework.DomainModels.Persisters.IPersisterReader <IParcel> parcelReader =
                Global
                .ContainerDaySim
                .GetInstance <IPersistenceFactory <IParcel> >()
                .Reader;

            IParcelCreator parcelCreator =
                Global
                .ContainerDaySim
                .GetInstance <IWrapperFactory <IParcelCreator> >()
                .Creator;

            foreach (IParcel parcel in parcelReader)
            {
                Framework.DomainModels.Wrappers.IParcelWrapper parcelWrapper = parcelCreator.CreateWrapper(parcel);

                ISubzone[] subzones = zoneSubzones[parcelWrapper.ZoneId];
                // var subzone = (parcel.GetDistanceToTransit() > 0 && parcel.GetDistanceToTransit() <= .5) ? 0 : 1;
                // JLBscale replaced above with following:
                int subzone = (parcelWrapper.GetDistanceToTransit() / Global.Settings.DistanceUnitsPerMile > 0 && parcelWrapper.GetDistanceToTransit() / Global.Settings.DistanceUnitsPerMile <= .5) ? 0 : 1;

                subzones[subzone].Households           += parcelWrapper.Households;
                subzones[subzone].StudentsK8           += parcelWrapper.StudentsK8;
                subzones[subzone].StudentsHighSchool   += parcelWrapper.StudentsHighSchool;
                subzones[subzone].StudentsUniversity   += parcelWrapper.StudentsUniversity;
                subzones[subzone].EmploymentEducation  += parcelWrapper.EmploymentEducation;
                subzones[subzone].EmploymentFood       += parcelWrapper.EmploymentFood;
                subzones[subzone].EmploymentGovernment += parcelWrapper.EmploymentGovernment;
                subzones[subzone].EmploymentIndustrial += parcelWrapper.EmploymentIndustrial;
                subzones[subzone].EmploymentMedical    += parcelWrapper.EmploymentMedical;
                subzones[subzone].EmploymentOffice     += parcelWrapper.EmploymentOffice;
                subzones[subzone].EmploymentRetail     += parcelWrapper.EmploymentRetail;
                subzones[subzone].EmploymentService    += parcelWrapper.EmploymentService;
                subzones[subzone].EmploymentTotal      += parcelWrapper.EmploymentTotal;
                //Removed following that are not defined the same way in actum.  Need to accommodate parking soem other way
                //subzones[subzone].ParkingOffStreetPaidDailySpaces += parcelWrapper.ParkingOffStreetPaidDailySpaces;
                //subzones[subzone].ParkingOffStreetPaidHourlySpaces += parcelWrapper.ParkingOffStreetPaidHourlySpaces;
            }

            foreach (ISubzone[] subzones in _eligibleZones.Values.Select(zone => zoneSubzones[zone.Id]))
            {
                for (int subzone = 0; subzone < TOTAL_SUBZONES; subzone++)
                {
                    double       hou = subzones[subzone].Households;
                    double       k12 = subzones[subzone].StudentsK8 + subzones[subzone].StudentsHighSchool;
                    double       uni = subzones[subzone].StudentsUniversity;
                    double       edu = subzones[subzone].EmploymentEducation;
                    double       foo = subzones[subzone].EmploymentFood;
                    double       gov = subzones[subzone].EmploymentGovernment;
                    double       ind = subzones[subzone].EmploymentIndustrial;
                    double       med = subzones[subzone].EmploymentMedical;
                    double       off = subzones[subzone].EmploymentOffice;
                    double       ret = subzones[subzone].EmploymentRetail;
                    double       ser = subzones[subzone].EmploymentService;
                    double       tot = subzones[subzone].EmploymentTotal;
                    const double oth = 0;

                    double subtotal = foo + ret + ser + med;


                    //subzones[subzone].MixedUseMeasure = Math.Log(1 + subtotal * (subzones[subzone]).ParkingOffStreetPaidHourlySpaces * 100 / Math.Max(subtotal + (subzones[subzone]).ParkingOffStreetPaidHourlySpaces * 100, Constants.EPSILON));
                    //zeroed out above MixedUseMeasure because it relies on parking variable not available for actum
                    subzones[subzone].MixedUseMeasure = 0;

                    subzones[subzone].SetSize(Global.Settings.Purposes.HomeBasedComposite, ComputeSize(Math.Exp(HBG019) * edu + Math.Exp(HBG020) * foo + Math.Exp(HBG021) * gov + Math.Exp(HBG022) * off + Math.Exp(HBG023) * oth + Math.Exp(HBG024) * ret + Math.Exp(HBG025) * ser + Math.Exp(HBG026) * med + Math.Exp(HBG027) * ind + Math.Exp(HBG029) * hou + Math.Exp(HBG030) * uni + Math.Exp(HBG031) * k12));
                    subzones[subzone].SetSize(Global.Settings.Purposes.WorkBased, ComputeSize(Math.Exp(WBG019) * edu + Math.Exp(WBG020) * foo + Math.Exp(WBG021) * gov + Math.Exp(WBG022) * off + Math.Exp(WBG023) * oth + Math.Exp(WBG024) * ret + Math.Exp(WBG025) * ser + Math.Exp(WBG026) * med + Math.Exp(WBG027) * ind + Math.Exp(WBG029) * hou + Math.Exp(WBG030) * uni));
                    subzones[subzone].SetSize(Global.Settings.Purposes.Escort, ComputeSize(Math.Exp(PSG067) * edu + Math.Exp(PSG068) * foo + Math.Exp(PSG069) * gov + Math.Exp(PSG070) * off + Math.Exp(PSG071) * oth + Math.Exp(PSG072) * ret + Math.Exp(PSG073) * ser + Math.Exp(PSG074) * med + Math.Exp(PSG075) * ind + Math.Exp(PSG077) * hou + Math.Exp(PSG078) * uni + k12));
                    subzones[subzone].SetSize(Global.Settings.Purposes.PersonalBusiness, ComputeSize(Math.Exp(PSG080) * edu + Math.Exp(PSG081) * foo + Math.Exp(PSG082) * gov + Math.Exp(PSG083) * off + Math.Exp(PSG084) * oth + Math.Exp(PSG085) * ret + Math.Exp(PSG086) * ser + Math.Exp(PSG087) * med + Math.Exp(PSG088) * ind + Math.Exp(PSG090) * hou + Math.Exp(PSG091) * uni));
                    subzones[subzone].SetSize(Global.Settings.Purposes.Shopping, ComputeSize(Math.Exp(PSG094) * foo + Math.Exp(PSG095) * gov + Math.Exp(PSG097) * oth + Math.Exp(PSG098) * ret + Math.Exp(PSG099) * ser + Math.Exp(PSG100) * med + Math.Exp(PSG103) * hou + Math.Exp(PSG105) * k12));
                    subzones[subzone].SetSize(Global.Settings.Purposes.Meal, ComputeSize(Math.Exp(PSG107) * foo + Math.Exp(PSG115) * tot + Math.Exp(PSG117) * uni));
                    subzones[subzone].SetSize(Global.Settings.Purposes.Social, ComputeSize(Math.Exp(PSG119) * edu + Math.Exp(PSG120) * foo + Math.Exp(PSG121) * gov + Math.Exp(PSG122) * off + Math.Exp(PSG123) * oth + Math.Exp(PSG125) * ser + Math.Exp(PSG126) * med + Math.Exp(PSG129) * hou + Math.Exp(PSG130) * uni));
                }
            }

            return(zoneSubzones);
        }
Esempio n. 6
0
        public static void LoadData()
        {
            Framework.DomainModels.Persisters.IPersisterReader <IParcel> parcelReader =
                Global
                .ContainerDaySim.GetInstance <IPersistenceFactory <IParcel> >()
                .Reader;

            IParcelCreator parcelCreator =
                Global
                .ContainerDaySim
                .GetInstance <IWrapperFactory <IParcelCreator> >()
                .Creator;

            Parcels = new Dictionary <int, IParcelWrapper>(parcelReader.Count);

            Framework.DomainModels.Persisters.IPersisterReader <IZone> zoneReader =
                Global
                .ContainerDaySim
                .GetInstance <IPersistenceFactory <IZone> >()
                .Reader;

            //            ZoneTotals = new Dictionary<int, ZoneTotals>(zoneReader.Count);
            ZoneKeys = new Dictionary <int, int>(zoneReader.Count);

            Dictionary <int, IZone> zones = new Dictionary <int, IZone>();

            foreach (IZone zone in zoneReader)
            {
                ZoneKeys.Add(zone.Id, zone.Key);
                zones.Add(zone.Id, zone);
            }

            Dictionary <int, Framework.ShadowPricing.IShadowPriceParcel> shadowPrices = ShadowPriceReader.ReadShadowPrices();

            foreach (IParcel parcel in parcelReader)
            {
                IParcelWrapper parcelWrapper = parcelCreator.CreateWrapper(parcel);

                Parcels.Add(parcel.Id, parcelWrapper);


                if (zones.TryGetValue(parcel.ZoneId, out IZone zone))
                {
                    parcelWrapper.District = zone.External;
                }

                parcelWrapper.SetShadowPricing(zones, shadowPrices);

                //                ZoneTotals zoneTotals;
                //
                //                if (!ZoneTotals.TryGetValue(parcel.ZoneId, out zoneTotals)) {
                //                    zoneTotals = new ZoneTotals();
                //
                //                    ZoneTotals.Add(parcel.ZoneId, zoneTotals);
                //                }
                //
                //                zoneTotals.SumTotals(parcel);
            }

            if (Global.DestinationParkingNodeIsEnabled)
            {
                DestinationParkingNodeDao = new DestinationParkingNodeDao();
            }
            if (Global.ParkAndRideNodeIsEnabled)
            {
                ParkAndRideNodeDao = new ParkAndRideNodeDao();
            }
        }