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); }