예제 #1
0
        private bool GatherAllUtility(IModeChoiceNode node, IZone o, IZone d, out float utility)
        {
            var cat = node as IModeCategory;

            if (cat == null)
            {
                if (node.Feasible(o, d, SimulationTime))
                {
                    utility = (float)Math.Exp(node.CalculateV(o, d, SimulationTime));
                    return(!float.IsNaN(utility));
                }
            }
            else
            {
                // check to make sure that we are feasible
                if (!node.Feasible(o, d, SimulationTime))
                {
                    utility = 0f;
                    return(false);
                }
                // if we are feasible then go through and get the utility of our children
                float totalUtility        = 0f;
                var   length              = cat.Children.Count;
                bool  anyChildrenFeasible = false;
                for (int i = 0; i < length; i++)
                {
                    float res;
                    if (GatherAllUtility(cat.Children[i], o, d, out res))
                    {
                        anyChildrenFeasible = true;
                        totalUtility       += res;
                    }
                }
                if (anyChildrenFeasible)
                {
                    utility = (float)(Math.Pow(totalUtility, cat.Correlation)
                                      * Math.Exp(cat.CalculateCombinedV(o, d, SimulationTime)));
                    return(true);
                }
            }
            // if we got here then there were no feasible alternatives
            utility = 0f;
            return(false);
        }
예제 #2
0
        private bool GatherUtility(TreeData <float> treeData, IModeChoiceNode node, int o, int d, IZone[] zones)
        {
            var cat = node as IModeCategory;

            treeData.Result = float.NaN;
            if (!node.Feasible(zones[o], zones[d], SimulationTime))
            {
                treeData.Result = float.NaN;
                return(false);
            }
            if (cat == null)
            {
                treeData.Result = (node.CurrentlyFeasible > 0 ? (float)Math.Exp(node.CalculateV(zones[o], zones[d], SimulationTime)) : float.NaN);
                return(!float.IsNaN(treeData.Result));
            }
            else if (cat.CurrentlyFeasible > 0)
            {
                bool  hasAlternatives = false;
                float totalUtility    = 0;
                var   treeChildren    = treeData.Children;
                var   catChildren     = cat.Children;
                for (int i = 0; i < treeData.Children.Length; i++)
                {
                    if (GatherUtility(treeChildren[i], catChildren[i], o, d, zones))
                    {
                        hasAlternatives = true;
                        totalUtility   += treeChildren[i].Result;
                    }
                }
                if (hasAlternatives)
                {
                    if (totalUtility >= this.MinLogSumToE)
                    {
                        var localUtility = cat.CalculateCombinedV(zones[o], zones[d], SimulationTime);
                        treeData.Result = (float)(Math.Pow(totalUtility, cat.Correlation) * Math.Exp(localUtility));
                        return(true);
                    }
                }
            }
            treeData.Result = float.NaN;
            return(false);
        }
예제 #3
0
 private bool GatherAllUtility(IModeChoiceNode node, IZone o, IZone d, out float utility)
 {
     var cat = node as IModeCategory;
     if ( cat == null )
     {
         if ( node.Feasible( o, d, SimulationTime ) )
         {
             utility = (float)Math.Exp( node.CalculateV( o, d, SimulationTime ) );
             return !float.IsNaN( utility );
         }
     }
     else
     {
         // check to make sure that we are feasible
         if ( !node.Feasible( o, d, SimulationTime ) )
         {
             utility = 0f;
             return false;
         }
         // if we are feasible then go through and get the utility of our children
         float totalUtility = 0f;
         var length = cat.Children.Count;
         bool anyChildrenFeasible = false;
         for ( int i = 0; i < length; i++ )
         {
             float res;
             if ( GatherAllUtility( cat.Children[i], o, d, out res ) )
             {
                 anyChildrenFeasible = true;
                 totalUtility += res;
             }
         }
         if ( anyChildrenFeasible )
         {
             utility = (float)( Math.Pow( totalUtility, cat.Correlation )
                 * Math.Exp( cat.CalculateCombinedV( o, d, SimulationTime ) ) );
             return true;
         }
     }
     // if we got here then there were no feasible alternatives
     utility = 0f;
     return false;
 }
예제 #4
0
 private bool GatherUtility(TreeData<float> treeData, IModeChoiceNode node, int o, int d, IZone[] zones)
 {
     var cat = node as IModeCategory;
     treeData.Result = float.NaN;
     if ( !node.Feasible( zones[o], zones[d], SimulationTime ) )
     {
         treeData.Result = float.NaN;
         return false;
     }
     if ( cat == null )
     {
         treeData.Result = ( node.CurrentlyFeasible > 0 ? (float)Math.Exp( node.CalculateV( zones[o], zones[d], SimulationTime ) ) : float.NaN );
         return !float.IsNaN( treeData.Result );
     }
     else if ( cat.CurrentlyFeasible > 0 )
     {
         bool hasAlternatives = false;
         float totalUtility = 0;
         var treeChildren = treeData.Children;
         var catChildren = cat.Children;
         for ( int i = 0; i < treeData.Children.Length; i++ )
         {
             if ( GatherUtility( treeChildren[i], catChildren[i], o, d, zones ) )
             {
                 hasAlternatives = true;
                 totalUtility += treeChildren[i].Result;
             }
         }
         if ( hasAlternatives )
         {
             if ( totalUtility >= this.MinLogSumToE )
             {
                 var localUtility = cat.CalculateCombinedV( zones[o], zones[d], SimulationTime );
                 treeData.Result = (float)( Math.Pow( totalUtility, cat.Correlation ) * Math.Exp( localUtility ) );
                 return true;
             }
         }
     }
     treeData.Result = float.NaN;
     return false;
 }