当前位置: 首页>>代码示例>>C#>>正文


C# InterpretationContext.FindOnStack方法代码示例

本文整理汇总了C#中DataDictionary.Interpreter.InterpretationContext.FindOnStack方法的典型用法代码示例。如果您正苦于以下问题:C# InterpretationContext.FindOnStack方法的具体用法?C# InterpretationContext.FindOnStack怎么用?C# InterpretationContext.FindOnStack使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DataDictionary.Interpreter.InterpretationContext的用法示例。


在下文中一共展示了InterpretationContext.FindOnStack方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Evaluate

        /// <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;
        }
开发者ID:nikiforovandrey,项目名称:ERTMSFormalSpecs,代码行数:50,代码来源:DistanceForSpeed.cs

示例2: Evaluate

        /// <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);
            IValue value = context.FindOnStack(Value).Value;
            if (value is Function)
            {
                retVal = value;
            }
            else
            {
                retVal = TargetType.convert(value);
            }
            context.LocalScope.PopContext(token);

            return retVal;
        }
开发者ID:nikiforovandrey,项目名称:ERTMSFormalSpecs,代码行数:27,代码来源:Cast.cs

示例3: CreateGraph

        /// <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 virtual Graph CreateGraph(InterpretationContext context, Parameter parameter, ExplanationPart explain)
        {
            Graph retVal = Graph;

            if (retVal == null)
            {
                try
                {
                    InterpretationContext ctxt = new InterpretationContext(context);
                    if (Cases.Count > 0)
                    {
                        // For now, just create graphs for functions using 0 or 1 parameter.
                        if (FormalParameters.Count == 0)
                        {
                            IValue value = Evaluate(ctxt, new Dictionary<Actual, IValue>(), explain);
                            retVal = Graph.createGraph(value, parameter, explain);
                        }
                        else if (FormalParameters.Count == 1)
                        {
                            Parameter param = (Parameter) FormalParameters[0];
                            int token = ctxt.LocalScope.PushContext();
                            IValue actualValue = null;
                            if (parameter != null)
                            {
                                IVariable actual = ctxt.FindOnStack(parameter);
                                if (actual != null)
                                {
                                    actualValue = actual.Value;
                                }
                                else
                                {
                                    actualValue = new PlaceHolder(parameter.Type, 1);
                                }

                                ctxt.LocalScope.SetParameter(param, actualValue);
                            }
                            retVal = CreateGraphForParameter(ctxt, param, explain);

                            if (getCacheable() && actualValue is PlaceHolder)
                            {
                                Graph = retVal;
                            }

                            ctxt.LocalScope.PopContext(token);
                        }
                        else
                        {
                            IValue value = Evaluate(ctxt, new Dictionary<Actual, IValue>(), explain);
                            retVal = Graph.createGraph(value, parameter, explain);
                        }
                    }
                }
                catch (Exception e)
                {
                    AddError("Cannot create graph of function, reason : " + e.Message);
                }
            }

            return retVal;
        }
开发者ID:nikiforovandrey,项目名称:ERTMSFormalSpecs,代码行数:67,代码来源:Function.cs

示例4: CreateSurface

        /// <summary>
        ///     Provides the surface of this function if it has been statically defined
        /// </summary>
        /// <param name="context">the context used to create the surface</param>
        /// <param name="explain"></param>
        /// <returns></returns>
        public override Surface CreateSurface(InterpretationContext context, ExplanationPart explain)
        {
            Surface retVal = null;

            IValue firstValue = context.FindOnStack(First).Value;
            IValue secondValue = context.FindOnStack(Second).Value;
            Surface firstSurface = createSurfaceForValue(context, firstValue, explain);
            if (firstSurface != null)
            {
                Surface secondSurface = createSurfaceForValue(context, secondValue, explain);
                if (secondSurface != null)
                {
                    retVal = firstSurface.Min(secondSurface);
                }
                else
                {
                    Second.AddError("Cannot create surface for " + Second);
                }
            }
            else
            {
                First.AddError("Cannot create surface for " + First);
            }

            return retVal;
        }
