首页 理论 架构 工程 文档 白皮书 著作 研究 案例 下载 博客 关于 开始使用 →

第158章 Need与Goal类

第158章 Need与Goal类

158.1 提出背景

在个体认知工程中,仅仅具备Object、State、Relation、Scene和Knowledge,还不能形成完整的行为驱动结构。

对象可以回答:

当前存在什么?

状态可以回答:

当前是什么状态?

关系可以回答:

对象之间是什么关系?

场景可以回答:

当前处于什么整体环境?

知识可以回答:

系统已经知道什么?

但是,个体还需要解决一个更加重要的问题:

为什么要进行某一个行为,以及最终希望达到什么结果?

例如:

当前状态:
杯子是空的

系统如果只有State,只知道:

杯子 → 空

但是还不知道是否需要改变这个状态。

如果存在Need:

Need = 获得水

则系统产生Goal:

Goal = 让杯子中有水

然后建立Condition:

杯子存在
水存在
杯子可以被拿起

再根据Priority判断目标的重要程度,随后进入Goal State,最终产生Result。

因此形成:

Need
↓
Goal
↓
Condition
↓
Priority
↓
State
↓
Result

这一结构使个体认知从“描述当前世界”进一步进入“驱动目标行为”。


158.2 Need的概念定义

Need,中文称为“需要”,表示个体当前存在的某种需求状态。

Need不是行为。

Need也不是Goal。

Need回答的是:

个体为什么需要发生某种变化?

例如:

需要水
需要食物
需要移动
需要获取信息
需要解决问题
需要完成任务

这些都可以成为Need。

形式化表示:

N=(T,S,P)N=(T,S,P)

其中:

  • NN:Need;
  • TT:Need Type,需求类型;
  • SS:Need State,需求状态;
  • PP:Priority,需求优先级。

Need可以进一步产生Goal:

Need→GoalNeed \rightarrow Goal

因此:

Need
↓
产生目标方向
↓
Goal

158.3 Need与Goal的区别

Need和Goal必须严格区分。

Need表示:

希望解决什么需求。

Goal表示:

希望达到什么具体目标状态。

例如:

Need = 获得水

可以形成:

Goal = 杯子中存在水

再例如:

Need = 获取信息

可以形成:

Goal = 获得指定对象的信息

因此:

Need
↓
需求方向
↓
Goal
↓
目标状态

可以概括为:

Need = 为什么要改变
Goal = 希望改变成什么

158.4 Need Type

Need Type用于区分不同类型的需求。

例如:

survival
resource
information
task
maintenance
interaction
achievement

在工程中,可以根据具体系统建立自己的Need Type集合。

例如:

$needType = 'information';

表示当前需求属于信息获取类型。

也可以:

$needType = 'task';

表示当前需求属于任务完成类型。

因此:

Need
↓
Need Type
↓
确定需求属于哪一种结构

158.5 Need State

Need本身也具有State。

例如:

unknown
active
satisfied
unsatisfied
cancelled

其中:

  • unknown:需求状态未知;
  • active:需求当前存在;
  • satisfied:需求已经满足;
  • unsatisfied:需求尚未满足;
  • cancelled:需求已经取消。

例如:

Need = 获得水
State = active

执行相关行为以后:

Need = 获得水
State = satisfied

因此:

Need
↓
State
↓
决定需求是否仍然需要继续处理

158.6 Goal的概念定义

Goal,中文称为“目标”,表示个体希望通过认知和行为达到的目标状态。

Goal不是简单的愿望描述,而应该具有明确的目标条件和目标结果。

例如:

Goal = 杯子中有水

可以进一步表示:

Object = 杯子
Attribute / State = 有水

因此Goal可以定义为:

G=(T,C,S,R)G=(T,C,S,R)

其中:

  • GG:Goal;
  • TT:Goal Type,目标类型;
  • CC:Condition,目标成立条件;
  • SS:Goal State,目标当前状态;
  • RR:Result,目标结果。

基本结构为:

Goal
├── Type
├── Condition
├── Priority
├── State
└── Result

158.7 Goal Type

Goal Type用于定义目标的类型。

例如:

task
state_change
acquisition
maintenance
problem_solving
completion

例如:

Goal Type = state_change

表示目标是使某个状态发生改变。

例如:

当前:
杯子 = 空

目标:

杯子 = 有水

这就是状态变化型Goal。


158.8 Condition

