You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

AnyLogic中多物料按指定顺序进入工位及传送带的实现方法咨询

Hey there! Let's work through your two AnyLogic sorting requirements step by step. I get why using just agent.priority didn't cut it—your needs involve multiple independent sequencing rules, which global priority can't handle on its own. Here's how to fix it:

1. Initial Requirement: Feed 3 Workstations in Specific Sequences

Your goal: Randomly generated materials (types 1, 2, 3) need to reach 3 workstations in distinct repeating orders:

  • Station 1: 1 → 2 → 3 → 1...
  • Station 2: 2 → 3 → 1 → 2...
  • Station 3: 3 → 1 → 2 → 3...

Solution: Use Pull Blocks + State Tracking

This setup lets each workstation actively pull the exact material type it needs next, regardless of generation order:

  1. Add a type identifier to your material agent:
    • Open your agent's properties, add an int parameter named type, and set it to 1, 2, or 3 when generating agents (configure this in your Source block's "On create" action).
  2. Create a central queue:
    • Add a Queue block named mainQueue—all randomly generated materials first enter this queue.
  3. Add state variables for each workstation:
    • In your main agent's properties, create three int variables:
      • nextTypeStation1 = 1 (Station 1 starts needing type 1)
      • nextTypeStation2 = 2 (Station 2 starts needing type 2)
      • nextTypeStation3 = 3 (Station 3 starts needing type 3)
  4. Add Pull blocks for each workstation:
    • Create three Pull blocks (pullStation1, pullStation2, pullStation3), each linked to mainQueue.
    • Configure each pull block's Pull Condition:
      • For pullStation1: agent.type == nextTypeStation1
      • For pullStation2: agent.type == nextTypeStation2
      • For pullStation3: agent.type == nextTypeStation3
    • Add an On Pulled action to each pull block to update the next needed type:
      • pullStation1 action:
        nextTypeStation1 = nextTypeStation1 == 3 ? 1 : nextTypeStation1 + 1;
        
      • pullStation2 action:
        nextTypeStation2 = nextTypeStation2 == 3 ? 1 : nextTypeStation2 + 1;
        
      • pullStation3 action:
        nextTypeStation3 = nextTypeStation3 == 3 ? 1 : nextTypeStation3 + 1;
        
  5. Link to workstations:
    • Connect each Pull block to its corresponding workstation (e.g., a Process block).

This way, each workstation will only receive materials in your exact desired order—even if materials are generated randomly.

2. Supplementary Requirement: Sequential Merging into Final Conveyor

Your goal: Three Sources generating MyAgent1, MyAgent2, MyAgent3 must enter the final conveyor in the repeating order MyAgent2 → MyAgent1 → MyAgent3, one at a time.

Solution: Queue Blocks + Coordination Event

This ensures strict sequential entry, even if agents are generated at different speeds:

  1. Add a type identifier to your agents:
    • If MyAgent1/2/3 share a parent agent, add an int parameter agentType (set 1 for MyAgent1, 2 for MyAgent2, 3 for MyAgent3). If not, you can use agent instanceof MyAgent2 for checks, but a type parameter is cleaner.
  2. Create per-agent queues:
    • Add three Queue blocks (queueAgent1, queueAgent2, queueAgent3), each linked to its corresponding Source. Set each queue's Release Condition to false—we'll manually release agents via code.
  3. Add a state variable for sequencing:
    • In your main agent, create an int variable nextExpectedAgent = 2 (start with MyAgent2).
  4. Add a coordination event:
    • Add an Event block named triggerRelease. Set its Action to:
      // Release the next expected agent if it's available
      if (nextExpectedAgent == 2 && !queueAgent2.isEmpty()) {
          queueAgent2.release(queueAgent2.getFirst());
      } else if (nextExpectedAgent == 1 && !queueAgent1.isEmpty()) {
          queueAgent1.release(queueAgent1.getFirst());
      } else if (nextExpectedAgent == 3 && !queueAgent3.isEmpty()) {
          queueAgent3.release(queueAgent3.getFirst());
      }
      
      // Update the next expected agent (cycle back to 2 after 3)
      nextExpectedAgent = switch(nextExpectedAgent) {
          case 2 -> 1;
          case 1 -> 3;
          case 3 -> 2;
          default -> 2;
      };
      
  5. Link to final conveyor and auto-trigger the event:
    • Connect all three queues to your final conveyor.
    • Add an On Entry action to the final conveyor:
      triggerRelease.restart(); // Trigger next release after current agent enters
      
    • In your main agent's On startup action, add triggerRelease.restart(); to start the sequence.

This setup will wait for the required agent to be available, release it to the conveyor, then immediately prepare for the next in order—ensuring strict one-at-a-time sequential entry.


内容的提问来源于stack exchange,提问作者Afif

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.29 19:12:31