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

fromJSON

描述

FuzzyVariable.fromJSON() 方法将从JSON格式中恢复模糊变量对象。模糊变量包含模糊集合和模糊规则。

语法

FuzzyVariable.fromJSON(jsonString)

参数

jsonString: 要恢复的模糊变量对象的JSON字符串。

返回值

FuzzyVariable对象

示例

const jsonString = '{"name":"temperature","min":0,"max":100,"sets":[{"name":"cold","type":"triangle","params":[0,0,25]},{"name":"moderate","type":"triangle","params":[0,25,50]},{"name":"hot","type":"triangle","params":[25,50,100]}],"rules":[{"antecedent":[{"set":"cold","variable":"temperature"}],"consequent":{"set":"low","variable":"fan_speed"}},{"antecedent":[{"set":"moderate","variable":"temperature"}],"consequent":{"set":"medium","variable":"fan_speed"}},{"antecedent":[{"set":"hot","variable":"temperature"}],"consequent":{"set":"high","variable":"fan_speed"}}]}';

const fuzzyVariable = FuzzyVariable.fromJSON(jsonString);
console.log(fuzzyVariable);

上述代码将输出以下内容:

{
  name: 'temperature',
  min: 0,
  max: 100,
  sets: [
    { name: 'cold', type: 'triangle', params: [ 0, 0, 25 ] },
    { name: 'moderate', type: 'triangle', params: [ 0, 25, 50 ] },
    { name: 'hot', type: 'triangle', params: [ 25, 50, 100 ] }
  ],
  rules: [
    {
      antecedent: [ { set: 'cold', variable: 'temperature' } ],
      consequent: { set: 'low', variable: 'fan_speed' }
    },
    {
      antecedent: [ { set: 'moderate', variable: 'temperature' } ],
      consequent: { set: 'medium', variable: 'fan_speed' }
    },
    {
      antecedent: [ { set: 'hot', variable: 'temperature' } ],
      consequent: { set: 'high', variable: 'fan_speed' }
    }
  ]
}

注意事项

JSON字符串应该以与FuzzyVariable.toJSON()输出的字符串相同的格式编写。否则,恢复过程可能会失败。

在开发中,我们建议使用FuzzyVariable.toJSON()方法生成JSON字符串,并使用FuzzyVariable.fromJSON()方法将其恢复为对象。