Exemplo n.º 1
0
        internal PossibleTripChainSolution(ModeChoiceTripData[] baseTripData, int[] solution, TourData tourData)
        {
            BaseData = baseTripData;
            var modes = new int[solution.Length];

            for (int i = 0; i < modes.Length; i++)
            {
                modes[i] = solution[i];
            }
            if (tourData != null)
            {
                TourData             = tourData;
                TourDependentUtility = TourData.TourUtilityModifiers;
            }
            PickedModes = modes;
            RegenerateU();
        }
Exemplo n.º 2
0
 internal PossibleTripChainSolution(ModeChoiceTripData[] baseTripData, int[] solution, TourData tourData)
 {
     var numberOftrips = solution.Length;
     BaseData = baseTripData;
     PickedModes = solution.Clone() as int[];
     if ( tourData != null )
     {
         TourData = tourData;
         var modifiers = TourData.TourUtilityModifiers;
         var picked = PickedModes;
         var localTotal = 0.0f;
         for ( int i = 0; i < modifiers.Length; i++ )
         {
             localTotal += modifiers[i];
         }
         TourDependentUtility = localTotal;
     }
     RegenerateU();
 }
Exemplo n.º 3
0
        internal PossibleTripChainSolution(ModeChoiceTripData[] baseTripData, int[] solution, TourData tourData)
        {
            var numberOftrips = solution.Length;

            BaseData    = baseTripData;
            PickedModes = solution.Clone() as int[];
            if (tourData != null)
            {
                TourData = tourData;
                var modifiers  = TourData.TourUtilityModifiers;
                var picked     = PickedModes;
                var localTotal = 0.0f;
                for (int i = 0; i < modifiers.Length; i++)
                {
                    localTotal += modifiers[i];
                }
                TourDependentUtility = localTotal;
            }
            RegenerateU();
        }
