示例#1
0
        /// <summary>
        /// Whether the signal is restricted to be <= 0
        /// </summary>
        public static bool IsAlwaysNonpositive(Signal signal)
        {
            if (signal == null)
            {
                throw new ArgumentNullException("signal");
            }

            return(signal.IsFlagEnabled(StdAspect.NegativeOrZeroConstraintFlag) ||
                   IsConstant(signal) && RealValue.CanConvertLosslessFrom(signal.Value) && RealValue.ConvertFrom(signal.Value).Value <= 0d);
        }
示例#2
0
        /// <summary>
        /// Checks if the specified value is compatible with this type.  A
        /// value is compatible if and only if it is an numeric value
        /// representing positive or negative infinity
        /// </summary>
        /// <param name="value">The value to check</param>
        /// <returns>True if the value is compatible, false if not</returns>
        public override bool IsCompatible(MibValue value)
        {
            RealValue number = value as RealValue;

            if (number != null)
            {
                return(double.IsInfinity(number.Value));
            }

            return(false);
        }
示例#3
0
        private void assertRealValue(AttributeValue attr, double value)
        {
            Assert.IsInstanceOfType(attr.getValue(), typeof(PrimitiveObjectBlock));
            PrimitiveObjectBlock pob = (PrimitiveObjectBlock)attr.getValue();

            Assert.IsInstanceOfType(pob.getSimpleValue(), typeof(RealValue));
            RealValue actual = (RealValue)pob.getSimpleValue();

            java.lang.Double expected = new java.lang.Double(value);
            Assert.AreEqual(actual.getValue(), expected);
        }
示例#4
0
        public override bool StillValidAfterEvent(Signal signal)
        {
            if (signal == null)
            {
                throw new ArgumentNullException("signal");
            }

            if (signal.Value == null)
            {
                return(false);
            }
            return(RealValue.CanConvertLosslessFrom(signal.Value));
        }
示例#5
0
        public void DirectLosslessConversionsTest()
        {
            IntegerValue int1 = new IntegerValue(35);

            RationalValue rat1 = ValueConverter <RationalValue> .ConvertFrom(int1);

            Assert.AreEqual(35, rat1.NumeratorValue, "01");
            Assert.AreEqual(1, rat1.DenominatorValue, "02");

            RealValue real1 = ValueConverter <RealValue> .ConvertFrom(rat1);

            Assert.AreEqual(35d, real1.Value, 0.0001d, "03");
        }
示例#6
0
 /// <returns>true if an event shall be posted.</returns>
 private bool UpdatePeriods(int index, Signal inputSignal)
 {
     if (RealValue.CanConvertLosslessFrom(inputSignal.Value))
     {
         periods[index] = TimeSpan.FromSeconds(1.0 / RealValue.ConvertFrom(inputSignal.Value).Value);
         return(true);
     }
     else
     {
         periods[index] = TimeSpan.Zero;
         return(false);
     }
 }
示例#7
0
        public void NeuronWithCachedValue()
        {
            var    real   = new RealValue(1.0);
            Neuron neuron = new Neuron(real);

            Assert.AreEqual(1, neuron.Value);

            real.Value = 0.0;

            Assert.AreEqual(1, neuron.Value);

            neuron.Clear();

            Assert.AreEqual(0, neuron.Value);
        }
