我怎样才能得到物品的组合
How can I get a combination of items
我刚开始使用 Minizinc,我会在这方面提供一些帮助。
如何编写以下约束:
I want to buy at most 4 GROUP offers, spend at most 100$ and I can buy
only one item from every group. Maximize quality.
int: items = 10;
set of int: GROUPS = 0..itms;
set of int: PRODUCTS = 1..7;
set of int:BUYS = 1..4;
int : max_spent = 100;
array[GROUPS] of set of int : package = array1d(GROUPS,[{},{1,2,3},{4,7},{3,6},{1,4,5},{3,4,7},{1,2,5},{4,6},{3,7},{3,7,5},{2,3}]);
array[GROUPS] of int: package_price = array1d(GROUPS,[0,5,5,25,10,12,20,40,55,52,10]);
array[GROUPS] of int: package_quality = array1d(GROUPS,[0,7,2,7,2,3,5,4,9,6,5]);
所需的输出应类似于:
{3,7} {4,6} {1,2,5} {}
quality = 10;
price = 97;
---更新---
到目前为止我尝试了:
var int : will_buy;
will_buy = sum(i in BUYS)(package_price[i]);
constraint will_buy <= max_spent;
var int : quality;
quality = sum(i in GROUPS)(package_quality[i]);
array[GROUPS] of var BUYS: index;
include "element.mzn";
constraint forall(t in GROUPS)
(
element(index[t], package_price, package_price[t])
/\
element(index[t], package_quality, package_quality[t])
);
:/
您的问题是众所周知的背包问题的变体。 MiniZinc tutorial 第 3.6 章给出了这个问题的解决方案。了解背包模型的MiniZinc模型应该可以给你解决这个问题的指导。
或者,您可能想看看 global packing constraints,这些可能会使建模更容易。
我刚开始使用 Minizinc,我会在这方面提供一些帮助。
如何编写以下约束:
I want to buy at most 4 GROUP offers, spend at most 100$ and I can buy only one item from every group. Maximize quality.
int: items = 10;
set of int: GROUPS = 0..itms;
set of int: PRODUCTS = 1..7;
set of int:BUYS = 1..4;
int : max_spent = 100;
array[GROUPS] of set of int : package = array1d(GROUPS,[{},{1,2,3},{4,7},{3,6},{1,4,5},{3,4,7},{1,2,5},{4,6},{3,7},{3,7,5},{2,3}]);
array[GROUPS] of int: package_price = array1d(GROUPS,[0,5,5,25,10,12,20,40,55,52,10]);
array[GROUPS] of int: package_quality = array1d(GROUPS,[0,7,2,7,2,3,5,4,9,6,5]);
所需的输出应类似于:
{3,7} {4,6} {1,2,5} {}
quality = 10;
price = 97;
---更新---
到目前为止我尝试了:
var int : will_buy;
will_buy = sum(i in BUYS)(package_price[i]);
constraint will_buy <= max_spent;
var int : quality;
quality = sum(i in GROUPS)(package_quality[i]);
array[GROUPS] of var BUYS: index;
include "element.mzn";
constraint forall(t in GROUPS)
(
element(index[t], package_price, package_price[t])
/\
element(index[t], package_quality, package_quality[t])
);
:/
您的问题是众所周知的背包问题的变体。 MiniZinc tutorial 第 3.6 章给出了这个问题的解决方案。了解背包模型的MiniZinc模型应该可以给你解决这个问题的指导。
或者,您可能想看看 global packing constraints,这些可能会使建模更容易。