Exemplo n.º 1
0
 public override bool RuntimeValidation(ref string error)
 {
     // Get the zone system from the travel demand model
     if (ZoneSystemSource != null)
     {
         ZoneSystemSource.LoadData();
         ZoneSystem = ZoneSystemSource.GiveData();
     }
     else
     {
         if (Functions.ModelSystemReflection.GetRootOfType(Config, typeof(ITravelDemandModel), this, out IModelSystemStructure tdm))
         {
             ZoneSystem = ((ITravelDemandModel)tdm.Module).ZoneSystem;
             if (ZoneSystem != null && !ZoneSystem.Loaded)
             {
                 ZoneSystem.LoadData();
             }
         }
     }
     if (ZoneSystem == null)
     {
         error = $"In {Name} we were unable to load a zone system for our calculations!";
         return(false);
     }
     return(base.RuntimeValidation(ref error));
 }
Exemplo n.º 2
0
 private void LoadZoneData()
 {
     Status = "Loading Zone System";
     ZoneSystem.LoadData();
     Status = "Loading Demographics";
     Demographics.LoadData();
 }
Exemplo n.º 3
0
 public bool RuntimeValidation(ref string error)
 {
     if ((_SecondaryPool = Root.Pools.FirstOrDefault(p => p.Name == SecondaryPool.Data)) == null)
     {
         error = $"In '{Name}' we were unable to find a pool with the name '{SecondaryPool.Data}'.";
         return(false);
     }
     // this is safe because a parent's runtime validation will always execute first
     if ((_PrimaryAttribute = Parent._PrimaryPool.Attributes.FirstOrDefault(a => a.Name == PrimaryAttribute.Data)) == null)
     {
         error = $"In '{Name} we were unable to find an attribute called '{PrimaryAttribute.Data}' in the pool '{Parent._PrimaryPool.Name}'.'";
         return(false);
     }
     _SecondaryAttributes = SecondaryAttributes.Select(s => _SecondaryPool.Attributes.FirstOrDefault(at => at.Name == s.Data)).ToArray();
     for (int i = 0; i < _SecondaryAttributes.Length; i++)
     {
         if (_SecondaryAttributes[i] == null)
         {
             error = $"In '{Name}' we were unable to find an attribute named '{SecondaryAttributes[i].Data}' in the pool '{SecondaryPool.Name}'";
             return(false);
         }
     }
     // Get the zone system from the travel demand model
     if (ZoneSystemSource != null)
     {
         ZoneSystemSource.LoadData();
         ZoneSystem = ZoneSystemSource.GiveData();
     }
     else
     {
         if (Functions.ModelSystemReflection.GetRootOfType(Config, typeof(ITravelDemandModel), this, out IModelSystemStructure tdm))
         {
             ZoneSystem = ((ITravelDemandModel)tdm.Module).ZoneSystem;
             if (ZoneSystem != null && !ZoneSystem.Loaded)
             {
                 ZoneSystem.LoadData();
             }
         }
     }
     return(true);
 }
Exemplo n.º 4
0
 public bool RuntimeValidation(ref string error)
 {
     // Get the zone system from the travel demand model
     if (ZoneSystemSource != null)
     {
         ZoneSystemSource.LoadData();
         ZoneSystem = ZoneSystemSource.GiveData();
     }
     else
     {
         if (Functions.ModelSystemReflection.GetRootOfType(Config, typeof(ITravelDemandModel), this, out IModelSystemStructure tdm))
         {
             ZoneSystem = ((ITravelDemandModel)tdm.Module).ZoneSystem;
             if (ZoneSystem != null && !ZoneSystem.Loaded)
             {
                 ZoneSystem.LoadData();
             }
         }
     }
     // ZoneSystem can still be null at the end of this
     return(true);
 }
Exemplo n.º 5
0
        private void BuildHouseholdData()
        {
            // We actually don't need to startup the networks since we don't need their data.
            // We just need them so we know that the modes will be satisfied when running
            ZoneSystem.LoadData();
            HouseholdLoader.LoadData();
            var households = HouseholdLoader.ToArray();

            VehicleTypes.Add(AutoType);
            using (MemoryStream mem = new MemoryStream())
            {
                BinaryWriter writer = new BinaryWriter(mem);
                writer.Write(households.Length);
                var numberOfVehicleTypes = VehicleTypes.Count;
                writer.Write(numberOfVehicleTypes);
                for (int i = 0; i < numberOfVehicleTypes; i++)
                {
                    writer.Write(VehicleTypes[i].VehicleName);
                }
                foreach (var household in households)
                {
                    // write out all of the household attributes
                    writer.Write(household.HouseholdId);
                    writer.Write(household.Persons.Length);
                    for (int i = 0; i < numberOfVehicleTypes; i++)
                    {
                        writer.Write(household.Vehicles.Count((v) => v.VehicleType.VehicleName == VehicleTypes[i].VehicleName));
                    }
                    writer.Write(household.HomeZone.ZoneNumber);
                    SendAttached(writer, household);
                    foreach (var person in household.Persons)
                    {
                        // Send the person's information
                        writer.Write(person.Age);
                        writer.Write(person.Female);
                        writer.Write((Int32)person.EmploymentStatus);
                        writer.Write((Int32)person.Occupation);
                        if (person.EmploymentZone == null)
                        {
                            writer.Write(-1);
                        }
                        else
                        {
                            writer.Write(person.EmploymentZone.ZoneNumber);
                        }
                        writer.Write((Int32)person.StudentStatus);
                        if (person.SchoolZone == null)
                        {
                            writer.Write(-1);
                        }
                        else
                        {
                            writer.Write(person.SchoolZone.ZoneNumber);
                        }
                        writer.Write(person.Licence);

                        writer.Write(person.FreeParking);
                        SendAttached(writer, person);
                        // Start sending the trip chains
                        writer.Write(person.TripChains.Count);
                        foreach (var tripChain in person.TripChains)
                        {
                            writer.Write(tripChain.JointTripID);
                            writer.Write(tripChain.JointTripRep);
                            SendAttached(writer, tripChain);
                            writer.Write(tripChain.Trips.Count);
                            foreach (var trip in tripChain.Trips)
                            {
                                writer.Write(trip.OriginalZone.ZoneNumber);
                                writer.Write(trip.DestinationZone.ZoneNumber);
                                writer.Write((Int32)trip.Purpose);
                                writer.Write(trip.ActivityStartTime.Hours);
                                writer.Write(trip.ActivityStartTime.Minutes);
                                writer.Write(trip.ActivityStartTime.Seconds);
                                var mode = ((ITashaMode)trip[ObservedMode]);
                                if (mode == null)
                                {
                                    throw new XTMFRuntimeException(this, "In household #" + household.HouseholdId
                                                                   + " for Person #" + person.Id + " for Trip #" + trip.TripNumber + " there was no observed mode stored!");
                                }
                                writer.Write(mode.ModeName);
                                SendAttached(writer, trip);
                            }
                        }
                    }
                }
                writer.Flush();
                HouseholdData = mem.ToArray();
            }
        }