示例#8
0
        public IEnumerable <Attribute> Fetch(string path, DateTime lastWriteTime)
        {
            using (var reader = Execute(path, lastWriteTime))
            {
                while (reader.Read())
                {
                    var name      = reader.GetString(0);
                    var source    = reader.GetInt32(1);
                    var type      = reader.GetInt32(2);
                    var valueSize = reader.GetInt64(4);

                    // parse value
                    BaseValue value = null;
                    switch ((AttributeType)type)
                    {
                    case AttributeType.Int:
                        value = new IntValue(reader.GetInt32(3));
                        break;

                    case AttributeType.Double:
                        value = new RealValue(reader.GetDouble(3));
                        break;

                    case AttributeType.String:
                        value = new StringValue(reader.GetString(3));
                        break;

                    case AttributeType.DateTime:
                        value = new DateTimeValue(reader.GetDateTime(3));
                        break;

                    case AttributeType.Image:
                        var buffer = new byte[valueSize];
                        var length = reader.GetBytes(3, 0, buffer, 0, buffer.Length);
                        Trace.Assert(buffer.Length == length);
                        value = new ImageValue(buffer);
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }

                    // return the attribute
                    yield return(new Attribute(name, value, (AttributeSource)source));
                }
            }
        }
        private IPrimitiveValue parsePrimitiveValue(IJsonReader <TokenType> jreader)
        {
            TokenType type  = jreader.getCurrentTokenType();
            object    value = jreader.getCurrentValue();
            bool      isOk  = (((type == TokenType.String) ||
                                (type == TokenType.Boolean) ||
                                (type == TokenType.Integer) ||
                                (type == TokenType.Float)) &&
                               (value != null) &&
                               ((value is String) ||
                                (value is Boolean) ||
                                (value is ValueType)));
            IPrimitiveValue pvalue = null;

            if (isOk)
            {
                if (type == TokenType.String)
                {
                    pvalue = CharacterStringValue.create((String)value);
                }
                if (type == TokenType.Integer)
                {
                    pvalue = IntegerValue.create((ValueType)value);
                }
                if (type == TokenType.Float)
                {
                    pvalue = RealValue.create((ValueType)value);
                }
                if (type == TokenType.Boolean)
                {
                    pvalue = BooleanValue.create((Boolean)value);
                }
            }
            else
            {
                throw new ArgumentException("Argument 'type' must be a TokenType with " +
                                            "option of String or Boolean " +
                                            "or Integer or Float\n" +
                                            "Argument 'value' must be not null and " +
                                            "of type String or Boolean or ValueType.");
            }
            return(pvalue);
        }
示例#10
0
        public void IndirectLosslessConversionsTest()
        {
            ToggleValue toggle1 = ToggleValue.InitialToggle;

            Assert.AreEqual("Std.Toggle(A)", toggle1.ToString(), "01");

            RationalValue rat1 = ValueConverter <RationalValue> .ConvertFrom(toggle1);

            Assert.AreEqual(1, rat1.NumeratorValue, "02");
            Assert.AreEqual(1, rat1.DenominatorValue, "03");

            RationalValue rat2 = ValueConverter <RationalValue> .ConvertFrom(toggle1.Toggle());

            Assert.AreEqual(0, rat2.NumeratorValue, "04");
            Assert.AreEqual(1, rat2.DenominatorValue, "05");

            RealValue real1 = ValueConverter <RealValue> .ConvertFrom(toggle1);

            Assert.AreEqual(1d, real1.Value, 0.0001d, "06");
        }
示例#11
0
        public double[] Evaluate(params double[] inputs)
        {
            if (inputs.Length != _inputs.Count)
            {
                throw new System.ArgumentException("The count of inputs doesn't match the systems count of input signals.", "inputs");
            }

            for (int i = 0; i < inputs.Length; i++)
            {
                _inputs[i].PostNewValue(new RealValue(inputs[i]));
            }

            _context.Scheduler.SimulateInstant();

            double[] outputs = new double[_outputs.Count];
            for (int i = 0; i < outputs.Length; i++)
            {
                outputs[i] = RealValue.ConvertFrom(_outputs[i].Value).Value;
            }
            return(outputs);
        }
示例#12
0
        public void SetText(object Value)
        {
            if ((Value == null) || (Value.ToString() == "NaN") || (string.IsNullOrEmpty(Value.ToString())))
            {
                if (RealValue != -99999)
                {
                    IsModify = true;
                }
                RealValue = -99999;


                return;
            }
            try
            {
                if (decimal.Parse(Value.ToString()) == RealValue)
                {
                    if (!string.IsNullOrEmpty(this.Text))
                    {
                        IsModify = false;
                        return;
                    }
                }

                if (RealValue.ToString() != Value.ToString())
                {
                    IsModify = true;
                }

                RealValue = decimal.Parse(Value.ToString());
            }
            catch (Exception E)
            {
                RealValue = -99999;
            }

            //decimal? dec = null;
        }
示例#13
0
 public virtual T Visit(RealValue node)
 {
     return(Visit((ConstantValue)node));
 }
