【问题标题】:Model stops simulating when exporting data from database从数据库导出数据时模型停止模拟
【发布时间】:2021-05-25 01:58:28
【问题描述】:

我正在从我的 AnyLogic 模型中导出数据,方法是从保存到内部数据库的数据中写入/附加每次运行的文本文件。我在实验的After simulation run 字段中使用以下代码:

// create header
file.println("id"+","+"replicate"+","+"diagnostic_pathway_duration"+","+"total_cost_patient"+","+
                "referred_gh"+","+"referred_th"+","+"tx_gh"+","+"tx_th"+","+"tx_ah"+","+"arrival_gh"+","+
                "complete_gh"+","+"arrival_th"+","+"complete_th"+","+"arrival_ah"+","+"complete_ah"+","+
                "pathway_concluded");

// Write data from dbase table                                
List<Tuple> rows = selectFrom(patient_export).list();

for (Tuple row : rows) {
        file.println(        row.get( patient_export.id ) + "," + 
                                        row.get( patient_export.replicate ) + "," + 
                                        row.get( patient_export.diagnostic_pathway_duration ) + "," + 
                                        row.get( patient_export.total_cost_patient ) + "," + 
                                        row.get( patient_export.referred_gh ) + "," + 
                                        row.get( patient_export.referred_th ) + "," + 
                                        row.get( patient_export.tx_gh ) + "," + 
                                        row.get( patient_export.tx_th ) + "," + 
                                        row.get( patient_export.tx_ah ) + "," + 
                                        row.get( patient_export.arrival_gh ) + "," + 
                                        row.get( patient_export.complete_gh ) + "," + 
                                        row.get( patient_export.arrival_th ) + "," + 
                                        row.get( patient_export.complete_th ) + "," + 
                                        row.get( patient_export.arrival_ah ) + "," + 
                                        row.get( patient_export.complete_ah ) + "," + 
                                        row.get( patient_export.pathway_concluded ));
}
file.close();
deleteFrom(patient_export).execute();

initial experiment setup 字段中,我包含了以下代码:

deleteFrom(patient_export).execute();

但是,一段时间后不再执行模拟运行。该模型只是不再进步,并且CPU没有被征税。在一个实例中,实验在 45 次迭代后停止模拟,结果生成了一个 210 mb 的文本文件,大约有 110 万行。

我通过使用事件触发Patient 中的函数将数据保存到内部数据库。这是代码:

insertInto(patient_export)
    .columns(patient_export.iteration, patient_export.replicate, patient_export.id, patient_export.diagnostic_pathway_duration,
             patient_export.total_cost_patient, patient_export.referred_gh, patient_export.referred_th, patient_export.tx_gh,
             patient_export.tx_th, patient_export.tx_ah, patient_export.arrival_gh, patient_export.complete_gh, patient_export.arrival_th,
             patient_export.complete_th, patient_export.arrival_ah, patient_export.complete_ah, patient_export.pathway_concluded
            ) //database tables
    .values(main.v_iteration, main.v_replicate, p_patientId, p_diagnostic_pathway_duration, p_totalCost, p_referred_GH, p_referred_TH,
            p_Tx_GH, p_Tx_TH, p_Tx_AH, p_timeArrivedDxGH, p_timeCompletedDxGH, p_timeArrivedDxTH, p_timeCompletedDxTH, p_timeArrivedDxAH,
            p_timeCompletedDxAH, p_diagnosticPathwayConcluded
    .execute();

我在这里做错了什么?内部数据库是否在发挥作用?非常感谢所有帮助。

【问题讨论】:

  • 当您关闭任何 dbase 写入时,它是否按预期工作?首先尝试找出真正导致问题的代码部分并报告;)(即模型编写或实验后编写)
  • 感谢本杰明的指点。我已将其范围缩小到如何在数据库中保存数据。当我禁用该功能时,我没有任何问题。尽管我在实验中使用了System.gc(); deleteFrom(patient_export).execute();,但我的数据库仍然很大(~500 mb),尽管我的数据库表中没有列出任何记录。当然,模型执行不会被记录。
  • 似乎不是我的模型特有的。例如,当我运行这个模型 (sdaza.com/blog/2020/anylogic-database) 时,它会在数据库达到 ~300 mb 的大小时停止模拟。不知道发生了什么。
  • 在 dbase 属性中,有一个复选框“退出时自动压缩”(或类似的)。试试看。
  • 8.3.3(大学版)没有这个选项

标签: anylogic


【解决方案1】:

【讨论】:

  • 我在帮助文档中看到了这一点,但我的 AnyLogic 版本(大学 8.3.3)中没有该选项。不过还是谢谢。
  • 您可以手动执行 SQL 语句来执行此操作,“COMPACT”语句执行此操作...
猜你喜欢
  • 1970-01-01
  • 2020-12-09
  • 1970-01-01
  • 1970-01-01
  • 2012-07-01
  • 2012-11-20
  • 1970-01-01
  • 2020-08-14
  • 2014-09-20
相关资源
最近更新 更多