在我的任意逻辑项目中,我从内部数据库查询数据集。我要查询的表具有以下结构:
Name: product_innovation_level
--------------------------------
ID|level_customer|level_employee|
--|--------------|--------------|
1| 10| 14|我能找到的唯一示例是使用Tuple类,如下所示。它可以工作,但我必须手动从项目中提取所需的值,这让人觉得很笨拙。
Tuple innovationLevel = selectFrom(product_innovation_level).
where(product_innovation_level.id.eq(1)).
firstResult(product_innovation_level.level_customer, product_innovation_level.level_employee);
double ngEmployee = innovationLevel.get(product_innovation_level.level_employee);
double ngCustomer = innovationLevel.get(product_innovation_level.level_customer);是否有更好的方法直接将值选择到模型类中?我在找这样的东西:
xxx innovationLevel = selectFrom(product_innovation_level).
where(product_innovation_level.id.eq(1)).
firstResult(xxx);我应该用什么级别来做xxx?我找到了一个自动创建的类Qproduct_innovation_level,但是我没有找到一种方法来访问这个数据集的值。
Qproduct_innovation_level innovationLevel = selectFrom(product_innovation_level).
where(product_innovation_level.id.eq(1)).
firstResult(product_innovation_level);
int i = innovationLevel.level_customer.intValue();
Error: Type mismatch: cannot convert from NumberExpression<Integer> to int我试图自己编写一个模型类,但是在这里我得到了类型错配错误(不能从Qproduct_innovation_level转换到InnovationLevelModel)。
发布于 2019-07-01 02:37:33
好吧,我的回答可能有点荒谬,但也许这是你想要的.
使用以下构造函数和变量创建一个类:
public class MyClass implements Serializable {
public double ngEmployee;
public double ngCustomer;
/**
* Default constructor
*/
public MyClass(Tuple innovationLevel) {
this.ngEmployee = innovationLevel.get(product_innovation_level.level_employee);
this.ngCustomer = innovationLevel.get(product_innovation_level.level_customer);
}
}然后您可以创建这个类的一个实例,如下所示:
MyClass mc=new MyClass(selectFrom(product_innovation_level).
where(product_innovation_level.id.eq(1)).
firstResult(product_innovation_level.level_customer, product_innovation_level.level_employee));魔法..。现在您可以使用mc.ngEmployee和mc.ngCustomer访问变量。
发布于 2019-07-01 18:18:55
这是使用AnyLogic从数据库表中可视化地自动创建代理种群(包括代理类型定义)的地方。
使用Agent向导(从代理面板的顶部):通过使用数据库表创建新类型的填充,AnyLogic将
因此,在您的示例中,您可以拥有一个代理类型的总体innovationLevels ( InnovationLevel ),其中该代理具有参数。
id (int型)levelCustomer (int型)levelEmployee (int型)(向导将自动定义此代理类型及其在数据库表驱动的人口中的使用)。
请参阅帮助中的AnyLogic帮助>基于代理的建模>创建基于DB数据的新代理填充。
如果您的If是连续的(例如,1,2,3,.)然后,您还可以通过其在列表中的位置访问给定的创新级别(例如,列表中的第二个可能是id 2的innovationLevels(1) )。如果您希望能够通过id“随机访问”创新级别(如果ID不是顺序的话),您还可以创建ID到InnovationLevel的映射(使用集合)。
其他代理可以根据需要包括对InnovationLevel实例的引用。
https://stackoverflow.com/questions/56818912
复制相似问题