Ejemplo n.º 1
0
 public SensorData(float bL, float bR, float tL, float tR, float wKg, CenterOfGravity cog)
 {
     _bottomLeft = bL;
     _bottomoRight = bR;
     _topLeft = tL;
     _topRight = tR;
     _weightKg = wKg;
     _cog = cog;
     _date = DateTime.Now;
 }
Ejemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        Defuzzification result = new CenterOfGravity(
            term,
            new Dictionary <IDimension, decimal> {
            { altitude, (decimal)transform.position.y }
        }
            );

        _rigidbody.AddForce(Vector3.up * (float)result.CrispValue);
        //Debug.Log((float)result.CrispValue);
    }
        private float ComputeGas(float distanceToFrontBound, FuzzyRelation relation)
        {
            decimal distance = (decimal)Mathf.Clamp(distanceToFrontBound, 0.0f, 150.0f);

            if (displayGui)
            {
                memberDangerouslyClose = (float)dangerousClose.IsMember(distance);
                memberClose            = (float)close.IsMember(distance);
                memberFar = (float)far.IsMember(distance);

                memberZeroSpeed = (float)zeroSpeed.IsMember((decimal)m_Car.CurrentSpeed);
                memberLowSpeed  = (float)lowSpeed.IsMember((decimal)m_Car.CurrentSpeed);
                memberHighSpeed = (float)highSpeed.IsMember((decimal)m_Car.CurrentSpeed);
            }



            /*
             * FuzzySet projection = simpleSteeringRules.Project(new Dictionary<IDimension, decimal>()
             * {
             *  {inputSideBoundDistance, distance }
             * });
             *
             * string str = "";
             *
             * for (decimal i = -100; i <= 100; i += 20) {
             *  str += i + ": " + projection.IsMember(i) + ",  ";
             * }
             * Debug.Log(str);
             */

            Defuzzification result = new CenterOfGravity(relation, new Dictionary <IDimension, decimal>()
            {
                { inputFrontBoundDistance, distance },
                { inputSpeed, (decimal)m_Car.CurrentSpeed }
            });

            //Debug.Log("distance: " + distance + ", gas: " + result.CrispValue);

            crispGas = (float)result.CrispValue;
            return((float)result.CrispValue);
        }
        private float ComputeSteering(float distToLeftBound, float distToRightBound, FuzzyRelation relation)
        {
            float r      = Mathf.Clamp(distToRightBound, 0.0f, 20.0f);
            float l      = Mathf.Clamp(distToLeftBound, 0.0f, 20.0f);
            float middle = (l + r) / 2;

            float fCarPosition;

            if (r < middle)
            {
                fCarPosition = 10.0f - (r / middle) * 10.0f;
            }
            else
            {
                fCarPosition = -10.0f + (l / middle) * 10.0f;
            }

            decimal carPosition = (decimal)fCarPosition;

            if (displayGui)
            {
                memberLeft   = (float)dangerousLeft.IsMember(carPosition);
                memberRight  = (float)dangerousRight.IsMember(carPosition);
                memberCenter = (float)safe.IsMember(carPosition);
            }


            Defuzzification result = new CenterOfGravity(relation, new Dictionary <IDimension, decimal>()
            {
                { inputSideBoundDistance, carPosition }
            });

            crispSteeringWheel = (float)result.CrispValue;

            return((float)result.CrispValue);
        }
Ejemplo n.º 5
0
    public float Calc(float inputVolume, float inputQueue)
    {
        inputVolume = Mathf.Clamp(inputVolume, 0, 1200);
        inputQueue  = Mathf.Clamp(inputQueue, 0, 30);
        //#region Definitions
        ////Definition of dimensions on which we will measure the input values
        //ContinuousDimension volume = new ContinuousDimension("Volume", "Vehicle per hour", "veh/hr", 0, 1200);
        //ContinuousDimension queue = new ContinuousDimension("Weight", "Vehicle lenth on proper direction", "veh", 0, 30);


        ////Definition of dimension for output value
        //ContinuousDimension greenLight = new ContinuousDimension("Green Time", "green phase duration of Traffic Light", "s", 5, 60);

        ////Definition of basic fuzzy sets with which we will work
        ////  input sets:
        //FuzzySet Volume_small = new RightLinearSet(volume, "Small", 100, 300);
        //FuzzySet Volume_middle = new TrapezoidalSet(volume, "Middle", 300, 400, 100, 600);
        //FuzzySet Volume_large = new TrapezoidalSet(volume, "Large", 600, 700, 400, 900);
        //FuzzySet Volume_extraLarge = new LeftLinearSet(volume, "Extra Large", 700, 900);

        //FuzzySet Queue_small = new RightLinearSet(queue, "Small", 0, 7);
        //FuzzySet Queue_middle = new TriangularSet(queue, "Middle", 10, 14);
        //FuzzySet Queue_large = new TriangularSet(queue, "Large", 17, 14);
        //FuzzySet Queue_extraLarge = new LeftLinearSet(queue, "Extra Large", 17, 23);

        ////  output set:
        //FuzzySet Time_veryShort = new RightLinearSet(greenLight, "veryshort", 7, 15);
        //FuzzySet Time_short = new TrapezoidalSet(greenLight, "short", 15, 23, 7, 30);
        //FuzzySet Time_middle = new TrapezoidalSet(greenLight, "middle", 30, 38, 23, 45);
        //FuzzySet Time_long = new TrapezoidalSet(greenLight, "long", 45, 53, 38, 60);
        //FuzzySet Time_veryLong = new LeftLinearSet(greenLight, "verylong", 53, 60);

        ////Definition of antedescent
        //FuzzyRelation relation =
        //    ((Volume_small & Queue_small) & Time_veryShort) |
        //    ((Volume_small & Queue_middle) & Time_short) |
        //    ((Volume_small & Queue_large) & Time_short) |
        //    ((Volume_small & Queue_extraLarge) & Time_middle) |
        //    ((Volume_middle & Queue_small) & Time_short) |
        //    ((Volume_middle & Queue_middle) & Time_middle) |
        //    ((Volume_middle & Queue_large) & Time_middle) |
        //    ((Volume_middle & Queue_extraLarge) & Time_long) |
        //    ((Volume_large & Queue_small) & Time_middle) |
        //    ((Volume_large & Queue_middle) & Time_long) |
        //    ((Volume_large & Queue_large) & Time_long) |
        //    ((Volume_large & Queue_extraLarge) & Time_veryLong) |
        //    ((Volume_extraLarge & Queue_small) & Time_middle) |
        //    ((Volume_extraLarge & Queue_middle) & Time_long) |
        //    ((Volume_extraLarge & Queue_large) & Time_veryLong) |
        //    ((Volume_extraLarge & Queue_extraLarge) & Time_veryLong);
        //#endregion

        #region Deffuzification of the output set
        Defuzzification myRes = new CenterOfGravity(relation, new Dictionary <IDimension, decimal> {
            { volume, (decimal)inputVolume },
            { queue, (decimal)inputQueue }
        });

        ans = (float)myRes.CrispValue;
        #endregion

        return((float)ans);
    }
 public void Setup()
 {
     centerOfGravity = new CenterOfGravity();
 }