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); }
private bool GatherUtility(TreeData <float[]> treeData, IModeChoiceNode node, int o, int d, IZone[] zones) { var cat = node as IModeCategory; int index = o * zones.Length + d; if (!node.Feasible(zones[o], zones[d], SimulationTime)) { treeData.Result[index] = float.NaN; return(false); } if (cat == null) { treeData.Result[index] = node.CurrentlyFeasible > 0 ? (float)Math.Exp(node.CalculateV(zones[o], zones[d], SimulationTime)) : float.NaN; return(!float.IsNaN(treeData.Result[index])); } else if (cat.Correlation > 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[index]; } } if (hasAlternatives) { if (totalUtility >= this.MinLogSumToE) { var localUtility = cat.CalculateCombinedV(zones[o], zones[d], SimulationTime); if (cat.Correlation == 1f) { if (localUtility == 0f) { treeData.Result[index] = (float)(totalUtility); } else { treeData.Result[index] = (float)(totalUtility * Math.Exp(localUtility)); } } else { treeData.Result[index] = (float)(Math.Pow(totalUtility, cat.Correlation) * Math.Exp(localUtility)); } return(true); } } } treeData.Result[index] = float.NaN; return(false); }
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; }
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; }