示例#14
0
 public override bool Visit(RealValue node)
 {
     Visit((ConstantValue)node);
     return(true);
 }
示例#15
0
        public Gain(FlightControlSystem fcs, XmlElement element)
            : base(fcs, element)
        {
            gain   = null;
            Table  = null;
            InMin  = -1.0;
            InMax  = 1.0;
            OutMin = OutMax = 0.0;

            if (compType == "PURE_GAIN")
            {
                if (element.FindElement("gain") == null)
                {
                    log.Error("      No GAIN specified (default: 1.0)");
                }
            }

            XmlElement gain_element = element.FindElement("gain");

            if (gain_element != null)
            {
                gain = new ParameterValue(gain_element, propertyManager);
            }
            else
            {
                gain = new RealValue(1.0);
            }

            if (compType == "AEROSURFACE_SCALE")
            {
                XmlElement scale_element = element.FindElement("domain");
                if (scale_element != null)
                {
                    if (scale_element.FindElement("max") != null && scale_element.FindElement("min") != null)
                    {
                        XmlElement elem = scale_element.FindElement("max");
                        InMax = FormatHelper.ValueAsNumber(elem);
                        elem  = scale_element.FindElement("min");
                        InMin = FormatHelper.ValueAsNumber(elem);
                    }
                }
                scale_element = element.FindElement("range");
                if (scale_element == null)
                {
                    throw new Exception("No range supplied for aerosurface scale component");
                }
                if (scale_element.FindElement("max") != null && scale_element.FindElement("min") != null)
                {
                    XmlElement elem = scale_element.FindElement("max");
                    OutMax = FormatHelper.ValueAsNumber(elem);
                    elem   = scale_element.FindElement("min");
                    OutMin = FormatHelper.ValueAsNumber(elem);
                }
                else
                {
                    log.Error("Maximum and minimum output values must be supplied for the " +
                              "aerosurface scale component");
                    throw new Exception("Some inputs are missing.");
                }
                ZeroCentered = true;
                XmlElement zero_centered = element.FindElement("zero_centered");
                //ToDo if zero centered, then mins must be <0 and max's must be >0
                if (zero_centered != null)
                {
                    string sZeroCentered = element.FindElementValue("zero_centered");
                    if (sZeroCentered == "0" || sZeroCentered == "false")
                    {
                        ZeroCentered = false;
                    }
                }
            }

            if (compType == "SCHEDULED_GAIN")
            {
                if (element.FindElement("table") != null)
                {
                    Table = new Table(propertyManager, element.FindElement("table"));
                }
                else
                {
                    log.Error("A table must be provided for the scheduled gain component");
                    throw new Exception("Some inputs are missing.");
                }
            }

            Bind(element);

            Debug(0);
        }
示例#16
0
        public void ExitFactor(QueryParser.FactorContext context)
        {
            BaseValue constantValue = null;

            // parse INT
            var constantToken = context.INT();

            if (constantToken != null)
            {
                var value = int.Parse(constantToken.Symbol.Text, CultureInfo.InvariantCulture);
                constantValue = new IntValue(value);
            }
            else if (context.REAL() != null) // parse REAL
            {
                constantToken = context.REAL();
                var value = double.Parse(constantToken.Symbol.Text, CultureInfo.InvariantCulture);
                constantValue = new RealValue(value);
            }
            else if (context.STRING() != null) // parse STRING
            {
                constantToken = context.STRING();
                constantValue = new StringValue(ParseStringValue(constantToken.Symbol));
            }

            // if this is a constant
            if (constantValue != null)
            {
                _expressions.Push(new ConstantExpression(
                                      constantToken.Symbol.Line,
                                      constantToken.Symbol.Column,
                                      constantValue));
                return;
            }

            // parse ID
            string identifier      = null;
            var    identifierToken = context.ID();

            if (identifierToken != null)
            {
                identifier = identifierToken.Symbol.Text;
            }
            else if (context.COMPLEX_ID() != null) // parse COMPLEX_ID
            {
                identifierToken = context.COMPLEX_ID();
                identifier      = ParseComplexIdentifier(identifierToken.Symbol);
            }

            // this is an ID or a function call
            if (identifierToken != null)
            {
                if (context.LPAREN() == null) // attribute access
                {
                    _expressions.Push(new AttributeAccessExpression(
                                          identifierToken.Symbol.Line,
                                          identifierToken.Symbol.Column,
                                          identifier));
                }
                else // function call
                {
                    var stackTop   = _expressionsFrameStart.Pop();
                    var parameters = new List <ValueExpression>();
                    while (_expressions.Count > stackTop)
                    {
                        parameters.Add(_expressions.Pop());
                    }

                    parameters.Reverse();
                    _expressions.Push(new FunctionCallExpression(
                                          identifierToken.Symbol.Line,
                                          identifierToken.Symbol.Column,
                                          identifier,
                                          parameters));
                }

                return;
            }

            // if this is a unary minus
            var unaryOperator = context.ADD_SUB();

            if (unaryOperator != null)
            {
                if (unaryOperator.Symbol.Text == "-")
                {
                    var parameter = _expressions.Pop();
                    _expressions.Push(new UnaryMinusExpression(
                                          unaryOperator.Symbol.Line,
                                          unaryOperator.Symbol.Column,
                                          parameter));
                }
            }

            // otherwise, this is a subexpression => it is already on the stack
        }
