AnyLogic + Pypeline:在每次实验运行之前运行 Python 脚本

问题描述 投票:0回答:1

我想在每次运行 AnyLogic 实验之前运行一个外部 Python 脚本。我试着按照这里的解释 (https://www.anylogic.com/upload/pdf/q-and-a-with-writeups.pdf)。文档作者建议通过模拟页面中的变量来初始化PyCommunicator对象。当我运行模型时,我试图做到这一点,变量为空值。

为了了解我是否在 PyCommunicator 对象的构造函数的参数定义中犯了一些错误,我进入了主代理,在那里我从调色板中拖动了另一个 PyCommunicator 对象并通过属性面板进行了设置,然后我尝试了手动创建一个 PyCommunicator 对象,复制构造函数中已存在对象的完全相同的值。这里的代码:

//py is the PyCommunicator object created by drag and drop from Palette
//py2 is the manually created PyCommunicator object

System.out.println("Py object: "+py);
System.out.println("Enable: "+py.enable);
System.out.println("Load last config: "+py.loadLastWorkingConfig);
System.out.println("Python command type: "+py.pythonCommandType);
System.out.println("Python command: "+py.pythonCommand);
System.out.println("Python executable path: "+py.pythonExecPath);
System.out.println("Throw error: "+py.throwErrorOnFailedAttempt);
System.out.println("Redirect output: "+py.redirectPyOutput);

PyCommunicator py2 = new PyCommunicator(py.enable,py.loadLastWorkingConfig,py.pythonCommandType,py.pythonCommand,py.pythonExecPath,py.throwErrorOnFailedAttempt,py.redirectPyOutput);
System.out.println("Py2 object: "+py2);

同样在这种情况下,手动创建的对象为空。这是我在控制台收到的:

Py object: Python 3.11.0
C:\...\python.exe
Enable: true
Load last config: false
Python command type: PYTHON_PATH
Python command: null
Python executable path: C:\...\python.exe
Throw error: false
Redirect output: true
Py2 object: null

我做错了什么???

python simulation anylogic
1个回答
0
投票

第二个测试确实有效。看起来您没有将 Python 库导入模拟实验。将

import...
代码从 Main(在高级 Java 下)复制到您的模拟实验属性(同一部分)

© www.soinside.com 2019 - 2024. All rights reserved.