Condition,中文称为“条件”,表示Goal成立或者执行所需要满足的条件。

例如:

Goal:
杯子中有水

需要:

杯子存在
水存在
可以取得水
杯子没有损坏

这些就是Condition。

因此:

Goal
↓
Conditions
↓
判断目标是否可以执行或成立

可以形式化为:

C={C1,C2,…,Cn}C=\{C_1,C_2,\ldots,C_n\}

如果:

C1∧C2∧⋯∧Cn=trueC_1\land C_2\land\cdots\land C_n=true

则目标的必要条件全部满足。


158.9 Condition与Goal的关系

Condition不是Goal本身。

例如:

Goal = 杯子中有水

而:

Condition 1 = 杯子存在
Condition 2 = 水存在
Condition 3 = 可以接触杯子

表示:

Conditions
↓
支持Goal执行或成立

因此:

Condition ≠ Goal

而是:

Condition
↓
Goal成立基础

158.10 Priority

Priority,中文称为“优先级”,表示Need或Goal在多个需求、多个目标同时存在时的处理顺序。

例如系统同时存在:

Goal A = 获取水
Goal B = 整理桌面
Goal C = 查看文件

系统必须确定先处理哪个Goal。

可以定义:

Goal A Priority = 10
Goal B Priority = 5
Goal C Priority = 3

数值越高表示优先级越高。

于是:

Goal A
↓
优先执行

Priority的作用是:

将多个Goal转换成可排序的执行顺序。


158.11 Priority的工程模型

可以定义:

P(Gi)=piP(G_i)=p_i

其中:

  • GiG_i:第i个Goal;
  • pip_i:该Goal的Priority。

例如:

P(G1)=10P(G_1)=10 P(G2)=5P(G_2)=5

则:

G1>G2G_1>G_2

表示:

Goal 1
↓
Goal 2

优先处理Goal 1。

因此:

Need
↓
多个Goal
↓
Priority
↓
Goal排序

158.12 State

Goal也必须具有独立State。

例如:

pending
active
achieved
failed
cancelled

其中:

  • pending:目标等待处理;
  • active:目标正在处理;
  • achieved:目标已经实现;
  • failed:目标执行失败;
  • cancelled:目标被取消。

于是:

Goal
↓
Goal State

能够表示目标当前所处阶段。


158.13 Goal State转换

Goal State可以形成状态转换:

pending
↓
active
↓
achieved

如果执行失败:

pending
↓
active
↓
failed

如果目标被取消:

pending
↓
cancelled

因此:

Stateold→Condition→StatenewState_{old}\rightarrow Condition\rightarrow State_{new}

例如:

Goal = 获取水
State = pending

条件满足后:

pending
↓
active

完成以后:

active
↓
achieved

158.14 Result

Result,中文称为“结果”,表示Goal执行以后产生的实际结果。

例如:

Goal:
让杯子中有水

执行完成以后:

Result:
杯子状态 = 有水

因此:

Goal
↓
Behavior
↓
Result

Result不能简单根据Goal文字判断,而应该来自实际运行后的状态变化。

例如目标:

Goal = 打开门

执行行为:

Behavior = 执行开门

实际结果:

Door State = open

因此:

Goal
↓
Action
↓
State Change
↓
Result

158.15 Goal与Result的区别

Goal表示:

希望发生什么。

Result表示:

实际发生了什么。

例如:

Goal = 杯子中有水

但是执行以后:

杯子仍然为空

那么:

Goal = 未达到
Result = 空杯

因此:

Goal ≠ Result

系统必须比较:

GoalStatevsResultStateGoalState \quad vs \quad ResultState

才能判断目标是否真正完成。


158.16 Goal完成判断

Goal是否完成,可以通过Condition和Result进行判断。

例如:

Goal:
杯子中有水

目标条件:

杯子中存在水 = true

执行以后读取实际状态:

杯子中存在水 = true

则:

Goal State = achieved

如果:

杯子中存在水 = false

则:

Goal State = failed

因此:

Goal
↓
Execution
↓
Result
↓
Compare
↓
Goal State

这是Goal工程运行的关键过程。


158.17 Need → Goal转换

一个Need可以产生一个或多个Goal。

例如:

Need = 获取水

可以产生:

Goal 1 = 找到水
Goal 2 = 获得容器
Goal 3 = 将水装入容器

形成:

Need
↓
Goal 1
Goal 2
Goal 3

