/// <summary> /// Provides the graph of this function if it has been statically defined /// </summary> /// <param name="context">the context used to create the graph</param> /// <param name="parameter"></param> /// <param name="explain"></param> /// <returns></returns> public override Graph CreateGraph(InterpretationContext context, Parameter parameter, ExplanationPart explain) { Graph retVal = null; Graph graph = createGraphForValue(context, context.FindOnStack(Function).Value, explain, parameter); if (graph != null) { double speed = GetDoubleValue(context.FindOnStack(Speed).Value); double solutionX = graph.SolutionX(speed); if (solutionX == double.MaxValue) { // No value found, return Unknown Range distanceType = (Range)EFSSystem.FindByFullName("Default.BaseTypes.Distance"); EnumValue unknownDistance = distanceType.findEnumValue("Unknown"); retVal = Graph.createGraph(distanceType.getValueAsDouble(unknownDistance)); } else { // Create the graph for this solution retVal = Graph.createGraph(solutionX); } } else { Function.AddError("Cannot create graph for " + Function); } return(retVal); }
/// <summary> /// Ensures that the length of the section is consistent with EFS's length scale /// </summary> /// <param name="length"></param> /// <returns></returns> private IValue SegmentLength(double length) { IValue retVal = new DoubleValue(EFSSystem.DoubleType, length); NameSpace defaultNameSpace = OverallNameSpaceFinder.INSTANCE.findByName(EFSSystem.Dictionaries[0], "Default.BaseTypes"); Range LengthType = defaultNameSpace.findTypeByName("Length") as Range; EnumValue infinity = LengthType.findEnumValue("Infinity"); if (!LengthType.Less(retVal, infinity)) { retVal = infinity; } return(retVal); }
/// <summary> /// Provides the value of the function /// </summary> /// <param name="context"></param> /// <param name="actuals">the actual parameters values</param> /// <param name="explain"></param> /// <returns>The value for the function application</returns> public override IValue Evaluate(InterpretationContext context, Dictionary <Actual, IValue> actuals, ExplanationPart explain) { IValue retVal = null; int token = context.LocalScope.PushContext(); AssignParameters(context, actuals); Function function = context.FindOnStack(Function).Value as Function; if (function != null) { double speed = GetDoubleValue(context.FindOnStack(Speed).Value); Parameter parameter = (Parameter)function.FormalParameters[0]; int token2 = context.LocalScope.PushContext(); context.LocalScope.SetGraphParameter(parameter); Graph graph = function.CreateGraph(context, (Parameter)function.FormalParameters[0], explain); context.LocalScope.PopContext(token2); if (graph != null) { double solutionX = graph.SolutionX(speed); if (solutionX == double.MaxValue) { Range distanceType = (Range)EFSSystem.FindByFullName("Default.BaseTypes.Distance"); retVal = distanceType.findEnumValue("Unknown"); } else { retVal = new DoubleValue(EFSSystem.DoubleType, solutionX); } } else { Function.AddError("Cannot evaluate graph for function while computing the distance for the given speed"); } } else { Function.AddError("Cannot get function for " + Function); } context.LocalScope.PopContext(token); return(retVal); }