【问题标题】:Anylogic: How to add costs (per route) per time of day?Anylogic:如何在一天中的每个时间添加成本(每条路线)?
【发布时间】:2023-01-04 08:54:59
【问题描述】:

我有关于集装箱运输每天每条路线不同成本的数据(例如,早上从 A 区到 B 区;运输总成本为 100 欧元),几乎有 200 个区域,一天 4 次。我如何在每条路线的 Anylogic 模型中分配这些成本一天中的每个时间

(在此之后,我希望代理商(卡车)决定(根据成本)旅行的路线和时间)

【问题讨论】:

    标签: database routes simulation anylogic


    【解决方案1】:

    在没有示例数据的情况下,我正在使用一些虚构的数据来举例说明如何执行此操作。

    假设我有以下路线和成本数据

    您可以将其导入 AnyLogic 数据库,然后使用它们用您的数据填充自定义类。

    例如,这是您的路线的自定义 Java 类

    public class MyRoute {
        String id;
        String from;
        String to;
        
        LinkedHashMap<String, Double> routeCosts = new LinkedHashMap<String, Double>();
        
        /**
         * Default constructor
         */
        public MyRoute(String id, String from, String to) {
            this.id = id;
            this.from = from;
            this.to = to;
        }
        
        public void addCost(String timeOfDay, double cost) {
            routeCosts.put(timeOfDay, cost);
        }
    }
    
    

    然后我有一个小功能可以从数据库中填充它们

    List<Tuple> rows = selectFrom(routes).list();
    
    for (Tuple row : rows) {
        MyRoute route = new MyRoute(
            row.get( routes.route ),
            row.get( routes.from_db ),
            row.get( routes.to_db )
        );
        
        // Add costs
        List<Tuple> costRows = selectFrom(costs)
        .where(costs.route.eq(route.id))
        .list();
    
        for (Tuple costRow : costRows) {
            route.addCost(
                row.get( costs.time_of_day ), 
                row.get( costs.cost )
            );
        }   
    }
    
    

    现在您可以根据费用或一天中的时间对路线进行排序,并以此来做出您的决定

    您可以在此处查看有关排序的更多信息https://www.baeldung.com/java-hashmap-sort

    【讨论】:

    • 非常感谢您的回答!在实施它时,我只从最后一个气味中得到一个错误:myRoutes.add(route); 它说:“无法解析 myRoutes”,(当我将其更改为时它也不起作用我的路线).. 你知道为什么吗?
    • 对不起!我在我的 main 上有一个 myRoutes 集合,我在其中添加了创建的路线以检查它们。将编辑答案
    猜你喜欢
    • 2023-01-03
    • 2022-01-22
    • 1970-01-01
    • 2018-08-26
    • 2022-01-24
    • 1970-01-01
    • 2019-12-09
    • 2022-06-10
    • 1970-01-01
    相关资源
    最近更新 更多