如何将从 AnyLogic 模型数据库中检索到的字符串表示为变量名?

How to represent a string retrieved from the AnyLogic model database as a variable name?

我正在构建大型存储设施(如集装箱码头)的 AnyLogic 模型,该设施在多个区域有数百个存储位置。存储的物品堆叠在每个物品的顶部,需要以后进先出的方式取回。该模型在启动时将当前库存加载为代理群体,包括标识每个代理位置的参数。

该模型还有数据库 table,它将每个位置的唯一名称(字符串值)与代表模型中位置的队列对象的名称联系起来.在启动时,模型需要创建一个集合 (LinkedHashMap),它将位置名称 (Key) (String) 与其队列名称 (Value) 进行映射。但是,由于数据库将值存储为字符串,因此我需要将从数据库查询 (String) 中检索到的队列名称值转换为对象 variable name.

这是违规函数的示例。您会注意到 'for' 循环的第二行尝试使用数据库中“loc_q”列的值(字符串)填充 q 变量(队列)。当然,这会导致类型不匹配错误。如何将字符串值转换为队列名称?

 Queue q = null;
 String str = null;

 List<Tuple> s = selectFrom(storage_locations)
    .orderBy(storage_locations.loc_id.asc())
    .list(storage_locations.loc_id, storage_locations.loc_q);

 for (Tuple sl : s) {
     str = sl.get(storage_locations.loc_id);
     q = sl.get(storage_locations.loc_q);
     colMapQ.put(str, q);
 }

我承认我不是 Java 大师,所以我可能错过了这里的基本步骤。我花了 3 天时间搜索堆栈溢出和 gitHub,但没有取得太大成功。有没有人遇到过这个问题?非常感谢你的帮助。

你不能。您需要自己创建一个映射函数,该函数 returns 匹配给定字符串名称的 Queue 对象。

Select 模型中的所有队列对象,right-click 一个并从它们创建一个集合。

现在,编写一个循环遍历所有条目和 returns 与您的输入同名的 Queue 元素的函数,例如

for (Queue currentQueue : collectionOfAllQueues) {
    if (currentQueue.getName().equals(requiredDbaseName){
        return currentQueue;
    }
}