开发者ID:nikiforovandrey,项目名称:ERTMSFormalSpecs,代码行数:32,代码来源:MinSurface.cs

示例5: Evaluate

        /// <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);
            BoolValue val = context.FindOnStack(Value).Value as BoolValue;
            if (val != null)
            {
                if (val.Val)
                {
                    retVal = EFSSystem.BoolType.False;
                }
                else
                {
                    retVal = EFSSystem.BoolType.True;
                }
            }
            context.LocalScope.PopContext(token);

            return retVal;
        }
开发者ID:nikiforovandrey,项目名称:ERTMSFormalSpecs,代码行数:30,代码来源:Not.cs

示例6: Evaluate

        /// <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);

            Collection collectionType =
                (Collection)
                    EFSSystem.FindType(
                        OverallNameSpaceFinder.INSTANCE.findByName(EFSSystem.Dictionaries[0],
                            "Default"),
                        "TargetsCol");
            ListValue collection = new ListValue(collectionType, new List<IValue>());

            // compute targets from the MRSP
            Function function1 = context.FindOnStack(SpeedRestrictions).Value as Function;
            if (function1 != null && !function1.Name.Equals("EMPTY"))
            {
                Graph graph1 = createGraphForValue(context, function1, explain);
                ComputeTargets(graph1.Function, collection);
            }

            context.LocalScope.PopContext(token);

            retVal = collection;
            return retVal;
        }
开发者ID:GautierBerck,项目名称:ERTMSFormalSpecs,代码行数:36,代码来源:Targets.cs

示例7: Evaluate

        /// <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);

            DoubleValue value = context.FindOnStack(Value).Value as DoubleValue;
            DoubleValue multiple = context.FindOnStack(Multiple).Value as DoubleValue;
            if (value != null && multiple != null)
            {
                double res = Math.Floor(value.Val);
                while (res > 0 && res%multiple.Val != 0)
                {
                    res--;
                }
                retVal = new DoubleValue(ReturnType, res);
            }

            context.LocalScope.PopContext(token);

            return retVal;
        }
开发者ID:nikiforovandrey,项目名称:ERTMSFormalSpecs,代码行数:31,代码来源:RoundToMultiple.cs

示例8: Evaluate

        /// <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;

            AssignParameters(context, actuals);
            Graph graph = createGraphForValue(context, context.FindOnStack(FunctionA).Value, explain);
            if (graph != null)
            {
                foreach (Graph.Segment segment in graph.Segments)
                {
                    if (segment.Expression.A == 0.0)
                    {
                        double speed = segment.Expression.V0;

                        Function function = context.FindOnStack(FunctionB).Value as Function;
                        if (function.FormalParameters.Count > 0)
                        {
                            Parameter functionParameter = (Parameter) function.FormalParameters[0];
                            Actual actual = functionParameter.CreateActual();
                            actual.Value = new DoubleValue(EFSSystem.DoubleType, speed);
                            Dictionary<Actual, IValue> values = new Dictionary<Actual, IValue>();
                            values[actual] = new DoubleValue(EFSSystem.DoubleType, speed);
                            IValue solution = function.Evaluate(context, values, explain);
                            double doubleValue = GetDoubleValue(solution);

                            if (doubleValue >= segment.Start && doubleValue <= segment.End)
                            {
                                retVal = new DoubleValue(EFSSystem.DoubleType, doubleValue);
                                break;
                            }
                        }
                        else
                        {
                            FunctionB.AddError("The FunctionB doesn't have any parameter");
                            break;
                        }
                    }
                    else
                    {
                        FunctionA.AddError("The FunctionA is not a step function");
                        break;
                    }
                }
            }
            else
            {
                FunctionA.AddError("Cannot create graph for " + FunctionA);
            }

            if (retVal == null)
            {
                FunctionA.AddError("Cannot compute the intersection of " + FunctionA + " and " + FunctionB);
                FunctionB.AddError("Cannot compute the intersection of " + FunctionA + " and " + FunctionB);
            }

            return retVal;
        }
开发者ID:nikiforovandrey,项目名称:ERTMSFormalSpecs,代码行数:65,代码来源:IntersectAt.cs