多个Goal之间还可以存在顺序关系:

Goal 1
↓
Goal 2
↓
Goal 3

或者:

Goal 1 ─┐
        ├→ Goal 3
Goal 2 ─┘

因此Need负责提供需求方向,而Goal负责把需求转化为可执行目标。


158.18 Need与Priority

多个Need也可能同时存在。

例如:

Need A = 获取信息
Need B = 完成任务
Need C = 维护系统

系统需要对Need进行Priority排序。

因此:

Need
↓
Priority
↓
Need排序
↓
Goal选择

例如:

Need B Priority = 10
Need C Priority = 7
Need A Priority = 4

系统优先处理Need B。

这样Priority不仅可以作用于Goal,也可以作用于Need。


158.19 Need与Goal的PHP OOP设计

可以首先建立Need类:

class Need
{
    protected $type;
    protected $state;
    protected $priority;
    protected $goals = array();

    public function __construct($type, $priority = 0)
    {
        $this->type = $type;
        $this->priority = $priority;
        $this->state = 'active';
    }

    public function getType()
    {
        return $this->type;
    }

    public function getState()
    {
        return $this->state;
    }

    public function setState($state)
    {
        $this->state = $state;
    }

    public function getPriority()
    {
        return $this->priority;
    }

    public function addGoal(Goal $goal)
    {
        $this->goals[] = $goal;
    }

    public function getGoals()
    {
        return $this->goals;
    }
}

这里形成:

Need
├── Type
├── State
├── Priority
└── Goals

158.20 Goal类的PHP OOP设计

建立Goal类:

class Goal
{
    protected $type;
    protected $conditions = array();
    protected $priority;
    protected $state;
    protected $result;

    public function __construct($type, $priority = 0)
    {
        $this->type = $type;
        $this->priority = $priority;
        $this->state = 'pending';
        $this->result = null;
    }

    public function getType()
    {
        return $this->type;
    }

    public function addCondition($condition)
    {
        $this->conditions[] = $condition;
    }

    public function getConditions()
    {
        return $this->conditions;
    }

    public function getPriority()
    {
        return $this->priority;
    }

    public function setState($state)
    {
        $this->state = $state;
    }

    public function getState()
    {
        return $this->state;
    }

    public function setResult($result)
    {
        $this->result = $result;
    }

    public function getResult()
    {
        return $this->result;
    }
}

因此Goal已经具备:

Goal
├── Type
├── Conditions
├── Priority
├── State
└── Result

158.21 Goal条件判断

Goal可以增加条件检查方法:

public function checkConditions()
{
    foreach ($this->conditions as $condition) {
        if (!$condition) {
            return false;
        }
    }

    return true;
}

运行:

Goal
↓
Conditions
↓
checkConditions()
↓
true / false

如果条件全部满足:

pending
↓
active

否则:

pending
↓
等待

这样Goal具备基本运行能力。


158.22 Goal执行后的Result

执行过程不应该直接把Goal标记为完成。

必须获得实际Result。

例如:

$result = array(
    'state' => 'water_present',
    'success' => true
);

$goal->setResult($result);

然后根据Result判断:

if ($result['success']) {
    $goal->setState('achieved');
} else {
    $goal->setState('failed');
}

完整过程:

Goal
↓
Condition
↓
Execution
↓
Result
↓
Success / Failure
↓
Goal State

这保证Goal的完成状态来自实际结果,而不是程序预先假定。


158.23 Need—Goal运行模型

Need和Goal可以形成完整运行链:

Need
↓
Need State
↓
Need Priority
↓
Goal Creation
↓
Goal Priority
↓
Goal Conditions
↓
Goal State
↓
Behavior
↓
Result
↓
Goal State Update
↓
Need State Update

例如:

Need = 获取水
↓
State = active
↓
Priority = 10
↓
Goal = 杯子中有水
↓
检查Conditions
↓
Goal = active
↓
执行行为
↓
Result = 杯子中有水
↓
Goal = achieved
↓
Need = satisfied

这样就形成需求到结果的完整闭环。


158.24 Need与Goal的状态闭环

Need和Goal之间存在状态依赖。

当Goal未完成:

Goal State = pending / active

则:

Need State = active

当Goal完成:

Goal State = achieved

则:

Need State = satisfied

因此:

Goal State
↓
Need State

可以形成:

Goalachieved→NeedsatisfiedGoal_{achieved}\rightarrow Need_{satisfied}

