AnyLogic风电场仿真实验时长设置与离线风机数量数据导出咨询
Guide to Setting 2-Week Simulation Duration and Exporting Offline Turbine Data in AnyLogic
Hey Simon, glad to hear you’ve got your wind farm model up and running using the official tutorials—great start! Let’s walk through how to adjust the simulation duration to 2 weeks and export the count of offline turbines during that period, step by step:
1. Set Simulation Duration to 2 Weeks
- Open your experiment (usually named
Mainor whatever you’ve called it) by double-clicking it in the Project view. - Navigate to the Time tab in the experiment’s properties panel.
- Look for the Simulation duration field. You can set this in a couple intuitive ways:
- If your model uses hours as the time unit: Enter
336(since 2 weeks = 2×7×24 hours). - For a more readable approach, use AnyLogic’s built-in time function: Type
weeks(2)—it’ll automatically convert to your model’s default time unit (just make sure your project’s time unit is set logically, e.g., hours or days, in Project Settings > Time).
- If your model uses hours as the time unit: Enter
- Click Apply to save the setting. Your simulation will now run for exactly 2 weeks.
2. Track and Export Offline Turbine Count Data
First, we need to track how many turbines are offline at any time, then export that data to a usable file.
Step 2.1: Track Offline Turbines in Real-Time
- In your main model agent (or the
Mainagent), create a collection to manage offline turbines:- Add a
Collection<Turbine>variable (replaceTurbinewith your actual wind turbine agent name) and name itofflineTurbines. - In your turbine agent’s code, when a turbine goes offline (e.g., when a fault is triggered), add:
main.offlineTurbines.add(this); - When the turbine comes back online (e.g., after maintenance completes), add:
main.offlineTurbines.remove(this); - To get the real-time offline count, you can directly use
offlineTurbines.size()whenever you need it—no extra variable required, though you can create anIntegervariableofflineTurbineCountand update it if that feels more straightforward.
- Add a
Step 2.2: Record Data at Regular Intervals
- Drag a
Datasetcomponent from the Analysis palette into yourMainagent, name itofflineTurbineDataset. - Add a Periodic Event component to log data at your desired frequency (e.g., every hour):
- Set the event’s Interval to
hours(1)(adjust to days, minutes, etc., based on how granular you want the data). - In the event’s Action field, add this code to log the current simulation time and offline turbine count:
offlineTurbineDataset.add(time(), main.offlineTurbines.size());
- Set the event’s Interval to
Step 2.3: Export the Data to a File
You can choose to export automatically when the simulation ends, or add a manual button for on-demand exports:
- Automatic Export on Simulation Stop:
- Open your experiment’s properties, go to the Actions tab, and find the On stop field.
- Add this code to save the dataset as a CSV file (it’ll save to your model’s root directory):
main.offlineTurbineDataset.writeCsv(new File("2week_offline_turbine_data.csv"));
- Manual Export Button:
- Drag a
Buttoncomponent into your model’s presentation area, set its text to "Export Offline Data". - In the button’s On click action, paste the same CSV export code above.
- Drag a
Step 2.4: Verify the Data
Run a short test simulation first (e.g., 1 day) to make sure:
- The offline count updates correctly when turbines fail or recover.
- The dataset records the right values at each interval.
- The CSV file generates properly with clear time and count columns.
内容的提问来源于stack exchange,提问作者Simon
相关产品推荐
相关产品推荐

