示例#1
0
        static Offset <FDouble> Serialise(FlatBufferBuilder b, IHasDouble numeral)
        {
            FDouble.StartFDouble(b);
            var vec2 = numeral.ObservationValue;

            var granularity = numeral.DoubleSpace.DecimalGranularity;
            var xs          = numeral.DoubleSpace.Xspace;
            var ys          = numeral.DoubleSpace.Yspace;

            FDouble.AddXRange(b,
                              FRange.CreateFRange(b,
                                                  granularity,
                                                  xs.Max,
                                                  xs.Min,
                                                  xs.NormalisedBool));
            FDouble.AddYRange(b,
                              FRange.CreateFRange(b,
                                                  granularity,
                                                  ys.Max,
                                                  ys.Min,
                                                  ys.NormalisedBool));
            FDouble.AddVec2(b, FVector2.CreateFVector2(b, vec2.x, vec2.y));

            return(FDouble.EndFDouble(b));
        }
示例#2
0
        static Offset <FObjective> Serialise(FlatBufferBuilder b, EnvironmentDescription description)
        {
            var ob_name = "None";
            var ep_len  = -1;
            var a       = 0;
            var f       = 0f;
            var c       = 0f;
            var d       = false;

            if (description.ObjectiveFunction != null)
            {
                ob_name = description.ObjectiveFunction.Identifier;
                ep_len  = description.ObjectiveFunction.EpisodeLength;
                f       = description.ObjectiveFunction.SignalSpace.Min;
                c       = description.ObjectiveFunction.SignalSpace.Max;
                a       = description.ObjectiveFunction.SignalSpace.DecimalGranularity;
                d       = description.ObjectiveFunction.SignalSpace.NormalisedBool;
            }

            var objective_name_offset = b.CreateString(ob_name);

            FObjective.StartFObjective(b);
            FObjective.AddMaxEpisodeLength(b, ep_len);
            FObjective.AddSignalSpace(b,
                                      FRange.CreateFRange(b,
                                                          a,
                                                          f,
                                                          c,
                                                          d));
            FObjective.AddObjectiveName(b, objective_name_offset);
            return(FObjective.EndFObjective(b));
        }
示例#3
0
        static Offset <FTriple> Serialise(FlatBufferBuilder b, IHasTriple numeral)
        {
            FTriple.StartFTriple(b);
            var vec3 = numeral.ObservationValue;

            FTriple.AddVec3(b,
                            FVector3.CreateFVector3(b,
                                                    vec3.x,
                                                    vec3.y,
                                                    vec3.z));
            var granularity = numeral.TripleSpace.DecimalGranularity;
            var xs          = numeral.TripleSpace.Xspace;
            var ys          = numeral.TripleSpace.Yspace;
            var zs          = numeral.TripleSpace.Zspace;

            FTriple.AddXRange(b,
                              FRange.CreateFRange(b,
                                                  granularity,
                                                  xs.Max,
                                                  xs.Min,
                                                  xs.NormalisedBool));
            FTriple.AddYRange(b,
                              FRange.CreateFRange(b,
                                                  granularity,
                                                  ys.Max,
                                                  ys.Min,
                                                  ys.NormalisedBool));
            FTriple.AddZRange(b,
                              FRange.CreateFRange(b,
                                                  granularity,
                                                  zs.Max,
                                                  zs.Min,
                                                  zs.NormalisedBool));
            return(FTriple.EndFTriple(b));
        }
示例#4
0
        static Offset <FArray> Serialise(FlatBufferBuilder b, IHasFloatArray float_a)
        {
            var v_offset = FArray.CreateArrayVectorBlock(b, float_a.ObservationArray);
            //var v_offset = CustomFlatBufferImplementation.CreateFloatVector(b, float_a.ObservationArray);

            var ranges_vector = new VectorOffset();

            FArray.StartRangesVector(b, float_a.ObservationSpace.Length);
            foreach (var tra in float_a.ObservationSpace)
            {
                FRange.CreateFRange(b,
                                    tra.DecimalGranularity,
                                    tra.Max,
                                    tra.Min,
                                    tra.NormalisedBool);
            }

            ranges_vector = b.EndVector();

            FArray.StartFArray(b);
            FArray.AddArray(b, v_offset);

            FArray.AddRanges(b, ranges_vector);

            return(FArray.EndFArray(b));
        }
示例#5
0
        /// <summary>
        /// </summary>
        /// <param name="b"></param>
        /// <param name="sensor"></param>
        /// <returns></returns>
        static Offset <FQTObs> Serialise(FlatBufferBuilder b, IHasQuaternionTransform sensor)
        {
            var pos       = sensor.Position;
            var rot       = sensor.Rotation;
            var pos_range = sensor.PositionSpace;
            var rot_range = sensor.RotationSpace;

            FQTObs.StartFQTObs(b);
            FQTObs.AddPosRange(b,
                               FRange.CreateFRange(b,
                                                   pos_range.DecimalGranularity,
                                                   pos_range.Max,
                                                   pos_range.Min,
                                                   pos_range.NormalisedBool));
            FQTObs.AddRotRange(b,
                               FRange.CreateFRange(b,
                                                   rot_range.DecimalGranularity,
                                                   rot_range.Max,
                                                   rot_range.Min,
                                                   rot_range.NormalisedBool));
            FQTObs.AddTransform(b,
                                FQuaternionTransform.CreateFQuaternionTransform(b,
                                                                                pos.x,
                                                                                pos.y,
                                                                                pos.z,
                                                                                rot.x,
                                                                                rot.y,
                                                                                rot.z,
                                                                                rot.w));

            return(FQTObs.EndFQTObs(b));
        }
