在我的任何logic-project i从内部数据库中查询数据集。我要查询的表具有以下结构:
Name: product_innovation_level
--------------------------------
ID|level_customer|level_employee|
--|--------------|--------------|
1| 10| 14|
我能找到的唯一示例使用元组级,如下所示。它有效,但是我必须手动从项目中提取所需值感到非常笨拙。
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(。
好吧,我的回答可能有点荒谬,但也许这是您想要的...
创建一个具有以下构造函数和变量的类:
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
这是您从数据库表中使用AnyLogic对代理群体(包括代理类型定义(的视觉定义的自动创建的地方。
使用Agent
向导(从代理调色板的顶部(:通过创建新类型的种群,使用数据库表,任何logic will will
- 创建一个具有参数的新代理类型,该类型与表中的列匹配 中的列
- 创建该代理类型的总体,每行实例(其他变体(,将列映射到适当的代理参数
因此,在您的情况下,您可以拥有代理类型InnovationLevel
的 innovationLevels
,该代理具有参数
-
id
(类型int
( -
levelCustomer
(类型int
( -
levelEmployee
(类型int
(
(向导将自动定义该代理类型及其在数据库桌驱动的人群中的使用(。
请参阅 Anylogic帮助>基于代理的建模>在帮助中基于DB数据创建新的代理总体。
如果您的ID是顺序的(例如,1,2,3,...(,然后您也可以通过其在列表中的位置访问给定的创新级别(例如,列表中第二个可能是ID的innovationLevels(1)
2(。您还可以执行诸如创建ID的地图(使用集合(为InnovationLevel
的事情,如果您想通过ID"随机访问"创新级别(如果ID不是顺序的(。
其他代理可以根据需要包括对InnovationLevel
实例的引用。