首页 文章

我可以在AnyLogic拆分组件中将单个代理拆分为多个代理吗?

提问于
浏览
1

我've a question about the 1250974 component of AnyLogic PMI library. To better explain the case I will post a picture of a part of the scenario I'米建筑 .
AnyLogic circuit
.

在上图中,左侧的source元素生成“Requirement”类型的对象(它是从Agent类继承的自定义类) . 此类表示一个矩阵,其中包含每个客户“Ci”的每个产品“Pi”的要求(给出矩阵的示例):

Requirement Matrix

该矩阵可以被视为代理的集合,因为每一行都是与我的电路块的第一个相关的代理(逻辑上它包含有关从产品供应商订购的产品Pi的数量的信息)并且每列是与我的电路块的第二个相关的代理(逻辑上它包含客户Ci的销售预测) .

可能的是,在拆分块的“on at enter”事件中,构建一个脚本,该脚本首先迭代行并在“out”split的端口上发出每个行,然后迭代列并在“out-”上发出每个行 . 复制“分裂的端口 . 我将发布一个我正在考虑放入“on at enter”事件的脚本的伪代码:

matrix = (Requirement)agent;
Iterator<Object> reqIter = matrix.getRequirements(); //iterate the rows
while (reqIter.hasNext())
{
   Object current = reqIter.next();
   //PUSH current in the out port of the split
}

Iterator<Object> sellIter = matrix.getRequirements(); //iterate the columns
while (sellIter.hasNext())
{
   Object current = sellIter.next();
   //PUSH current in the out-copy port of the split
}

1 回答

  • 2

    我会在 nuove matrici 之后放 SinkExit 块 . 如果在生成代理后可以销毁初始代理矩阵,则使用 Sink ;如果初始代理应该保存并稍后以某种方式重用,则使用 Exit . Split 块可以删除 . 将两个 Enter 块连接到相应的后续队列,而不是块 .

    Sink\Exit 内部的 On Enter 动作执行代码 . 可以使用 enterBlockName.take(new MyAgent(args...)); 将生成的代理注入到相应的队列中

    例如,考虑到代码生成 Agent 类型的实例,它将是:

    matrix = (Requirement)agent;
    Iterator<Object> reqIter = matrix.getRequirements(); //iterate the rows
    while (reqIter.hasNext())
    {
       Object current = reqIter.next();
       enter.take( new MyAgent(current) ); //PUSH current in the top flow
    }
    
    Iterator<Object> sellIter = matrix.getRequirements(); //iterate the columns
    while (sellIter.hasNext())
    {
       Object current = sellIter.next();
       enter1.take( new MyAgent(current) );   //PUSH current in the bottom flow
    }
    

相关问题