示例#6
0
        static Offset <FConfigurable> Serialise(
            FlatBufferBuilder b,
            IConfigurable configurable,
            string identifier)
        {
            var n = b.CreateString(identifier);

            int          observation_offset;
            FObservation observation_type;

            if (configurable is IHasQuaternionTransform)
            {
                observation_offset = Serialise(b, (IHasQuaternionTransform)configurable).Value;
                observation_type   = FObservation.FQTObs;
            }
            else if (configurable is PositionConfigurable)
            {
                observation_offset = Serialise(b, (PositionConfigurable)configurable).Value;
                observation_type   = FObservation.FTriple;
            }
            else if (configurable is IHasSingle)
            {
                observation_offset = Serialise(b, (IHasSingle)configurable).Value;
                observation_type   = FObservation.FSingle;
                // ReSharper disable once SuspiciousTypeConversion.Global
            }
            else if (configurable is IHasDouble)
            {
                // ReSharper disable once SuspiciousTypeConversion.Global
                observation_offset = Serialise(b, (IHasDouble)configurable).Value;
                observation_type   = FObservation.FDouble;
            }
            else if (configurable is EulerTransformConfigurable)
            {
                observation_offset = Serialise(b, (IHasEulerTransform)configurable).Value;
                observation_type   = FObservation.FETObs;
            }
            else
            {
                FConfigurable.StartFConfigurable(b);
                FConfigurable.AddConfigurableName(b, n);
                return(FConfigurable.EndFConfigurable(b));
            }

            FConfigurable.StartFConfigurable(b);
            FConfigurable.AddConfigurableName(b, n);
            FConfigurable.AddConfigurableValue(b, observation_offset);
            FConfigurable.AddConfigurableValueType(b, observation_type);
            FConfigurable.AddConfigurableRange(b,
                                               FRange.CreateFRange(b,
                                                                   0,
                                                                   0,
                                                                   0,
                                                                   false));
            return(FConfigurable.EndFConfigurable(b));
        }
示例#7
0
        static Offset <FSingle> Serialise(FlatBufferBuilder b, IHasSingle numeral)
        {
            FSingle.StartFSingle(b);
            FSingle.AddValue(b, numeral.ObservationValue);

            var range_offset = FRange.CreateFRange(b,
                                                   numeral.SingleSpace.DecimalGranularity,
                                                   numeral.SingleSpace.Max,
                                                   numeral.SingleSpace.Min,
                                                   numeral.SingleSpace.NormalisedBool);

            FSingle.AddRange(b, range_offset);
            return(FSingle.EndFSingle(b));
        }
示例#8
0
        static Offset <FActuator> Serialise(FlatBufferBuilder b, IActuator actuator, string identifier)
        {
            var n = b.CreateString(identifier);

            FActuator.StartFActuator(b);
            FActuator.AddActuatorName(b, n);
            FActuator.AddActuatorRange(b,
                                       FRange.CreateFRange(b,
                                                           actuator.MotionSpace.DecimalGranularity,
                                                           actuator.MotionSpace.Max,
                                                           actuator.MotionSpace.Min,
                                                           actuator.MotionSpace.NormalisedBool));
            return(FActuator.EndFActuator(b));
        }
示例#9
0
        static Offset <FMotor> build_motor(FlatBufferBuilder b, Motor motor, string identifier)
        {
            var n = b.CreateString(identifier);

            FMotor.StartFMotor(b);
            FMotor.AddMotorName(b, n);
            FMotor.AddValidInput(
                b,
                FRange.CreateFRange(
                    b,
                    motor.MotionValueSpace.DecimalGranularity,
                    motor.MotionValueSpace.MaxValue,
                    motor.MotionValueSpace.MinValue));
            FMotor.AddEnergySpentSinceReset(b, motor.GetEnergySpend());
            return(FMotor.EndFMotor(b));
        }
示例#10
0
        static Offset <FQuadruple> Serialise(FlatBufferBuilder b, IHasQuadruple numeral)
        {
            FQuadruple.StartFQuadruple(b);
            var quad = numeral.ObservationValue;

            FQuadruple.AddQuat(b,
                               FQuaternion.CreateFQuaternion(b,
                                                             quad.x,
                                                             quad.y,
                                                             quad.z,
                                                             quad.z));
            var granularity = numeral.QuadSpace.DecimalGranularity;
            var xs          = numeral.QuadSpace.Xspace;
            var ys          = numeral.QuadSpace.Yspace;
            var zs          = numeral.QuadSpace.Zspace;
            var ws          = numeral.QuadSpace.Wspace;

            FQuadruple.AddXRange(b,
                                 FRange.CreateFRange(b,
                                                     granularity,
                                                     xs.Max,
                                                     xs.Min,
                                                     xs.NormalisedBool));
            FQuadruple.AddYRange(b,
                                 FRange.CreateFRange(b,
                                                     granularity,
                                                     ys.Max,
                                                     ys.Min,
                                                     ys.NormalisedBool));
            FQuadruple.AddZRange(b,
                                 FRange.CreateFRange(b,
                                                     granularity,
                                                     zs.Max,
                                                     zs.Min,
                                                     zs.NormalisedBool));
            FQuadruple.AddWRange(b,
                                 FRange.CreateFRange(b,
                                                     granularity,
                                                     ws.Max,
                                                     ws.Min,
                                                     ws.NormalisedBool));
            return(FQuadruple.EndFQuadruple(b));
        }