Author:赵志乾
Date:2024-06-17
Declaration:All Right Reserved!!!
1. 类图
2. 原理解析
2.1 核心函数
函数 | 功能 |
---|---|
FlowchartBlock(Engine engine ,Agent owner, AgentList population ) | 构造函数,入参设定引擎、owner以及所在的群 |
boolean isInsideFlowchartBlock() | 判定该Block是否为内部Block,即是否是其他Block的组成部分 |
FlowchartBlock getFlowchartBlockRepresentative() | 获取该Block的顶层Block,如果该Block非内部Block,返回Block本身 |
Agent remove(Agent agent, FlowchartBlock receiver) | 从Block中移除并返回指定Agent,如果receiver不为空,则receiver将持有指定Agent |
Agent suspend(Agent agent) | 让Block挂起对指定Agent的处理(幂等);如果指定Agent本就处于挂起状态或不被该Block持有,则返回null |
Agent resume(Agent agent) | 让Block重新恢复对指定Agent的处理(幂等);如果指定Agent存在该Block内且之前处于挂起状态则返回指定Agent,否则返回null |
2.2 代码解析
由于Anylogic内核做过代码混淆,以下代码为二次加工后的逻辑;
//*************************构造函数******************************
public FlowchartBlock(Engine engine, Agent owner, AgentList<?> population) {
// 调用父类Agent的构造函数,入参分别为:引擎、所属owner、所属群
super(engine, owner, population);
}
//*************************层级函数******************************
// 判定该Block是否为内部Block
public boolean isInsideFlowchartBlock() {
// 判定标准:顶层Block是否为自身
return this.getFlowchartBlockRepresentative() != this;
}
// 获取顶层Block
public FlowchartBlock getFlowchartBlockRepresentative() {
// 如果owner是Block,则递归地获取顶层Block
Agent owner= this.getOwner();
return owner instanceof FlowchartBlock ? ((FlowchartBlock)owner).getFlowchartBlockRepresentative() : this;
}
//*************************内容操控函数***************************
// 从Block中移除指定Agent,如果receiver不为空,则移除的agent将有receiver持有
public Agent remove(Agent agent, FlowchartBlock receiver) {
// 默认不支持,需由子类覆写
throw this.error("not support");
}
//*************************处理控制函数***************************
// 挂起
public Agent suspend(Agent agent) {
// 默认不支持,需要子类覆写
throw this.error("not support");
}
// 恢复
public Agent resume(Agent agent) {
// 默认不支持, 需要子类覆写
throw this.error("not support");
}
3 应用场景
该类为所有流程处理块的基类,定义标准函数;