Example #1
0
        /// <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);
        }
Example #2
0
        /// <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);
        }
Example #3
0
 /// <summary>
 ///     Provides the model element referenced by this shortcut
 /// </summary>
 /// <returns></returns>
 public Namable GetReference()
 {
     return((Namable)EFSSystem.FindByFullName(ShortcutName));
 }