/// <summary>
 /// Resolve the scheduling conflicts for the household
 /// </summary>
 /// <param name="household">The household to resolve</param>
 public static ModeAssignmentHouseHold ResolveConflicts(this ITashaHousehold household)
 {
     if (!TestForNullModeSet(household))
     {
         return(ModeAssignmentHouseHold.NULL_SET);
     }
     if (TestForSimpleCase(household))    //more vehicles than people
     {
         // do what we need to do to assign vehicles to everyone
         //DoAssignment(household);
         return(ModeAssignmentHouseHold.SIMPLE_CASE);
     }
     if (TestForAdvancedCase(household))     //more vehicles than overlaps
     {
         //DoAssignment(household);
         return(ModeAssignmentHouseHold.SIMPLE_CASE);
     }
     // resort to the complex case
     IVehicleType[] bestAssignment = FindBestPossibleAssignment(household.AllTripChains(), new List <IVehicle>(household.Vehicles));
     if (bestAssignment == null)
     {
         return(ModeAssignmentHouseHold.NULL_SET);
     }
     return(ModeAssignmentHouseHold.ADVANCED_CASE);
 }
Exemple #2
0
        /// <summary>
        /// Runs the ModeChoice model on the given household
        /// </summary>
        /// <param name="h">The household to run on</param>
        public bool Run(ITashaHousehold h)
        {
            // Compute the error terms and feasibility of non shared modes
            ComputeErrorTerms(h);
            //there are no "trip chains" so return true
            for (int i = 0; i < this.HouseholdIterations; i++)
            {
                // To start with Generate the LogLikelyhoods
                if (i == 0)
                {
                    foreach (var person in h.Persons)
                    {
                        person.CalculateLoglikelihood();
                    }
                }
                else
                {
                    // on ever other one just update the utilities
                    h.UpdateUtilities();
                }

                ModeChoiceHousehold.ModeAssignmentHouseHold result = h.ResolveConflicts();

                //assign the best mode to each trip to prep for pass 3
                if (result == ModeChoiceHousehold.ModeAssignmentHouseHold.ADVANCED_CASE)
                {
                    List <ITripChain> l  = h.AllTripChains();
                    IVehicleType[]    vt = ModeChoiceHousehold.FindBestPossibleAssignment(l, new List <IVehicle>(h.Vehicles));
                    if (vt != null)
                    {
                        AssignBestMode(h, vt);
                    }
                    else
                    {
                        // TODO: should assign best possible vehicle even if
                        // someone cannot execute their tripchain since they can
                        // be passengers
                        return(false);
                    }
                }
                else if (result == ModeChoiceHousehold.ModeAssignmentHouseHold.SIMPLE_CASE)
                {
                    AssignBestMode(h);
                }
                else if (result == ModeChoiceHousehold.ModeAssignmentHouseHold.NULL_SET)
                {
                    ReleaseModeSets(h);
                    return(false);
                }

                //pass 3
                h.MultiPersonMode();

                //finally store it to the list of "generated" realities
                DoAssignment(h, i);
            }
            ReleaseModeSets(h);
            return(true);
        }
        /// <summary>
        /// Handle case where we check if there are more conflicting schedules than vehicles for all the trips
        /// in the household
        /// </summary>
        /// <param name="household">The household</param>`
        private static bool TestForAdvancedCase(ITashaHousehold household)
        {
            //a list of tripchains for each vehicle type
            List <ITripChain>[] optimalSets = TripChainsForVehicle(household.AllTripChains());
            var vehicles = household.Vehicles;

            // if there are no vehicles then we don't need to test for the case
            if (vehicles.Length == 0)
            {
                return(false);
            }
            var optimalSetsLength = optimalSets.Length;

            for (int i = 0; i < optimalSetsLength; i++)
            {
                //check if there is a conflict st the vehicle is required at more than one trip chain
                //at the same point in the day
                if (!ModeChoice.VehicleTypes[i].Finite)
                {
                    continue;
                }
                var ammount = 0;
                for (int j = 0; j < vehicles.Length; j++)
                {
                    if (vehicles[j].VehicleType == ModeChoice.VehicleTypes[i])
                    {
                        ammount++;
                    }
                }
                if (Conflict(optimalSets[i], ammount, i + 1))
                {
                    return(false);
                }
            }
            return(true);
        }
Exemple #4
0
        /// <summary>
        /// Runs the ModeChoice model on the given household
        /// </summary>
        /// <param name="h">The household to run on</param>
        public bool Run(ITashaHousehold h)
        {
            // Compute the error terms and feasibility of non shared modes
            ComputeErrorTerms( h );
            //there are no "trip chains" so return true
            for ( int i = 0; i < this.HouseholdIterations; i++ )
            {
                // To start with Generate the LogLikelyhoods
                if ( i == 0 )
                {
                    foreach ( var person in h.Persons )
                    {
                        person.CalculateLoglikelihood();
                    }
                }
                else
                {
                    // on ever other one just update the utilities
                    h.UpdateUtilities();
                }

                ModeChoiceHousehold.ModeAssignmentHouseHold result = h.ResolveConflicts();

                //assign the best mode to each trip to prep for pass 3
                if ( result == ModeChoiceHousehold.ModeAssignmentHouseHold.ADVANCED_CASE )
                {
                    List<ITripChain> l = h.AllTripChains();
                    IVehicleType[] vt = ModeChoiceHousehold.FindBestPossibleAssignment( l, new List<IVehicle>( h.Vehicles ) );
                    if ( vt != null )
                    {
                        AssignBestMode( h, vt );
                    }
                    else
                    {
                        // TODO: should assign best possible vehicle even if
                        // someone cannot execute their tripchain since they can
                        // be passengers
                        return false;
                    }
                }
                else if ( result == ModeChoiceHousehold.ModeAssignmentHouseHold.SIMPLE_CASE )
                {
                    AssignBestMode( h );
                }
                else if ( result == ModeChoiceHousehold.ModeAssignmentHouseHold.NULL_SET )
                {
                    ReleaseModeSets( h );
                    return false;
                }

                //pass 3
                h.MultiPersonMode();

                //finally store it to the list of "generated" realities
                DoAssignment( h, i );
            }
            ReleaseModeSets( h );
            return true;
        }