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

AnyLogic供应链配送仿真中车辆Agent非运行时间测量方法咨询

Tracking Idle Time for Delivery Vehicles in AnyLogic

Hey there! Let's break down how to track that idle time (non-movement time between tasks) for your 3 delivery vehicles in AnyLogic—both per-vehicle metrics and the fleet average. I’ll cover two practical approaches based on your initial idea and the TimeMeasurement tools you mentioned.


Approach 1: Use AnyLogic's TimeMeasurement API

This is the most straightforward way to directly track idle periods, as it handles start/stop timing automatically.

Step 1: Add a TimeMeasurement tracker to your Vehicle Agent

  1. Open your Vehicle Agent's Variables panel.
  2. Add a new variable with:
    • Name: idleTimeTracker
    • Type: TimeMeasurement
    • Initial value: new TimeMeasurement() (or initialize it in the agent's On Startup action: idleTimeTracker = new TimeMeasurement();)

Step 2: Trigger Start/Stop Timing

You need to tell the tracker when the vehicle enters idle mode and when it exits to start a new task:

  • Start idle timing: When the vehicle finishes a delivery and has no next task. For example, in the On Arrival action of your moveTo (or transport) module (after unloading):
    idleTimeTracker.start();
    
  • Stop idle timing: Right before the vehicle starts moving to a new customer. For example, in the code block where you assign a new delivery task:
    idleTimeTracker.stop();
    // Then trigger your movement code, e.g., moveTo(nextCustomer);
    
    Pro tip: If your vehicle starts idle at simulation launch, add idleTimeTracker.start(); to the Vehicle Agent's On Startup action.

Step 3: Collect and Analyze Data

Per-Vehicle Idle Time

At any point (e.g., simulation end), you can get a single vehicle's total idle time with:

// Replace 'myVehicle' with your specific vehicle agent reference
double vehicleIdleTime = myVehicle.idleTimeTracker.getTotalTime();

This returns time in your model's configured unit (e.g., hours, minutes—check your model settings!).

Fleet Average Idle Time

In your main agent (the one holding the fleet), add code to aggregate data when the simulation ends (put this in the main agent's On Simulation End action):

// Store all idle times in a list
List<Double> allVehicleIdleTimes = new ArrayList<>();
for (Vehicle vehicle : yourVehiclePopulation) { // Replace with your fleet population reference
    allVehicleIdleTimes.add(vehicle.idleTimeTracker.getTotalTime());
}

// Calculate average
double averageIdleTime = 0;
if (!allVehicleIdleTimes.isEmpty()) {
    averageIdleTime = allVehicleIdleTimes.stream()
        .mapToDouble(Double::doubleValue)
        .average()
        .orElse(0);
}
// You can log this or display it in a Text component
traceln("Average fleet idle time: " + averageIdleTime);

Approach 2: Calculate via Total Simulation Time - Total Movement Time

If you prefer your initial idea, this method works by subtracting the vehicle's total travel time from the total simulation time. Note: Adjust this if you need to exclude non-idle, non-movement time (like loading/unloading) — we’ll cover that too.

Step 1: Track Total Movement Time per Vehicle

  1. In your Vehicle Agent's Variables panel, add:

    • Name: totalTravelTime
    • Type: double
    • Initial value: 0
    • Optional: moveStartTime (Type: double) to track when each movement starts.
  2. Log movement start/end times:

    • When starting a movement: In the code block before triggering moveTo/transport, add:
      moveStartTime = time();
      
    • When finishing a movement: In the On Arrival action of the movement module, add:
      totalTravelTime += time() - moveStartTime;
      

Step 2: Calculate Idle Time

Per-Vehicle Idle Time

  • If "non-movement time" = all time not spent moving (including loading/unloading):
    double totalIdleTime = time() - totalTravelTime;
    
  • If you want true idle time (excluding task work like loading/unloading):
    Add another variable totalTaskTime (double, initial 0) to track loading/unloading duration. Update it during those tasks, then:
    double trueIdleTime = time() - totalTravelTime - totalTaskTime;
    

Fleet Average Idle Time

Similar to Approach 1, aggregate data in your main agent's On Simulation End action:

double totalFleetIdleTime = 0;
for (Vehicle vehicle : yourVehiclePopulation) {
    totalFleetIdleTime += (time() - vehicle.totalTravelTime);
    // Use vehicle.trueIdleTime if you calculated true idle time
}
double averageIdleTime = totalFleetIdleTime / yourVehiclePopulation.size();
traceln("Average fleet idle time: " + averageIdleTime);

Key Tips for Implementation

  • Time Unit Consistency: Always confirm your model's time unit (found in Model Settings) to avoid misinterpreting values (e.g., a value of 2 could mean 2 hours or 2 minutes).
  • Real-Time Visualization: Add a Text component or Bar Chart to your main agent’s canvas, binding it to the idle time variables to monitor progress during simulation.
  • Edge Cases: Handle vehicles that never receive tasks (their idle time should equal total simulation time) by ensuring your timing logic starts correctly on agent startup.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.29 14:22:35