示例#17
0
 public override string ToString()
 {
     return(RealValue.ToString() + ImageValue.ToString() + "i");
 }
示例#18
0
 public override string ToString()
 {
     return RealValue.ToString(CultureInfo.InvariantCulture);
 }
示例#19
0
 void IValueVisitor.Visit(RealValue attr)
 {
     _value.Value = attr.Value;
 }
示例#20
0
        public void RealValueZero()
        {
            RealValue value = new RealValue();

            Assert.AreEqual(0, value.Value);
        }
示例#21
0
        public void RealValueWithValue()
        {
            RealValue value = new RealValue(3.14159);

            Assert.AreEqual(3.14159, value.Value);
        }
示例#22
0
 /// <summary>
 /// Преобразование RealValue в строку
 /// </summary>
 /// <param name="value"></param>
 /// <returns></returns>
 public static string ToTestBenchString(RealValue value)
 {
     return(value.Value.ToString());
 }
示例#23
0
 public static bool IsConstantReal(Signal signal)
 {
     return(IsConstant(signal) && RealValue.CanConvertLosslessFrom(signal.Value));
 }
示例#24
0
 void IValueVisitor.Visit(RealValue attr)
 {
     Writer.Write((double)attr.Value);
 }
示例#25
0
        public PID(FlightControlSystem fcs, XmlElement element)
            : base(fcs, element)
        {
            XmlElement el;

            I_out_total        = 0.0;
            Input_prev         = Input_prev2 = 0.0;
            Trigger            = null;
            ProcessVariableDot = null;
            IsStandard         = false;
            IntType            = eIntegrateType.eNone; // No integrator initially defined.

            string pid_type = element.GetAttribute("type");

            if (pid_type == "standard")
            {
                IsStandard = true;
            }

            el = element.FindElement("kp");
            if (el != null)
            {
                Kp = new ParameterValue(el, propertyManager);
            }
            else
            {
                Kp = new RealValue(0.0);
            }

            el = element.FindElement("ki");
            if (el != null)
            {
                string integ_type = el.GetAttribute("type");
                if (integ_type == "rect")
                {            // Use rectangular integration
                    IntType = eIntegrateType.eRectEuler;
                }
                else if (integ_type == "trap")
                {     // Use trapezoidal integration
                    IntType = eIntegrateType.eTrapezoidal;
                }
                else if (integ_type == "ab2")
                {      // Use Adams Bashforth 2nd order integration
                    IntType = eIntegrateType.eAdamsBashforth2;
                }
                else if (integ_type == "ab3")
                {      // Use Adams Bashforth 3rd order integration
                    IntType = eIntegrateType.eAdamsBashforth3;
                }
                else
                {                               // Use default Adams Bashforth 2nd order integration
                    IntType = eIntegrateType.eAdamsBashforth2;
                }

                Ki = new ParameterValue(el, propertyManager);
            }
            else
            {
                Ki = new RealValue(0.0);
            }


            el = element.FindElement("kd");
            if (el != null)
            {
                Kd = new ParameterValue(el, propertyManager);
            }
            else
            {
                Kd = new RealValue(0.0);
            }

            el = element.FindElement("pvdot");
            if (el != null)
            {
                ProcessVariableDot = new PropertyValue(el.InnerText, propertyManager);
            }

            el = element.FindElement("trigger");
            if (el != null)
            {
                Trigger = new PropertyValue(el.InnerText, propertyManager);
            }

            Bind(el);
        }
        public void SerializeFilledCustomDataList()
        {
            Project p = new Project();
            Dictionary<Guid, Guid> emptyMappings = new Dictionary<Guid, Guid>();
            Dictionary<Guid, Signal> signals = new Dictionary<Guid, Signal>();
            Dictionary<Guid, Bus> buses = new Dictionary<Guid, Bus>();

            LiteralValue lv = new LiteralValue("test");
            IntegerValue iv = new IntegerValue(42);
            ComplexValue cv = new ComplexValue(Constants.Pi, Constants.E);
            RealValue rv = new RealValue(Constants.TwoInvSqrtPi);

            List<IValueStructure> values = new List<IValueStructure>();
            values.Add(lv);
            values.Add(iv);
            values.Add(cv);
            values.Add(rv);

            string xml = Serializer.SerializeListToString(values, emptyMappings, emptyMappings, "Structures");

            List<IValueStructure> ret = Serializer.DeserializeListFromString<IValueStructure>(xml, signals, buses, "Structures");

            Assert.AreEqual(4, ret.Count, "A");
            Assert.AreEqual(values[0].TypeId, ret[0].TypeId, "B1");
            Assert.AreEqual(values[1].TypeId, ret[1].TypeId, "B2");
            Assert.AreEqual(values[2].TypeId, ret[2].TypeId, "B3");
            Assert.AreEqual(values[3].TypeId, ret[3].TypeId, "B4");
            Assert.AreEqual(values[0].ToString(), ret[0].ToString(), "C1");
            Assert.AreEqual(values[1].ToString(), ret[1].ToString(), "C2");
            Assert.AreEqual(values[2].ToString(), ret[2].ToString(), "C3");
            Assert.AreEqual(values[3].ToString(), ret[3].ToString(), "C4");
        }
