我们做手机。我们有销售价格,生产成本,利润。

目标是最大化利润。组装每部电话需要以下组件。

组件的最大数量。

订单(我们订购了这么多手机,我们把它们卖出去了):

以下是我的mod文件:
set PHONE;
set COMPONENTS;
param price {PHONE} >= 0;
param cost {PHONE} >= 0;
param maxComponents {COMPONENTS} >= 0;
param ordered {PHONE} >= 0;
param matrix {COMPONENTS, PHONE}; #The amount of components needed to make a particular phone.
var x {PHONE} >= 0; # Number of manufactured telephones.
maximize profit: sum {i in PHONE} ( ordered[i] * price[i] - x[i] * cost[i] );
subject to min_manufacture {i in PHONE}:
x[i] >= ordered[i]; # We must produce a minimum of what is ordered
subject to component {i in COMPONENTS}:
sum {j in PHONE} matrix[i,j] * x[j] <= maxComponents[i]; # The number of components used must not exceed the maximum.
subject to min_quantity {i in COMPONENTS, l in PHONE}:
sum {j in PHONE} matrix[i,j] * x[j] >= matrix[i,l]; # Minimum quantity used per component if we manufacture at least one telephone. For example, a triple phone requires at least 2 of the five components.和dat文件:
set PHONE := 1 2 3 4 5;
set COMPONENTS:= 1 2 3 4 5 6 7;
param price :=
1 450
2 120
3 500
4 390
5 100;
param cost :=
1 370
2 90
3 400
4 320
5 70;
param maxComponents :=
1 28
2 20
3 8
4 30
5 47
6 27
7 15;
param ordered :=
1 3
2 5
3 5
4 0
5 10;
param matrix: 1 2 3 4 5 :=
1 1 1 0 0 0
2 1 1 0 0 0
3 1 0 0 0 0
4 1 0 1 1 0
5 0 0 2 1 1
6 0 0 2 1 0
7 0 0 1 1 0;问题是,例如,如果第六个分量的最大数量是三个,第七个分量的最大数量是两个,那么从三个音素产生1.5个,这是不可能的。以及用于三重电话1,5,3,1,5的第四、五、六、七个组件的使用量,这也不能。

我怎么做才能得到一个整数解?
因为如果我写变量x,它是一个整数,我得到的都是0。
我的运行文件:
model phone.mod;
data phone.dat;
option presolve 0;
option solver cplex;
solve;
display profit, x;
display {i in COMPONENTS, j in PHONE} matrix[i,j] * x[j];发布于 2020-12-01 11:59:34
您需要将相关变量声明为整数,如下所示:
var x {PHONE} >= 0 integer;一些求解器无法处理整数约束,可能会忽略该约束(带有警告消息),但CPLEX应该可以。
https://stackoverflow.com/questions/65077734
复制相似问题