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

Yuka js库的FuzzyModule类的fromJSON方法,用于将JSON格式的模糊控制系统描述转换为FuzzyModule实例。

语法

FuzzyModule.fromJSON(stringifiedJsonDescriptor)

参数

  • stringifiedJsonDescriptor:类型为String,是一个JSON格式的模糊控制系统描述字符串。

返回值

返回一个FuzzyModule实例,代表被转换的模糊控制系统。

描述

该方法是FuzzyModule类中的静态方法,用于从JSON字符串中解析描述模糊控制系统的数据,并返回一个相应的FuzzyModule实例。

JSON格式的模糊控制系统描述应包含以下属性:

  • variables:所有变量的数组,每个变量应该包含以下属性:
    • name:变量的名称
    • minValue:变量的最小值
    • maxValue:变量的最大值
    • terms:变量的词项,是一个对象,其键为词项名称,值为Term实例的JSON描述
  • rules:模糊规则的数组,每个规则应包含以下属性:
    • antecedent:前提条件,是一个对象,由变量名称和一个字符串表示的词项组成,例如:{"humidity": "high", "temperature": "low"}
    • consequent:结论,是由一个变量名称和一个字符串表示的词项组成的对象,例如:{"flow": "medium"}
    • weight:权重,是一个数字,用于调整规则的优先级

JSON格式的Term描述应包含以下属性:

  • type:Term的类型,例如:Triangle、LeftShoulder、RightShoulder、Trapezoid、Singleton
  • params:描述Term参数的对象,其属性根据Term类型而定

以下是一个示例JSON字符串:

{
  "variables": [
    {
      "name": "humidity",
      "minValue": 0,
      "maxValue": 100,
      "terms": {
        "low": {
          "type": "Triangle",
          "params": {
            "left": 0,
            "top": 25,
            "right": 50
          }
        },
        "medium": {
          "type": "Triangle",
          "params": {
            "left": 25,
            "top": 50,
            "right": 75
          }
        },
        "high": {
          "type": "Triangle",
          "params": {
            "left": 50,
            "top": 75,
            "right": 100
          }
        }
      }
    },
    {
      "name": "temperature",
      "minValue": 10,
      "maxValue": 40,
      "terms": {
        "low": {
          "type": "Triangle",
          "params": {
            "left": 10,
            "top": 15,
            "right": 20
          }
        },
        "medium": {
          "type": "Triangle",
          "params": {
            "left": 15,
            "top": 25,
            "right": 35
          }
        },
        "high": {
          "type": "Triangle",
          "params": {
            "left": 30,
            "top": 40,
            "right": 40
          }
        }
      }
    },
    {
      "name": "flow",
      "minValue": 0,
      "maxValue": 10,
      "terms": {
        "low": {
          "type": "Triangle",
          "params": {
            "left": 0,
            "top": 3,
            "right": 6
          }
        },
        "medium": {
          "type": "Triangle",
          "params": {
            "left": 3,
            "top": 5,
            "right": 8
          }
        },
        "high": {
          "type": "Triangle",
          "params": {
            "left": 6,
            "top": 10,
            "right": 10
          }
        }
      }
    }
  ],
  "rules": [
    {
      "antecedent": {
        "humidity": "low",
        "temperature": "low"
      },
      "consequent": {
        "flow": "low"
      },
      "weight": 1
    },
    {
      "antecedent": {
        "humidity": "medium",
        "temperature": "low"
      },
      "consequent": {
        "flow": "medium"
      },
      "weight": 1
    },
    {
      "antecedent": {
        "humidity": "high",
        "temperature": "low"
      },
      "consequent": {
        "flow": "high"
      },
      "weight": 1
    },
    {
      "antecedent": {
        "humidity": "low",
        "temperature": "medium"
      },
      "consequent": {
        "flow": "medium"
      },
      "weight": 1
    },
    {
      "antecedent": {
        "humidity": "medium",
        "temperature": "medium"
      },
      "consequent": {
        "flow": "high"
      },
      "weight": 1
    },
    {
      "antecedent": {
        "humidity": "high",
        "temperature": "medium"
      },
      "consequent": {
        "flow": "high"
      },
      "weight": 1
    },
    {
      "antecedent": {
        "humidity": "low",
        "temperature": "high"
      },
      "consequent": {
        "flow": "low"
      },
      "weight": 1
    },
    {
      "antecedent": {
        "humidity": "medium",
        "temperature": "high"
      },
      "consequent": {
        "flow": "low"
      },
      "weight": 1
    },
    {
      "antecedent": {
        "humidity": "high",
        "temperature": "high"
      },
      "consequent": {
        "flow": "medium"
      },
      "weight": 1
    }
  ]
}