如果Goal失败:

Goalfailed→NeedactiveGoal_{failed}\rightarrow Need_{active}

系统可以重新生成新的Goal。

例如:

Goal A
↓
failed
↓
Need仍然active
↓
重新生成Goal B

这形成目标调整机制。


158.25 Priority与Goal选择

如果一个Need生成多个Goal,则可以通过Priority进行选择。

例如:

Goal A = 找到水
Priority = 10

Goal B = 找到杯子
Priority = 8

Goal C = 找到桌子
Priority = 5

排序后:

Goal A
↓
Goal B
↓
Goal C

系统首先处理Goal A。

因此:

Goals
↓
Priority Calculation
↓
Sorting
↓
Selected Goal

Priority成为Goal管理的重要控制变量。


158.26 Goal与Scene

Goal不能脱离Scene。

例如:

Goal = 拿起杯子

当前Scene:

人
杯子
桌子

Scene Relations:

杯子 → 位于 → 桌子

Scene Conditions:

人可以接触杯子

只有在当前Scene满足相应条件时,Goal才具有执行基础。

因此:

Scene
↓
Scene Conditions
↓
Goal Conditions
↓
Goal

Goal实际上是在当前场景结构中运行的。


158.27 Goal与Knowledge

Knowledge为Goal提供目标判断所需要的结构信息。

例如系统已有Knowledge:

杯子位于桌子

又有Goal:

拿起杯子

系统可以通过Knowledge获得:

杯子在哪里

然后确定执行条件。

因此:

Knowledge
↓
Condition
↓
Goal
↓
Method
↓
Behavior

Knowledge并不直接等于Goal,但可以为Goal执行提供事实基础。


158.28 Goal与State

Goal本质上描述的是:

希望某个状态发生。

例如当前状态:

杯子 = empty

目标状态:

杯子 = filled

因此:

Statecurrent→Goal→StatetargetState_{current}\rightarrow Goal\rightarrow State_{target}

例如:

Current State
杯子 = 空
        ↓
Goal
杯子 = 有水
        ↓
Behavior
        ↓
New State
杯子 = 有水

所以Goal是连接“当前状态”和“目标状态”的重要对象。


158.29 Goal与Result形成验证闭环

Goal真正完成必须经过Result验证。

完整过程:

Current State
↓
Goal
↓
Condition
↓
Method
↓
Behavior
↓
Result
↓
Compare
↓
Goal State

如果:

Result = Goal

则:

Goal State = achieved

如果:

Result ≠ Goal

则:

Goal State = failed

或者重新进入:

active

因此:

Goal→Execution→Result→VerificationGoal \rightarrow Execution \rightarrow Result \rightarrow Verification

构成目标闭环。


158.30 Need与Goal在Individual中的位置

Individual可以拥有多个Need和Goal。

因此Individual结构进一步扩展为:

Individual
├── Identity
├── State
├── Objects
├── Relations
├── Knowledge
├── Needs
├── Goals
├── Capabilities
├── Methods
└── Behaviors

其中Need和Goal形成行为驱动部分:

Need
↓
Goal
↓
Method
↓
Behavior
↓
Result

而前面的认知结构提供运行基础:

Objects
↓
Relations
↓
Scene
↓
Knowledge
↓
Conditions

最终形成:

Knowledge
+
Scene
+
Need
+
Goal
↓
Condition
↓
Method
↓
Behavior
↓
Result

158.31 Need与Goal的完整工程模型

综合本章,可以建立:

Need=(Type,Priority,State,Goals)Need=(Type,Priority,State,Goals)

以及:

Goal=(Type,Condition,Priority,State,Result)Goal=(Type,Condition,Priority,State,Result)

完整结构为:

Need
├── Need Type
├── Priority
├── Need State
└── Goals
    └── Goal
        ├── Goal Type
        ├── Conditions
        ├── Priority
        ├── Goal State
        └── Result

因此形成明确的对象组合关系:

Individual
↓
Need
↓
Goal
↓
Condition
↓
State
↓
Result

158.32 Need—Goal认知运行闭环

最终可以建立完整运行模型:

Current State
↓
Need
↓
Goal
↓
Priority
↓
Condition
↓
Goal State
↓
Method
↓
Behavior
↓
Result
↓
Result Verification
↓
Goal State Update
↓
Need State Update
↓
Current State Update

例如:

当前:
杯子为空

产生:

