首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AnyLogic:从内部数据库中选择数据集的正确方法

AnyLogic:从内部数据库中选择数据集的正确方法
EN

Stack Overflow用户
提问于 2019-06-29 15:52:42
回答 2查看 515关注 0票数 1

在我的任意逻辑项目中,我从内部数据库查询数据集。我要查询的表具有以下结构:

代码语言:javascript
复制
Name: product_innovation_level
--------------------------------
ID|level_customer|level_employee|
--|--------------|--------------|
 1|            10|            14|

我能找到的唯一示例是使用Tuple类,如下所示。它可以工作,但我必须手动从项目中提取所需的值,这让人觉得很笨拙。

代码语言:javascript
复制
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);

是否有更好的方法直接将值选择到模型类中?我在找这样的东西:

代码语言:javascript
复制
xxx innovationLevel = selectFrom(product_innovation_level).
                                  where(product_innovation_level.id.eq(1)).
                                  firstResult(xxx);

我应该用什么级别来做xxx?我找到了一个自动创建的类Qproduct_innovation_level,但是我没有找到一种方法来访问这个数据集的值。

代码语言:javascript
复制
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)。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-07-01 02:37:33

好吧,我的回答可能有点荒谬,但也许这是你想要的.

使用以下构造函数和变量创建一个类:

代码语言:javascript
复制
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);
    }

}

然后您可以创建这个类的一个实例,如下所示:

代码语言:javascript
复制
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.ngEmployeemc.ngCustomer访问变量。

票数 0
EN

Stack Overflow用户

发布于 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实例的引用。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56818912

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档