Exemplo n.º 4
0
        private void ComputePossibleAssignments(ITashaMode[] modes)
        {
            var   possibleAssignments = PossibleAssignments;
            var   topLevel            = TripData.Length - 1;
            int   level       = 0;
            int   mode        = 0;
            var   trips       = TripChain.Trips;
            int   chainLength = trips.Count;
            ITrip currentTrip = trips[0];

            int[] possibleSolution = new int[chainLength];
            ITourDependentMode[] tourDependentModes;
            tourDependentModes = new ITourDependentMode[modes.Length];
            for (int i = 0; i < tourDependentModes.Length; i++)
            {
                tourDependentModes[i] = modes[i] as ITourDependentMode;
            }
            while (level != -1)
            {
                for (; mode < modes.Length; mode++)
                {
                    // For each feasible mode
                    var currentData = TripData[level];
                    if (currentData.Feasible[mode])
                    {
                        // find the total utility
                        // store the mode into our set and chain
                        currentTrip.Mode        = modes[mode];
                        possibleSolution[level] = mode;
                        // if we are at the end, store the set
                        if (level >= topLevel)
                        {
                            bool     feasible = true;
                            TourData tourData = null;
                            // make sure this chain is allowed
                            for (int j = 0; j < modes.Length; j++)
                            {
                                // if this doesn't work don't save it
                                if (!modes[j].Feasible(TripChain))
                                {
                                    feasible = false;
                                    break;
                                }
                            }
                            // if the modes think it is allowed calculate the tour level data
                            if (feasible)
                            {
                                for (int i = 0; i < chainLength; i++)
                                {
                                    if (tourDependentModes[possibleSolution[i]] != null)
                                    {
                                        if (tourDependentModes[possibleSolution[i]].CalculateTourDependentUtility(TripChain, i, out float tourUtility, out Action <ITripChain> onSelection))
                                        {
                                            if (tourData == null)
                                            {
                                                tourData = new TourData(tourUtility, new Action <ITripChain> [chainLength]);
                                            }
                                            else
                                            {
                                                tourData.TourUtilityModifiers = tourData.TourUtilityModifiers + tourUtility;
                                            }
                                            tourData.OnSolution[i] = onSelection;
                                        }
                                        else
                                        {
                                            feasible = false;
                                            break;
                                        }
                                    }
                                }
                            }
                            // if the tour level data thinks it is allowed, then it works and we can add it
                            if (feasible)
                            {
                                possibleAssignments.Add(new PossibleTripChainSolution(TripData, possibleSolution, tourData));
                            }
                        }
                        else
                        {
                            // otherwise go to the next trip
                            level++;
                            currentTrip = trips[level];
                            mode        = -1;
                        }
                    }
                }
                level--;
                if (level >= 0)
                {
                    mode        = possibleSolution[level] + 1;
                    currentTrip = trips[level];
                }
            }
Exemplo n.º 5
0
 private void ComputePossibleAssignments(ITashaMode[] modes)
 {
     var possibleAssignments = PossibleAssignments;
     var topLevel = TripData.Length - 1;
     int level = 0;
     int mode = 0;
     var trips = TripChain.Trips;
     int chainLength = trips.Count;
     ITrip currentTrip = trips[0];
     int[] possibleSolution;
     ITourDependentMode[] tourDependentModes;
     if((possibleSolution = PossibleSolution) == null || possibleSolution.Length < chainLength)
     {
         PossibleSolution = possibleSolution = new int[chainLength];
     }
     if((tourDependentModes = TourDependentModes) == null)
     {
         tourDependentModes = TourDependentModes = new ITourDependentMode[modes.Length];
         for(int i = 0; i < tourDependentModes.Length; i++)
         {
             tourDependentModes[i] = modes[i] as ITourDependentMode;
         }
     }
     while(level != -1)
     {
         for(; mode < modes.Length; mode++)
         {
             // For each feasible mode
             var currentData = TripData[level];
             if(currentData.Feasible[mode])
             {
                 // find the total utility
                 // store the mode into our set and chain
                 currentTrip.Mode = modes[mode];
                 possibleSolution[level] = mode;
                 // if we are at the end, store the set
                 if(level >= topLevel)
                 {
                     bool feasible = true;
                     TourData tourData = null;
                     // make sure this chain is allowed
                     for(int j = 0; j < modes.Length; j++)
                     {
                         // if this doesn't work don't save it
                         if(!modes[j].Feasible(TripChain))
                         {
                             feasible = false;
                             break;
                         }
                     }
                     // if the modes think it is allowed calculate the tour level data
                     if(feasible)
                     {
                         for(int i = 0; i < chainLength; i++)
                         {
                             if(tourDependentModes[possibleSolution[i]] != null)
                             {
                                 float tourUtility;
                                 Action<ITripChain> onSelection;
                                 if(tourDependentModes[possibleSolution[i]].CalculateTourDependentUtility(TripChain, i, out tourUtility, out onSelection))
                                 {
                                     if(tourData == null)
                                     {
                                         tourData = new TourData(new float[chainLength], new Action<ITripChain>[chainLength]);
                                     }
                                     tourData.TourUtilityModifiers[i] = tourUtility;
                                     tourData.OnSolution[i] = onSelection;
                                 }
                                 else
                                 {
                                     feasible = false;
                                     break;
                                 }
                             }
                         }
                     }
                     // if the tour level data thinks it is allowed, then it works and we can add it
                     if(feasible)
                     {
                         possibleAssignments.Add(new PossibleTripChainSolution(TripData, possibleSolution, tourData));
                     }
                 }
                 else
                 {
                     // otherwise go to the next trip
                     level++;
                     currentTrip = trips[level];
                     mode = -1;
                     continue;
                 }
             }
         }
         level--;
         if(level >= 0)
         {
             mode = possibleSolution[level] + 1;
             currentTrip = trips[level];
         }
     }
 }