Need:
获得水

产生:

Goal:
杯子中有水

判断:

Condition:
水存在
杯子可用

执行:

Behavior:
将水加入杯子

产生:

Result:
杯子中存在水

验证:

Result = Goal

于是:

Goal State = achieved
Need State = satisfied

最终:

Current State
杯子为空
↓
Need
获得水
↓
Goal
杯子中有水
↓
Condition
满足
↓
Behavior
执行
↓
Result
杯子中有水
↓
Goal
achieved
↓
Need
satisfied
↓
New State
杯子有水

158.33 PHP OOP工程结构

在实际PHP工程中,可以将相关对象进一步分离:

Need.php
Goal.php
Condition.php
GoalState.php
Result.php
PriorityManager.php
NeedManager.php
GoalManager.php

形成:

Individual
    ↓
NeedManager
    ↓
Need
    ↓
GoalManager
    ↓
Goal
    ├── Condition
    ├── Priority
    ├── State
    └── Result

这种结构能够避免把所有需求、目标、条件和结果逻辑全部堆积在Individual类中。


158.34 NeedManager

可以建立NeedManager:

class NeedManager
{
    protected $needs = array();

    public function addNeed(Need $need)
    {
        $this->needs[] = $need;
    }

    public function getNeeds()
    {
        return $this->needs;
    }

    public function getActiveNeeds()
    {
        $result = array();

        foreach ($this->needs as $need) {
            if ($need->getState() === 'active') {
                $result[] = $need;
            }
        }

        return $result;
    }
}

这样系统能够集中管理多个Need。


158.35 GoalManager

GoalManager负责Goal集合管理:

class GoalManager
{
    protected $goals = array();

    public function addGoal(Goal $goal)
    {
        $this->goals[] = $goal;
    }

    public function getGoals()
    {
        return $this->goals;
    }

    public function getActiveGoals()
    {
        $result = array();

        foreach ($this->goals as $goal) {
            if ($goal->getState() === 'active') {
                $result[] = $goal;
            }
        }

        return $result;
    }
}

进一步可以增加Priority排序。


158.36 PriorityManager

PriorityManager负责对Need或Goal进行排序。

例如:

class PriorityManager
{
    public function sortGoals(array $goals)
    {
        usort($goals, array($this, 'comparePriority'));

        return $goals;
    }

    protected function comparePriority($a, $b)
    {
        if ($a->getPriority() == $b->getPriority()) {
            return 0;
        }

        return ($a->getPriority() > $b->getPriority()) ? -1 : 1;
    }
}

这样:

Goals
↓
PriorityManager
↓
Priority排序
↓
Highest Priority Goal

成为实际可执行的工程过程。


158.37 本章总结

Need与Goal类建立了ICAI中的需求—目标工程结构。

Need回答:

为什么需要发生变化?

Goal回答:

希望达到什么状态?

Condition回答:

在什么条件下可以执行或成立?

Priority回答:

多个需求或目标同时存在时先处理什么?

State回答:

当前需求或目标处于什么阶段?

Result回答:

执行以后实际发生了什么?

因此形成:

Need→Goal→Condition→Execution→ResultNeed\rightarrow Goal\rightarrow Condition\rightarrow Execution\rightarrow Result

并通过State形成闭环:

Need→Goal→State→Result→StateNeed \rightarrow Goal \rightarrow State \rightarrow Result \rightarrow State

完整工程结构为:

Need
├── Type
├── Priority
├── State
└── Goals
    ↓
Goal
├── Type
├── Conditions
├── Priority
├── State
└── Result

最终形成ICAI的目标驱动运行链:

Current State
→ Need
→ Goal
→ Priority
→ Condition
→ Method
→ Behavior
→ Result
→ Verification
→ Goal State
→ Need State
→ New State

由此,ICAI的对象工程开始从前面的:

Object
→ Attribute
→ State
→ Relation
→ Scene
→ Knowledge

进一步进入:

Knowledge
+
Scene
+
Need
↓
Goal
↓
Condition
↓
Priority
↓
Method
↓
Behavior
↓
Result

这一步的核心变化,是系统不再只是“知道对象和场景是什么”,而开始建立:

基于当前状态产生需求、由需求形成目标、依据条件选择目标、按照优先级确定目标顺序、通过行为产生实际结果,并根据结果更新目标与需求状态的闭环机制。

Leave a Reply

Your email address will not be published. Required fields are marked *