示例9: Evaluate

        /// <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);

            ListValue value = context.FindOnStack(Collection) as ListValue;
            if (value != null)
            {
                Collection collectionType = value.Type as Collection;
                if (collectionType != null && collectionType.Type != null)
                {
                    Type elementType = collectionType.Type;

                    int i = 0;
                    while (i < value.Val.Count && value.Val[i] != EFSSystem.EmptyValue)
                    {
                        i += 1;
                    }

                    if (i < value.Val.Count)
                    {
                        retVal = elementType.DefaultValue;
                        value.Val[i] = retVal;
                    }
                    else
                    {
                        AddError("Cannot allocate element in list : list full");
                    }
                }
            }
            context.LocalScope.PopContext(token);

            return retVal;
        }
开发者ID:nikiforovandrey,项目名称:ERTMSFormalSpecs,代码行数:44,代码来源:Allocate.cs

示例10: CreateGraph

        /// <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 = null;

            Function function = context.FindOnStack(Function).Value as Function;
            if (function != null)
            {
                int token = context.LocalScope.PushContext();
                Parameter p = (Parameter) function.FormalParameters[0];
                context.LocalScope.SetGraphParameter(p);
                graph = createGraphForValue(context, function, explain, p);
                context.LocalScope.PopContext(token);
            }

            if (graph != null)
            {
                Function increment = context.FindOnStack(Increment).Value as Function;
                retVal = graph.AddIncrement(context, increment, explain);
            }
            else
            {
                Function.AddError("Cannot create graph for " + Function);
            }

            return retVal;
        }
开发者ID:nikiforovandrey,项目名称:ERTMSFormalSpecs,代码行数:35,代码来源:AddIncrement.cs

示例11: CreateGraph

        /// <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;

            IValue firstValue = context.FindOnStack(First).Value;
            IValue secondValue = context.FindOnStack(Second).Value;

            Graph firstGraph = createGraphForValue(context, firstValue, explain, parameter);
            if (firstGraph != null)
            {
                Graph secondGraph = createGraphForValue(context, secondValue, explain, parameter);
                if (secondGraph != null)
                {
                    retVal = firstGraph.Max(secondGraph) as Graph;
                }
                else
                {
                    Second.AddError("Cannot create graph for " + Second);
                }
            }
            else
            {
                First.AddError("Cannot create graph for " + First);
            }

            return retVal;
        }
开发者ID:nikiforovandrey,项目名称:ERTMSFormalSpecs,代码行数:34,代码来源:Max.cs

示例12: Evaluate

        /// <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);

            DoubleValue value = context.FindOnStack(Value).Value as DoubleValue;
            if (value != null)
            {
                int res = (int) Math.Round(value.Val);
                retVal = new IntValue(ReturnType, res);
            }

            context.LocalScope.PopContext(token);

            return retVal;
        }
开发者ID:nikiforovandrey,项目名称:ERTMSFormalSpecs,代码行数:26,代码来源:DoubleToInteger.cs