示例

const jsonDescriptor = `{
  "variables": [
    {
      "name": "humidity",
      "minValue": 0,
      "maxValue": 100,
      "terms": {
        "low": {
          "type": "Triangle",
          "params": {
            "left": 0,
            "top": 25,
            "right": 50
          }
        },
        "medium": {
          "type": "Triangle",
          "params": {
            "left": 25,
            "top": 50,
            "right": 75
          }
        },
        "high": {
          "type": "Triangle",
          "params": {
            "left": 50,
            "top": 75,
            "right": 100
          }
        }
      }
    },
    {
      "name": "temperature",
      "minValue": 10,
      "maxValue": 40,
      "terms": {
        "low": {
          "type": "Triangle",
          "params": {
            "left": 10,
            "top": 15,
            "right": 20
          }
        },
        "medium": {
          "type": "Triangle",
          "params": {
            "left": 15,
            "top": 25,
            "right": 35
          }
        },
        "high": {
          "type": "Triangle",
          "params": {
            "left": 30,
            "top": 40,
            "right": 40
          }
        }
      }
    },
    {
      "name": "flow",
      "minValue": 0,
      "maxValue": 10,
      "terms": {
        "low": {
          "type": "Triangle",
          "params": {
            "left": 0,
            "top": 3,
            "right": 6
          }
        },
        "medium": {
          "type": "Triangle",
          "params": {
            "left": 3,
            "top": 5,
            "right": 8
          }
        },
        "high": {
          "type": "Triangle",
          "params": {
            "left": 6,
            "top": 10,
            "right": 10
          }
        }
      }
    }
  ],
  "rules": [
    {
      "antecedent": {
        "humidity": "low",
        "temperature": "low"
      },
      "consequent": {
        "flow": "low"
      },
      "weight": 1
    },
    {
      "antecedent": {
        "humidity": "medium",
        "temperature": "low"
      },
      "consequent": {
        "flow": "medium"
      },
      "weight": 1
    },
    {
      "antecedent": {
        "humidity": "high",
        "temperature": "low"
      },
      "consequent": {
        "flow": "high"
      },
      "weight": 1
    },
    {
      "antecedent": {
        "humidity": "low",
        "temperature": "medium"
      },
      "consequent": {
        "flow": "medium"
      },
      "weight": 1
    },
    {
      "antecedent": {
        "humidity": "medium",
        "temperature": "medium"
      },
      "consequent": {
        "flow": "high"
      },
      "weight": 1
    },
    {
      "antecedent": {
        "humidity": "high",
        "temperature": "medium"
      },
      "consequent": {
        "flow": "high"
      },
      "weight": 1
    },
    {
      "antecedent": {
        "humidity": "low",
        "temperature": "high"
      },
      "consequent": {
        "flow": "low"
      },
      "weight": 1
    },
    {
      "antecedent": {
        "humidity": "medium",
        "temperature": "high"
      },
      "consequent": {
        "flow": "low"
      },
      "weight": 1
    },
    {
      "antecedent": {
        "humidity": "high",
        "temperature": "high"
      },
      "consequent": {
        "flow": "medium"
      },
      "weight": 1
    }
  ]
}`

const fuzzyModule = FuzzyModule.fromJSON(jsonDescriptor)

异常

如果给定的JSON字符串无效或描述不完整的模糊控制系统,则可能抛出异常。