示例#27
0
 public virtual TokenStream GetTokenStream(Analyzer analyzer)
 {
     return(RealValue.GetTokenStream(analyzer));
 }
示例#28
0
        /// Constructor
        public FCSComponent(FlightControlSystem fcsParent, XmlElement element)
        {
            input   = output = delay_time = 0.0;
            delay   = index = 0;
            ClipMin = ClipMax = new RealValue(0.0);
            clip    = cyclic_clip = false;
            dt      = fcs.GetChannelDeltaT();

            propertyManager = fcs.GetPropertyManager();

            if (element.LocalName.Equals("lag_filter"))
            {
                compType = "LAG_FILTER";
            }
            else if (element.LocalName.Equals("lead_lag_filter"))
            {
                compType = "LEAD_LAG_FILTER";
            }
            else if (element.LocalName.Equals("washout_filter"))
            {
                compType = "WASHOUT_FILTER";
            }
            else if (element.LocalName.Equals("second_order_filter"))
            {
                compType = "SECOND_ORDER_FILTER";
            }
            else if (element.LocalName.Equals("integrator"))
            {
                compType = "INTEGRATOR";
            }
            else if (element.LocalName.Equals("summer"))
            {
                compType = "SUMMER";
            }
            else if (element.LocalName.Equals("pure_gain"))
            {
                compType = "PURE_GAIN";
            }
            else if (element.LocalName.Equals("scheduled_gain"))
            {
                compType = "SCHEDULED_GAIN";
            }
            else if (element.LocalName.Equals("aerosurface_scale"))
            {
                compType = "AEROSURFACE_SCALE";
            }
            else if (element.LocalName.Equals("switch"))
            {
                compType = "SWITCH";
            }
            else if (element.LocalName.Equals("kinematic"))
            {
                compType = "KINEMATIC";
            }
            else if (element.LocalName.Equals("deadband"))
            {
                compType = "DEADBAND";
            }
            else if (element.LocalName.Equals("fcs_function"))
            {
                compType = "FCS_FUNCTION";
            }
            else if (element.LocalName.Equals("pid"))
            {
                compType = "PID";
            }
            else if (element.LocalName.Equals("sensor"))
            {
                compType = "SENSOR";
            }
            else if (element.LocalName.Equals("accelerometer"))
            {
                compType = "ACCELEROMETER";
            }
            else if (element.LocalName.Equals("magnetometer"))
            {
                compType = "MAGNETOMETER";
            }
            else if (element.LocalName.Equals("gyro"))
            {
                compType = "GYRO";
            }
            else if (element.LocalName.Equals("actuator"))
            {
                compType = "ACTUATOR";
            }
            else if (element.LocalName.Equals("waypoint_heading"))
            {
                compType = "WAYPOINT_HEADING";
            }
            else if (element.LocalName.Equals("waypoint_distance"))
            {
                compType = "WAYPOINT_DISTANCE";
            }
            else if (element.LocalName.Equals("angle"))
            {
                compType = "ANGLE";
            }
            else if (element.LocalName.Equals("distributor"))
            {
                compType = "DISTRIBUTOR";
            }
            else
            { // illegal component in this channel
                compType = "UNKNOWN";
            }

            name = element.GetAttribute("name");

            foreach (XmlNode currentNode in element.GetElementsByTagName("init"))
            {
                if (currentNode.NodeType == XmlNodeType.Element)
                {
                    XmlElement init_element = (XmlElement)currentNode;
                    initNodes.Add(new PropertyValue(init_element.InnerText, propertyManager));
                }
            }
            foreach (XmlNode currentNode in element.GetElementsByTagName("input"))
            {
                if (currentNode.NodeType == XmlNodeType.Element)
                {
                    XmlElement input_element = (XmlElement)currentNode;
                    inputNodes.Add(new PropertyValue(input_element.InnerText, propertyManager));
                }
            }
            foreach (XmlNode currentNode in element.GetElementsByTagName("output"))
            {
                if (currentNode.NodeType == XmlNodeType.Element)
                {
                    XmlElement   out_elem         = (XmlElement)currentNode;
                    string       output_node_name = out_elem.InnerText;
                    bool         node_exists      = propertyManager.HasNode(output_node_name);
                    PropertyNode OutputNode       = propertyManager.GetNode(output_node_name, true);
                    if (OutputNode == null)
                    {
                        log.Error("  Unable to process property: " + output_node_name);
                        throw new Exception("Invalid output property name in flight control definition");
                    }
                    outputNodes.Add(OutputNode);
                    // If the node has just been created then it must be initialized to a
                    // sensible value since FGPropertyNode::GetNode() does not take care of
                    // that.  If the node was already existing, its current value is kept
                    // unchanged.
                    if (!node_exists)
                    {
                        OutputNode.Set(output);
                    }
                }
            }
            XmlElement delay_elem = element.FindElement("delay");

            if (delay_elem != null)
            {
                delay_time = delay_elem.GetDataAsNumber();
                string delayType = delay_elem.GetAttribute("type");
                if (!string.IsNullOrEmpty(delayType))
                {
                    if (delayType == "time")
                    {
                        delay = (int)(delay_time / dt);
                    }
                    else if (delayType == "frames")
                    {
                        delay = (int)delay_time;
                    }
                    else
                    {
                        log.Error("Unallowed delay type");
                    }
                }
                else
                {
                    delay = (int)(delay_time / dt);
                }
                output_array.Resize(delay);
                for (int i = 0; i < delay; i++)
                {
                    output_array[i] = 0.0;
                }
            }

            XmlElement clip_el = element.FindElement("clipto");

            if (clip_el != null)
            {
                XmlElement el = clip_el.FindElement("min");
                if (el == null)
                {
                    log.Error("Element <min> is missing, <clipto> is ignored.");
                    return;
                }

                ClipMin = new ParameterValue(el, propertyManager);

                el = clip_el.FindElement("max");
                if (el == null)
                {
                    log.Error("Element <max> is missing, <clipto> is ignored.");
                    ClipMin = null;
                    return;
                }

                ClipMax = new ParameterValue(el, propertyManager);

                if (clip_el.GetAttribute("type") == "cyclic")
                {
                    cyclic_clip = true;
                }

                clip = true;
            }

            Debug(0);
        }