Mathematical optimization N个产品与M个特征的最优组合

Mathematical optimization N个产品与M个特征的最优组合,mathematical-optimization,Mathematical Optimization,我有X个固定成本的零件。每个部分有N个不同价值的方面 例如: Part 1: cost = 3, Width = 10, Length = 12, Height = 13, Weight = 12, Value = sum of four aspects = 47 Part 2: cost 4, Width = 20, Length = 15, Height = 12, Weight = 10, Value = sum of above four aspects = 57 Part 3: c

我有X个固定成本的零件。每个部分有N个不同价值的方面

例如:

Part 1: cost = 3,
Width = 10,
Length = 12,
Height = 13,
Weight = 12,
Value = sum of four aspects = 47

Part 2: cost 4,
Width = 20,
Length = 15,
Height = 12,
Weight = 10,
Value = sum of above four aspects = 57

Part 3: cost 2,
Width = 9,
Length = 12,
Height = 9,
Weight = 8,
Value = sum of above four aspects = 38
然后我有许多不同的项目,例如20个项目。 我一次最多可以选择的物品数量有一个上限,例如8件物品。 我有一个成本上限,即所选项目的成本总和应具有规定的限额,例如30

我现在必须从这个列表中选择项目,以便获得最大值。 另一个限制是,在最终的组合中,所有方面都应该平衡。 e、 g.宽度、长度、高度和重量的最终总和应均匀分布。如果不相等,至少在平衡范围内。i、 e.由于有4个方面,每个方面应占总价值的25%+/-5%


我试着用背包问题的方法解决它,但我这里有更多的维度。

一种方法是通过MILP模型。下面是一个用Minizing实现的简单模型
x
是二进制变量,表示是否选择了项

int: items = 5;
int: selectedItems = 3;
int: maxCost = 10;

set of int: ITEM = 1..items;

array[ITEM] of int: cost = [3, 4, 2, 1, 1];
array[ITEM] of int: width = [10, 20, 9, 15, 12];
array[ITEM] of int: length = [12, 15, 12, 15, 12];
array[ITEM] of int: height = [13, 12, 9, 15, 12];
array[ITEM] of int: weight = [12, 10, 8, 15, 12];
array[ITEM] of int: value = [width[i] + length[i] + height[i] + weight[i] | i in ITEM];
    
array[ITEM] of var 0..1: x;

% selected items constraint
constraint sum(x) <= selectedItems;

% cost constraint
constraint sum(i in ITEM)(cost[i]*x[i]) <= maxCost;

predicate balanced(array[ITEM] of var int: values) =
    let {var int: value = sum(i in ITEM)(values[i]*x[i])} in
    value >= 0.2*totalValue /\ value <= 0.3*totalValue;

% balance constraints
constraint balanced(width) /\ balanced(length) /\ balanced(height) /\ balanced(weight);

var 1..sum(value): totalValue = sum(i in ITEM)(value[i]*x[i]);

solve maximize totalValue;

output ["totalValue=\(totalValue)\n"] ++
["cost=\(sum(i in ITEM)(cost[i]*x[i]))\n"] ++ 
["x="] ++ [show(x)] ++
["\nratio="] ++ [show_float(5, 2,sum(i in ITEM)(width[i]*x[i]) / totalValue), show_float(5, 2,sum(i in ITEM)(length[i]*x[i]) / totalValue), show_float(5, 2,sum(i in ITEM)(height[i]*x[i]) / totalValue), show_float(5, 2,sum(i in ITEM)(weight[i]*x[i]) / totalValue)] ++
["\nvalue="] ++ [show(value)];

非常感谢。这有助于解决我手头的第一个问题。我真的对Minizing一无所知,但安装、理解和运行代码都非常简单。我现在试着得到这样的结果,将其中一个设置为30%,然后平均分配另一个。我如何做到这一点?我试着研究谓词平衡和等式,但我似乎没有弄对。可以考虑任何帮助。你可以考虑改变你的目标,比如(假设你想要代码<宽度>代码>接近30%)<代码>解决最大值总和+k*ABS(求和(i中项)(宽度[i] *x[i]));code>,这里的
k
是一个权重,使用例如
10
totalValue=165
cost=6
x=[0, 1, 0, 1, 1]
ratio= 0.28 0.25 0.24 0.22
value=[47, 57, 38, 60, 48]