Inheritance: DataDictionary.Namable
        /// <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
            {
                Log.Error("Cannot create graph for " + Function.ToString());
            }

            return retVal;
        }
示例#2
0
        private StructureValue GetStructFromParam(Parameter parameter)
        {
            StructureValue retVal = null;

            if (parameter != null)
            {
            }

            return retVal;
        }
 public virtual void visit(Parameter obj)
 {
     visit(obj, true);
 }
 public virtual void visit(Parameter obj, bool visitSubNodes)
 {
     visit ((Namable) obj, false);
     if (visitSubNodes){
     IXmlBBase[] Subs  = acceptor.subElements((IXmlBBase)obj);
     if (Subs != null){
     for (int i=0; i<Subs.Length; i++) {
       dispatch(Subs[i], true);
     } // If
     } // If
     }
 }
 public void appendParameters(Lock aLock,Parameter el)
 {
     __setDirty(true);
       el.__setDirty(true);
       allParameters().Add(el);
       acceptor.connectSon (this, el);
     NotifyControllers(aLock);
 }
 public void insertParameters(int idx, Parameter el,Lock aLock)
 {
     __setDirty(true);
       allParameters().Insert (idx, el);
     NotifyControllers(aLock);
 }
        /// <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>
        /// <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
            {
                Log.Error("Cannot create graph for " + Function.ToString());
            }

            return retVal;
        }
 public void copyTo(Parameter other)
 {
     base.copyTo(other);
     other.aTypeName = aTypeName;
 }
        /// <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");
                }
            }
            else
            {
                SpeedRestrictions.AddError("Cannot create graph for " + SpeedRestrictions);
            }

            return retVal;
        }
示例#10
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;

            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
                {
                    Log.Error("Cannot create graph for " + Second.ToString());
                }
            }
            else
            {
                Log.Error("Cannot create graph for " + First.ToString());
            }

            return retVal;
        }
示例#11
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;

            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;
        }
        /// <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;
        }
示例#13
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 firstGraph = createGraphForValue(context, context.FindOnStack(First).Value, explain);
            if (firstGraph != null)
            {
                Graph secondGraph = createGraphForValue(context, context.FindOnStack(Second).Value, explain);
                if (secondGraph != null)
                {
                    retVal = firstGraph.Min(secondGraph) as Graph;
                }
                else
                {
                    Second.AddError("Cannot create graph for " + Second);
                }
            }
            else
            {
                First.AddError("Cannot create graph for " + First);
            }

            return retVal;
        }