在 Anylogic(Java、SQL)上查找连续数据的最快方法是什么 [英] What is the fastest way to look up continuous data on Anylogic (Java, SQL)

查看:36
本文介绍了在 Anylogic(Java、SQL)上查找连续数据的最快方法是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含 900,000 行的数据库表.此表包含功率、制动力、火车行程的速度记录作为距离的函数.

I have a database table of 900,000 rows. This table contains power, braking power, speed log from train trips as a function of distance.

  1. 起源
  2. 目的地
  3. 从出发点行驶的距离
  4. 以 MW 为单位的功率读数
  5. 以 MW 为单位的制动力读数
  6. KPH 速读

有 13 个不同的目的地,出境和入境旅行有不同的数据集,因此有 26 个数据集.

There are 13 different destinations and outbound and inbound trips have different sets of data so there are 26 datasets.

目标是确定给定距离的功率,用于特定的原点和组合.目的地.

The aim is to determine the power at a given distance for a particular combination of origin & destination.

我尝试了两种不同的方法.这些正在工作,但速度非常慢(大约每小时 6 秒).鉴于我需要长时间运行此模拟,可能长达 25 年).这将花费我 350 多个小时来运行它.

I have attempted two different methods. These are working but are extremely slow (roughly 6 seconds per hour). Given that I need to run this simulation for long periods of time, potentially up to 25 years). This would take me over 350+ hours to run this.

方法一)使用 selectFrom 获取要插入的行进距离前后的数据数组.

selectFrom(table).where(table.origin.eq(origin), table.destination.eq(destination), table.power.between(currentDistance-1,currentDistance+1) ).ArrayOfDoubles(table.power)

这将返回一个包含功率读数的大约 <20 个元素的数组.然后,使用数组的第一个和最后一个元素进行插值以获得给定距离处的功率.

This returns an array of roughly <20 elements containing the power readings. then, interpolate using the first and last element of the array to obtain power at given distance.

方法二)创建代理实例时向 TableFunction 提供参数和值数据

tableFunction.setArgumentsAndValues(distanceArray,powerArray);

此方法也有效,但模拟变得停滞,因为每天产生约 30-40 个代理.

This method also works, but the simulation becomes stagnant as ~30-40 agents are produced per day.

推荐答案

数据库访问是一项缓慢且成本高昂的练习,如果可能,应该只进行一次,即将模拟开始时的所有数据加载到内存中.你可以这样做:

Database access is a slow and costly excercise and should only be done once if possible, i.e. load all data at the start of the simulation into memory. You can do that by:

  1. 创建一个 Java 类,该类表示与该数据库表中的数据相同的数据
  2. 在模型启动时将所有行作为该类的实例保存到地图中 - 您可以使用 Origin/Destination 作为键(使用 Anylogic 的 Pair 对象)和类实例作为值
  3. 使用地图进行查找,您将不再需要在运行时进行数据库查询

您的设置会较慢,但执行速度会快得多

You will have a slower setup, but much faster execution

这篇关于在 Anylogic(Java、SQL)上查找连续数据的最快方法是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