Exemple #1
0
        override public void Generate(Datastructure.SparseArray <float> production, Datastructure.SparseArray <float> attractions)
        {
            var flatProduction = production.GetFlatData();
            var flatAttraction = attractions.GetFlatData();

            var numberOfIndexes = flatAttraction.Length;

            // Compute the Production and Attractions
            float totalProduction = 0;
            float totalAttraction = 0;

            totalProduction = ComputeProduction(flatProduction, numberOfIndexes);
            totalAttraction = ComputeAttraction(flatAttraction, this.Root.ZoneSystem.ZoneArray.GetFlatData(), numberOfIndexes);

            // Normalize the attractions
            float productionAttractionRatio;

            if (totalAttraction != 0)
            {
                productionAttractionRatio = totalProduction / totalAttraction; // inverse totalAttraction to save on divisions
            }
            else
            {
                productionAttractionRatio = totalProduction / numberOfIndexes;
            }
            for (int i = 0; i < numberOfIndexes; i++)
            {
                flatAttraction[i] = flatAttraction[i] * productionAttractionRatio;
            }
        }
        private SchedulerTrip LoadTrip(BinaryReader reader, Datastructure.SparseArray <IZone> zoneArray, SchedulerTripChain chain, int tripNumber)
        {
            SchedulerTrip trip = SchedulerTrip.GetTrip(HouseholdIterations);

            trip.TripNumber = tripNumber;
            trip.TripChain  = chain;
            // figure out where we are going
            trip.OriginalZone    = zoneArray[reader.ReadInt32()];
            trip.DestinationZone = zoneArray[reader.ReadInt32()];
            trip.Purpose         = (Activity)reader.ReadInt32();
            // And learn when we are leaving, and at what time we need to get there
            Time time = new Time();

            // The activity's start time
            time.Hours             = reader.ReadInt32();
            time.Minutes           = reader.ReadInt32();
            time.Seconds           = reader.ReadInt32();
            trip.ActivityStartTime = time;
            // Get the observed mode
            var modeName = reader.ReadString();

            for (int i = 0; i < AllModes.Count; i++)
            {
                if (modeName == AllModes[i].ModeName)
                {
                    trip.ObservedMode = AllModes[i];
                }
            }
            LoadKeys(reader, trip);
            return(trip);
        }
        private TashaPerson LoadPerson(BinaryReader reader, Datastructure.SparseArray <IZone> zoneArray, TashaHousehold household, int personID)
        {
            TashaPerson person = new TashaPerson();

            person.Household        = household;
            person.Id               = personID;
            person.Age              = reader.ReadInt32();
            person.Female           = reader.ReadBoolean();
            person.EmploymentStatus = (TTSEmploymentStatus)reader.ReadInt32();
            person.Occupation       = (Occupation)reader.ReadInt32();
            person.EmploymentZone   = zoneArray[reader.ReadInt32()];
            person.StudentStatus    = (StudentStatus)reader.ReadInt32();
            person.SchoolZone       = zoneArray[reader.ReadInt32()];
            person.Licence          = reader.ReadBoolean();
            person.FreeParking      = reader.ReadBoolean();
            int numberOfTripChains;

            LoadKeys(reader, person);
            person.TripChains = new List <ITripChain>(numberOfTripChains = reader.ReadInt32());
            for (int i = 0; i < numberOfTripChains; i++)
            {
                person.TripChains.Add(LoadTripChain(reader, zoneArray, person));
            }
            return(person);
        }
Exemple #4
0
 private void CombineData(Datastructure.SparseArray <IZone> zones, float[][] matrix)
 {
     foreach (var source in DataSources)
     {
         foreach (var dataPoint in source.Read())
         {
             var o = zones.GetFlatIndex(dataPoint.O);
             var d = zones.GetFlatIndex(dataPoint.D);
             matrix[o][d] += dataPoint.Data;
         }
     }
 }
        private TashaHousehold LoadHousehold(BinaryReader reader, Datastructure.SparseArray <IZone> zoneArray)
        {
            var household = new TashaHousehold();
            int numberOfPeople;

            household.HouseholdId = reader.ReadInt32();
            // Learn how many people this household has and their number of vehicles
            household.Persons = new ITashaPerson[(numberOfPeople = reader.ReadInt32())];
            var vehicleList = new List <IVehicle>();

            // Produce the vehicles, all auto since it is the only type of resource we have
            for (int i = 0; i < VehicleTypes.Count; i++)
            {
                var numberOfVehicles = reader.ReadInt32();
                for (int j = 0; j < numberOfVehicles; j++)
                {
                    vehicleList.Add(TashaVehicle.MakeVehicle(VehicleTypes[i]));
                }
            }
            household.Vehicles = vehicleList.ToArray();
            household.HomeZone = zoneArray[reader.ReadInt32()];
            LoadKeys(reader, household);
            // now we can go and load the people
            for (int i = 0; i < numberOfPeople; i++)
            {
                household.Persons[i] = LoadPerson(reader, zoneArray, household, i);
            }
            // Link in the joint trip chain trip chains
            foreach (var person in household.Persons)
            {
                foreach (var tc in person.TripChains)
                {
                    if (tc.JointTrip)
                    {
                        if (tc.JointTripRep)
                        {
                            ((SchedulerTripChain)tc).GetRepTripChain = tc;
                        }
                        else
                        {
                            ((SchedulerTripChain)tc).GetRepTripChain = FindRepTripChain((SchedulerTripChain)tc, person.Household);
                        }
                    }
                }
            }
            return(household);
        }
        private SchedulerTripChain LoadTripChain(BinaryReader reader, Datastructure.SparseArray <IZone> zoneArray, TashaPerson person)
        {
            SchedulerTripChain chain = SchedulerTripChain.GetTripChain(person);

            chain.JointTripID  = reader.ReadInt32();
            chain.JointTripRep = reader.ReadBoolean();
            LoadKeys(reader, chain);
            int numberOfTrips = reader.ReadInt32();

            for (int i = 0; i < numberOfTrips; i++)
            {
                SchedulerTrip trip = LoadTrip(reader, zoneArray, chain, i);
                // Now that we have all of the data that we need, add ourselves to the trip chain
                chain.Trips.Add(trip);
            }
            return(chain);
        }