【问题标题】:Buy all items of a shopping list with minimum price and distance travelled以最低价格和行驶距离购买购物清单中的所有物品
【发布时间】:2021-05-11 13:15:32
【问题描述】:

我有一个我想购买的 20 件商品的清单 i = (1,...,20),并且城镇 j = (1,...5) 有 5 家超市,有两个给定条目:

Cij: the price of item "i" in supermarket "j"

Dj: the cost to travel between my house and the supermarket "j"

为方便起见,我想在最多 2 个市场中购买所有物品(所有物品都在所有市场中)。逛完市场后,我总是回家,如何制定整数线性问题模型以最小化成本

【问题讨论】:

    标签: linear-programming modeling


    【解决方案1】:

    在 MiniZinc 中实现的简单 MILP 模型(为简单起见,仅包含三个项目)。模型中x_ij表示商品j是否从店铺i购买,z_i表示是否访问店铺i

    int: Stores = 5;
    int: Items = 3;
    
    set of int: STORE = 1..Stores;
    set of int: ITEM = 1..Items;
    
    array[STORE,ITEM] of int: C = [| 5, 4, 5
                                   | 3, 2, 5 
                                   | 5, 5, 2 
                                   | 8, 1, 5 
                                   | 1, 8, 2 |];
    
    array[STORE] of int: D = [5, 4, 5, 2, 3];
        
    array[STORE,ITEM] of var 0..1: x;
    array[STORE] of var 0..1: z;
    
    % visit at most two shops
    constraint sum(i in STORE)(z[i]) <= 2;
    
    % buy each item once
    constraint forall(j in ITEM)
        (sum(i in STORE)(x[i,j]) = 1);
    
    % can't buy from a shop unless visited
    constraint forall(i in STORE)
        (sum(j in ITEM)(x[i,j]) <= Items*z[i]);
    
    var int: cost = sum(i in STORE)(2*D[i]*z[i]) + sum(i in STORE, j in ITEM)(C[i,j]*x[i,j]);
    
    solve minimize cost;
    
    output ["cost=\(cost)\n"] ++ 
    ["x="] ++ [show2d(x)] ++
    ["z="] ++ [show(z)];
    

    跑步给出:

    cost=14
    x=[| 0, 0, 0 |
         0, 0, 0 |
         0, 0, 0 |
         0, 1, 0 |
         1, 0, 1 |]
    z=[0, 0, 0, 1, 1]
    

    【讨论】:

      猜你喜欢
      • 2013-02-12
      • 1970-01-01
      • 2011-02-17
      • 2018-01-10
      • 2015-08-27
      • 2019-12-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多