internal static void CreateHouseholdProjects(this ITashaHousehold household) { SchedHouseholdData data; household.Attach("SData", data = new SchedHouseholdData()); ProjectSchedule jointOtherSchedule = new ProjectSchedule(); ProjectSchedule jointMarketSchedule = new ProjectSchedule(); Project jointOtherProject = new HouseholdProject(household, jointOtherSchedule); Project jointMarketProject = new HouseholdProject(household, jointMarketSchedule); data.JointOtherProject = jointOtherProject; data.JointMarketProject = jointMarketProject; }
public bool Run(ITashaHousehold household) { if(MaxTripChainSize > 0) { if(AnyOverMaxTripChainSize(household)) { return false; } } Random random = new Random( RandomSeed + household.HouseholdId ); ModeChoiceHouseholdData householdData = new ModeChoiceHouseholdData( household, AllModes.Length, VehicleTypes.Length + 1 ); HouseholdResourceAllocator householdResourceAllocator = new HouseholdResourceAllocator( household, AllModes ); PassengerMatchingAlgorithm passengerMatchingAlgorithm = null; // attach this so analysis modules can look at it later household.Attach( "ModeChoiceData", householdData ); household.Attach( "ResourceAllocator", householdResourceAllocator ); if ( PassengerMode != null ) { passengerMatchingAlgorithm = new PassengerMatchingAlgorithm( household, householdData, PassengerMode, AllModes ); household.Attach( "PassengerMatchingAlgorithm", passengerMatchingAlgorithm ); } for ( int i = 0; i < PostHouseholdIteration.Length; i++ ) { PostHouseholdIteration[i].HouseholdStart( household, HouseholdIterations ); } if ( !Pass1( householdData, random ) ) { for ( int i = 0; i < PostHouseholdIteration.Length; i++ ) { PostHouseholdIteration[i].HouseholdComplete( household, false ); } return false; } for ( int householdIteration = 0; householdIteration < HouseholdIterations; householdIteration++ ) { if ( householdIteration > 0 ) { RegenerateErrorTerms( householdData, random ); } // Start of Pass 2 AssignBestPerVehicle( Root.VehicleTypes, householdData, householdIteration ); var resolution = householdResourceAllocator.Resolve( householdData, VehicleTypes, householdIteration ); if ( resolution == null ) { for ( int i = 0; i < PostHouseholdIteration.Length; i++ ) { PostHouseholdIteration[i].HouseholdComplete( household, false ); } // failure return false; } AssignModes( resolution, householdData ); householdResourceAllocator.BuildVehicleAvailabilities( householdData, household.Vehicles ); // Start of Pass 2.5 ( rideshare ) ProcessRideshare( householdData ); // Start of Pass 3 (Passenger attaching to trip chains) if ( passengerMatchingAlgorithm != null ) { passengerMatchingAlgorithm.GeneratePotentialPassengerTrips( random, true ); passengerMatchingAlgorithm.ResolvePassengerTrips(); // Start of Pass 4 (Passenger attaching to new trips coming from home) passengerMatchingAlgorithm.GeneratePotentialPassengerTrips( random, false, householdResourceAllocator ); passengerMatchingAlgorithm.ResolvePassengerTrips(); } // Now at the end add to chosen modes (And assign joint trips) FinalAssignment( householdData, householdIteration ); for ( int i = 0; i < PostHouseholdIteration.Length; i++ ) { PostHouseholdIteration[i].HouseholdIterationComplete( household, householdIteration, HouseholdIterations ); } } for ( int i = 0; i < PostHouseholdIteration.Length; i++ ) { PostHouseholdIteration[i].HouseholdComplete( household, true ); } return true; }
public bool Run(ITashaHousehold household) { if (MaxTripChainSize > 0) { if (AnyOverMaxTripChainSize(household)) { return(false); } } Random random = new Random(RandomSeed + household.HouseholdId); ModeChoiceHouseholdData householdData = new ModeChoiceHouseholdData(household, AllModes.Length, VehicleTypes.Length + 1); HouseholdResourceAllocator householdResourceAllocator = new HouseholdResourceAllocator(household, AllModes); PassengerMatchingAlgorithm passengerMatchingAlgorithm = null; // attach this so analysis modules can look at it later household.Attach("ModeChoiceData", householdData); household.Attach("ResourceAllocator", householdResourceAllocator); if (PassengerMode != null) { passengerMatchingAlgorithm = new PassengerMatchingAlgorithm(household, householdData, PassengerMode, AllModes); household.Attach("PassengerMatchingAlgorithm", passengerMatchingAlgorithm); } for (int i = 0; i < PostHouseholdIteration.Length; i++) { PostHouseholdIteration[i].HouseholdStart(household, HouseholdIterations); } if (!Pass1(householdData, random)) { for (int i = 0; i < PostHouseholdIteration.Length; i++) { PostHouseholdIteration[i].HouseholdComplete(household, false); } return(false); } for (int householdIteration = 0; householdIteration < HouseholdIterations; householdIteration++) { if (householdIteration > 0) { RegenerateErrorTerms(householdData, random); } // Start of Pass 2 AssignBestPerVehicle(Root.VehicleTypes, householdData); var resolution = householdResourceAllocator.Resolve(householdData, VehicleTypes, householdIteration); if (resolution == null) { for (int i = 0; i < PostHouseholdIteration.Length; i++) { PostHouseholdIteration[i].HouseholdComplete(household, false); } // failure return(false); } AssignModes(resolution, householdData); householdResourceAllocator.BuildVehicleAvailabilities(householdData, household.Vehicles); // Start of Pass 2.5 ( rideshare ) ProcessRideshare(householdData); // Start of Pass 3 (Passenger attaching to trip chains) if (passengerMatchingAlgorithm != null) { passengerMatchingAlgorithm.GeneratePotentialPassengerTrips(random); passengerMatchingAlgorithm.ResolvePassengerTrips(); // Start of Pass 4 (Passenger attaching to new trips coming from home) passengerMatchingAlgorithm.GeneratePotentialPassengerTrips(random, false, householdResourceAllocator); passengerMatchingAlgorithm.ResolvePassengerTrips(); } // Now at the end add to chosen modes (And assign joint trips) FinalAssignment(householdData, householdIteration); for (int i = 0; i < PostHouseholdIteration.Length; i++) { PostHouseholdIteration[i].HouseholdIterationComplete(household, householdIteration, HouseholdIterations); } } for (int i = 0; i < PostHouseholdIteration.Length; i++) { PostHouseholdIteration[i].HouseholdComplete(household, true); } return(true); }