public ModeChoiceTripChainData(ITripChain tripChain, int numberOfModes, int numberOfVehicleTypes)
 {
     var trips = tripChain.Trips;
     TripChain = tripChain;
     BestPossibleAssignmentForVehicleType = new PossibleTripChainSolution[numberOfVehicleTypes];
     var tripData = new ModeChoiceTripData[trips.Count];
     PossibleAssignments = new List<PossibleTripChainSolution>((numberOfModes * trips.Count) >> 1);
     for(int i = 0; i < tripData.Length; i++)
     {
         tripData[i] = new ModeChoiceTripData(numberOfModes);
     }
     TripData = tripData;
 }
        public ModeChoiceTripChainData(ITripChain tripChain, int numberOfModes, int numberOfVehicleTypes)
        {
            var trips = tripChain.Trips;

            TripChain = tripChain;
            BestPossibleAssignmentForVehicleType = new PossibleTripChainSolution[numberOfVehicleTypes];
            var tripData = new ModeChoiceTripData[trips.Count];

            PossibleAssignments = new List <PossibleTripChainSolution>((numberOfModes * trips.Count) >> 1);
            for (int i = 0; i < tripData.Length; i++)
            {
                tripData[i] = new ModeChoiceTripData(numberOfModes);
            }
            TripData = tripData;
        }
 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();
 }
        public bool Pass1(ITashaMode[] modes)
        {
            var trips    = TripChain.Trips;
            var tripData = TripData;

            for (int i = 0; i < tripData.Length; i++)
            {
                bool anyModeFeasible           = false;
                ModeChoiceTripData currentTrip = tripData[i];
                for (int j = 0; j < modes.Length; j++)
                {
                    // go through each non shared mode and if it is feasible get the V for that mode
                    currentTrip.Feasible[j] = modes[j].Feasible(trips[i]);
                    if (currentTrip.Feasible[j])
                    {
                        var value = (float)modes[j].CalculateV(trips[i]);
                        if (!(float.IsNaN(value) | float.IsInfinity(value)))
                        {
                            currentTrip.V[j] = value;
                            anyModeFeasible  = true;
                        }
                        else
                        {
                            currentTrip.V[j]        = float.NegativeInfinity;
                            currentTrip.Feasible[j] = false;
                        }
                    }
                    else
                    {
                        currentTrip.V[j] = float.NegativeInfinity;
                    }
                }
                if (!anyModeFeasible)
                {
                    return(false);
                }
            }
            ComputePossibleAssignments(modes);
            return(PossibleAssignments.Count > 0);
        }
 private double EvaluateRandomFitness(ModeChoiceTripData tripData, int householdIterations)
 {
     int feasibleModes = 0;
     for ( int i = 0; i < tripData.Feasible.Length; i++ )
     {
         if ( tripData.Feasible[i] )
         {
             feasibleModes++;
         }
     }
     if ( feasibleModes == 0 ) feasibleModes = 1;
     return Math.Log( ( ( ( householdIterations / (double)feasibleModes ) ) + 1.0 )
         / ( householdIterations + 1.0 ) );
 }