AABB
AlignmentBehavior
ArriveBehavior
AStar
BFS
BoundingSphere
BVH
BVHNode
Cell
CellSpacePartitioning
CohesionBehavior
CompositeGoal
ConvexHull
Corridor
CostTable
DFS
Dijkstra
Edge
EntityManager
EvadeBehavior
EventDispatcher
Behavior
FollowPathBehavior
FuzzyAND
FuzzyCompositeTerm
FuzzyFAIRLY
FuzzyModule
FuzzyOR
FuzzyRule
FuzzySet
FuzzyTerm
FuzzyVariable
FuzzyVERY
GameEntity
Goal
GoalEvaluator
Graph
GraphUtils
HalfEdge
HeuristicPolicyDijkstra
HeuristicPolicyEuclid
HeuristicPolicyEuclidSquared
HeuristicPolicyManhattan
InterposeBehavior
LeftSCurveFuzzySet
LeftShoulderFuzzySet
LineSegment
Logger
MathUtils
Matrix3
Matrix4
MemoryRecord
MemorySystem
MeshGeometry
MessageDispatcher
MovingEntity
NavEdge
NavMesh
NavMeshLoader
NavNode
Node
NormalDistFuzzySet
OBB
ObstacleAvoidanceBehavior
OffsetPursuitBehavior
OnPathBehavior
Path
Plane
Polygon
Polyhedron
PriorityQueue
PursuitBehavior
Quaternion
Ray
RectangleTriggerRegion
Regular
RightSCurveFuzzySet
RightShoulderFuzzySet
SAT
SeekBehavior
SeparationBehavior
SingletonFuzzySet
Smoother
SphericalTriggerRegion
State
StateMachine
SteeringBehavior
SteeringManager
Task
TaskQueue
Telegram
Think
Time
TriangularFuzzySet
Trigger
TriggerRegion
Vector3
Vehicle
Version
WanderBehavior

flvs

简介

flvs是Yuka js库中的FuzzyModule(模糊模块)中的一个类。它是一个模糊语言变量集合,可以通过它来描述一个模糊系统。flvs包含了一系列模糊变量和它们的隶属函数。

属性

  • variables:一个map对象,包含了所有的模糊变量,其中模糊变量名称作为键,模糊变量对象作为值。

方法

  • addVariable(name, variable):添加一个模糊变量,参数name表示模糊变量名称,参数variable表示模糊变量对象。

  • getVariable(name):获取指定名称的模糊变量。

  • fuzzify(name, value):对指定名称的模糊变量进行模糊化,参数value为要进行模糊化的值。

  • defuzzify(name, method):对指定名称的模糊变量进行去模糊化(defuzzification),参数method为去模糊方法。

  • clear():清除所有变量的隶属函数。

示例

下面的示例演示了如何使用flvs类:

import { FuzzyModule, flvs } from 'yuka';

const fuzzModule = new FuzzyModule();

// 添加一个模糊变量
const fuzzyVariable = new flvs.FuzzyVariable('temperature', 0, 100);
fuzzyVariable.addTerm(new flvs.LeftShoulderFuzzySet('cold', 0, 20, 40));
fuzzyVariable.addTerm(new flvs.TriangularFuzzySet('cool', 20, 40, 60));
fuzzyVariable.addTerm(new flvs.TriangularFuzzySet('warm', 40, 60, 80));
fuzzyVariable.addTerm(new flvs.RightShoulderFuzzySet('hot', 60, 80, 100));
fuzzModule.addVariable('temperature', fuzzyVariable);

// 模糊化
fuzzModule.fuzzify('temperature', 50);

// 去模糊化,使用Centroid算法
const value = fuzzModule.defuzzify('temperature', flvs.CentroidMethod);

在上面的示例中,我们首先创建了一个模糊变量temperature,它的范围是0到100。然后我们给它添加了4个隶属函数,分别是cold、cool、warm和hot。接着我们将这个模糊变量添加到了FuzzyModule中。

然后我们对这个模糊变量进行了模糊化,传入的值为50。最后,我们使用Centroid算法对模糊变量进行了去模糊化,并将结果保存在value变量中。