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


C# Graph.AddSegment方法代码示例

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


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

示例1: CreateGraphForValue

        /// <summary>
        ///     Creates the graph for a value
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static Graph CreateGraphForValue(IValue value)
        {
            Graph retVal = new Graph();

            double val = GetDoubleValue(value);
            retVal.AddSegment(new Graph.Segment(0, double.MaxValue, new Graph.Segment.Curve(0.0, val, 0.0)));

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

示例2: createSurfaceForValue

        /// <summary>
        ///     Creates the surface associated to the value provided
        /// </summary>
        /// <param name="context"></param>
        /// <param name="value"></param>
        /// <param name="explain"></param>
        /// <returns></returns>
        protected Surface createSurfaceForValue(InterpretationContext context, IValue value, ExplanationPart explain)
        {
            Surface retVal = null;

            Function function = value as Function;
            if (function != null)
            {
                retVal = function.createSurface(context, explain);
            }
            else
            {
                DoubleValue val = value as DoubleValue;
                Graph graph = new Graph();
                graph.AddSegment(new Graph.Segment(0, double.MaxValue, new Graph.Segment.Curve(0, val.Val, 0)));
                retVal = new Surface(null, null);
                retVal.AddSegment(new Surface.Segment(0, double.MaxValue, graph));
            }

            return retVal;
        }
开发者ID:JamesOakey,项目名称:ERTMSFormalSpecs,代码行数:27,代码来源:PredefinedFunction.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 override Graph CreateGraph(InterpretationContext context, Parameter parameter, ExplanationPart explain)
        {
            Graph retVal = null;

            Graph mrspGraph = null;
            Function speedRestriction = context.FindOnStack(SpeedRestrictions).Value as Function;
            if (speedRestriction != null)
            {
                Parameter p = (Parameter) speedRestriction.FormalParameters[0];

                int token = context.LocalScope.PushContext();
                context.LocalScope.SetGraphParameter(p);
                mrspGraph = createGraphForValue(context, context.FindOnStack(SpeedRestrictions).Value, explain, p);
                context.LocalScope.PopContext(token);
            }

            if (mrspGraph != null)
            {
                Function deceleratorFactor = context.FindOnStack(DecelerationFactor).Value as Function;
                if (deceleratorFactor != null)
                {
                    Surface decelerationSurface = deceleratorFactor.CreateSurface(context, explain);
                    if (decelerationSurface != null)
                    {
                        FlatSpeedDistanceCurve mrspCurve = mrspGraph.FlatSpeedDistanceCurve(mrspGraph.ExpectedEndX());
                        AccelerationSpeedDistanceSurface accelerationSurface =
                            decelerationSurface.createAccelerationSpeedDistanceSurface(double.MaxValue, double.MaxValue);
                        QuadraticSpeedDistanceCurve brakingCurve = null;
                        try
                        {
                            brakingCurve = EtcsBrakingCurveBuilder.Build_A_Safe_Backward(accelerationSurface, mrspCurve);
                        }
                        catch (Exception)
                        {
                            retVal = new Graph();
                            retVal.AddSegment(new Graph.Segment(0, double.MaxValue, new Graph.Segment.Curve(0, 0, 0)));
                        }

                        if (brakingCurve != null)
                        {
                            retVal = new Graph();

                            // TODO : Remove the distinction between linear curves and quadratic curves
                            bool isLinear = true;
                            for (int i = 0; i < brakingCurve.SegmentCount; i++)
                            {
                                QuadraticCurveSegment segment = brakingCurve[i];
                                if (segment.A.ToUnits() != 0.0 || segment.V0.ToUnits() != 0.0)
                                {
                                    isLinear = false;
                                    break;
                                }
                            }

                            for (int i = 0; i < brakingCurve.SegmentCount; i++)
                            {
                                QuadraticCurveSegment segment = brakingCurve[i];

                                Graph.Segment newSegment;
                                if (isLinear)
                                {
                                    newSegment = new Graph.Segment(
                                        segment.X.X0.ToUnits(),
                                        segment.X.X1.ToUnits(),
                                        new Graph.Segment.Curve(0.0,
                                            segment.V0.ToSubUnits(SiSpeed_SubUnits.KiloMeter_per_Hour), 0.0));
                                }
                                else
                                {
                                    newSegment = new Graph.Segment(
                                        segment.X.X0.ToUnits(),
                                        segment.X.X1.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);
                            }
                        }
                    }
                    else
                    {
                        DecelerationFactor.AddError("Cannot create surface for " + DecelerationFactor);
                    }
                }
                else
                {
                    DecelerationFactor.AddError("Cannot evaluate " + DecelerationFactor + " as a function");
                }
            }
//.........这里部分代码省略.........
开发者ID:nikiforovandrey,项目名称:ERTMSFormalSpecs,代码行数:101,代码来源:DecelerationProfile.cs

示例4: createGraphForValue

        /// <summary>
        ///     Creates the graph associated to the parameter provided
        /// </summary>
        /// <param name="context"></param>
        /// <param name="value"></param>
        /// <param name="parameter"></param>
        /// <param name="explain"></param>
        /// <returns></returns>
        protected Graph createGraphForValue(InterpretationContext context, IValue value, ExplanationPart explain,
            Parameter parameter = null)
        {
            Graph retVal = new Graph();

            Function function = value as Function;
            if (function != null)
            {
                if (parameter == null)
                {
                    parameter = (Parameter) function.FormalParameters[0];
                    int token = context.LocalScope.PushContext();
                    context.LocalScope.setGraphParameter(parameter);
                    retVal = function.createGraph(context, parameter, explain);
                    context.LocalScope.PopContext(token);
                }
                else
                {
                    retVal = function.createGraph(context, parameter, explain);
                }
            }
            else
            {
                DoubleValue val = value as DoubleValue;
                retVal.AddSegment(new Graph.Segment(0, double.MaxValue, new Graph.Segment.Curve(0.0, val.Val, 0.0)));
            }

            return retVal;
        }
开发者ID:JamesOakey,项目名称:ERTMSFormalSpecs,代码行数:37,代码来源:PredefinedFunction.cs

示例5: 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


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