示例13: CreateGraph

        /// <summary>
        ///     Creates a graph for the function
        /// </summary>
        /// <param name="context"></param>
        /// <param name="parameter"></param>
        /// <param name="explain"></param>
        /// <returns></returns>
        public override Graph CreateGraph(InterpretationContext context, Parameter parameter, ExplanationPart explain)
        {
            Graph retVal = new Graph();

            StructureValue LocationStruct = context.FindOnStack(Target).Value as StructureValue;

            SiDistance location;
            SiSpeed speed;

            if (LocationStruct != null)
            {
                IVariable locationField = LocationStruct.Val["Location"] as IVariable;
                location = new SiDistance((locationField.Value as DoubleValue).Val);
                IVariable speedField = LocationStruct.Val["Speed"] as IVariable;
                speed = new SiSpeed((speedField.Value as DoubleValue).Val, SiSpeed_SubUnits.KiloMeter_per_Hour);

                Function decelerationFactor = context.FindOnStack(DecelerationFactor).Value as Function;
                if (decelerationFactor != null)
                {
                    Surface DecelerationSurface = decelerationFactor.CreateSurface(context, explain);
                    if (DecelerationSurface != null)
                    {
                        AccelerationSpeedDistanceSurface accelerationSurface =
                            DecelerationSurface.createAccelerationSpeedDistanceSurface(double.MaxValue, double.MaxValue);

                        QuadraticSpeedDistanceCurve BrakingCurve = null;

                        try
                        {
                            BrakingCurve = EtcsBrakingCurveBuilder.Build_Deceleration_Curve(accelerationSurface, speed,
                                location);
                        }
                        catch (Exception e)
                        {
                            retVal.AddSegment(new Graph.Segment(0, double.MaxValue, new Graph.Segment.Curve(0, 0, 0)));
                        }

                        SiSpeed finalSpeed = new SiSpeed(GetDoubleValue(context.FindOnStack(EndSpeed).Value),
                            SiSpeed_SubUnits.KiloMeter_per_Hour);
                        for (int i = 0; i < BrakingCurve.SegmentCount; i++)
                        {
                            QuadraticCurveSegment segment = BrakingCurve[i];

                            SiSpeed endSpeed = Max(finalSpeed, segment.Get(segment.X.X1));

                            SiDistance endDistance;
                            if (endSpeed == finalSpeed)
                            {
                                // Ensures that a braking curve is calculated until the finalSpeed
                                // but not further than the end of the curve segment
                                SiSpeed tmp = Max(segment.Get(segment.X.X1),
                                    endSpeed - new SiSpeed(0.001));
                                endDistance = segment.IntersectAt(tmp);
                            }
                            else
                            {
                                endDistance = segment.X.X1;
                            }

                            Graph.Segment newSegment = new Graph.Segment(
                                segment.X.X0.ToUnits(),
                                endDistance.ToUnits(),
                                new Graph.Segment.Curve(
                                    segment.A.ToSubUnits(SiAcceleration_SubUnits.Meter_per_SecondSquare),
                                    segment.V0.ToSubUnits(SiSpeed_SubUnits.KiloMeter_per_Hour),
                                    segment.D0.ToSubUnits(SiDistance_SubUnits.Meter)
                                    )
                                );
                            retVal.AddSegment(newSegment);

                            if (endSpeed == finalSpeed)
                            {
                                break;
                            }
                        }
                    }
                }
            }
            return retVal;
        }
开发者ID:nikiforovandrey,项目名称:ERTMSFormalSpecs,代码行数:87,代码来源:FullDecelerationForTarget.cs

示例14: CreateGraph

        /// <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;

            IVariable variable = context.FindOnStack(Value);

            if (variable != null)
            {
                retVal = Graph.createGraph(GetDoubleValue(variable.Value), parameter);
            }
            else
            {
                AddError("Cannot find variable " + Value + " on the stack");
            }

            return retVal;
        }
开发者ID:nikiforovandrey,项目名称:ERTMSFormalSpecs,代码行数:24,代码来源:Cast.cs

示例15: Evaluate

        /// <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);

            Collection collectionType =
                (Collection)
                    EFSSystem.FindType(
                        OverallNameSpaceFinder.INSTANCE.findByName(EFSSystem.Dictionaries[0],
                            "Kernel.SpeedAndDistanceMonitoring.TargetSpeedMonitoring"),
                        "Kernel.SpeedAndDistanceMonitoring.TargetSpeedMonitoring.Targets");
            ListValue collection = new ListValue(collectionType, new List<IValue>());

            Function function = context.FindOnStack(Targets).Value as Function;
            if (function != null && !function.Name.Equals("EMPTY"))
            {
                Graph graph1 = createGraphForValue(context, function, explain);
                ComputeTargets(graph1.Function, collection);
            }

            context.LocalScope.PopContext(token);

            retVal = collection;
            return retVal;
        }
开发者ID:nikiforovandrey,项目名称:ERTMSFormalSpecs,代码行数:35,代码来源:Discontinuities.cs


注:本文中的DataDictionary.Interpreter.InterpretationContext.FindOnStack方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。