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

Anylogic停车场景Delay块:如何获取空车位状态函数值?

Solution for Checking Free Parking Spots with AnyLogic Delay & Queue

Got it, let’s break down why you’re seeing that "undefined method" error and fix your parking spot check. The core issue here is that nFree() and spaceIndex() are only available for AnyLogic’s Storage component—they don’t exist for the Queue component you’re using.

Depending on how you’ve structured your parking simulation (Delay + Queue), here are the correct approaches to get free spot status:

1. If you’re using a Delay block with capacity as your parking lot (Queue for waiting vehicles)

This is the standard setup: The Delay block represents your parking area (set its capacity to your total number of spots), and the Queue holds vehicles waiting for an open spot.

  • To get the number of free spots: Use the Delay block’s getRemainingCapacity() method
  • To check if there’s at least one free spot: Use yourDelayBlockName.getRemainingCapacity() > 0

Example code you can use in functions, triggers, or displays:

// Check if any parking spots are free
boolean hasFreeSpot = parkingDelay.getRemainingCapacity() > 0;
// Get exact count of free spots
int freeSpots = parkingDelay.getRemainingCapacity();

2. If you’re using a Queue component as your parking lot

If you’ve set up a Queue with a fixed capacity (equal to total parking spots) to hold parked vehicles directly:

  • Total spots = yourQueueName.getCapacity()
  • Occupied spots = yourQueueName.size()
  • Free spots = yourQueueName.getCapacity() - yourQueueName.size()
  • Check for free spots = yourQueueName.size() < yourQueueName.getCapacity()

Example snippet:

int freeParkingSpots = parkingQueue.getCapacity() - parkingQueue.size();
boolean isSpotAvailable = freeParkingSpots > 0;

Pro Tip

Whenever you’re unsure about a component’s available methods, right-click it in your model, select Help, and you’ll get a full list of all supported functions and their descriptions. It’s a quick way to avoid these mix-ups!

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.14 08:41:30