如何在 CPLEX 的调度问题中添加新约束?
How to add new constraints in the scheduling problem at CPLEX?
我是 CPLEX 的初学者,我很难在我的项目中添加更多约束。当我有多个起点和终点且只有一个产品时,该脚本运行良好
我想在每个目的地有更多的产品需求,但我不知道如何写约束。
{string} Forest = {"A","B","C","D","E"};
{string} Destination = {"D1" , "D2"};
{string} Products = {"Pinus","Eucalyptus"};
float Demand [Destination][Products]= [[3,1],[4,5]];
float Distance [Forest][Destination]=[[21,52],[42,12],[25,15],[52,31],[9,42]];
float Stock [Forest][Products]= [[0.94,0],[0,8.62],[0,1.21],[2.6,0],[8.77,0]];`
//Decision Variables
dvar float+ Delivered [Forest][Destination];
//Função Objetivo
minimize
sum (u in Forest, c in Destination) Distance[u][c] * Delivered[u][c];
//Constraints
subject to {
forall (u in Forest)
sum (c in Destination)
Delivered[u][c] <= Stock [u];
forall (c in Destination)
sum (u in Forest)
Delivered[u][c] >= Demand[c];
}
您还需要按产品扩展您的决策变量(就像您对需求和库存所做的那样),以便您可以了解每种产品的交付量。
然后您可以通过添加 "forall (p in Products)".
为每个产品复制每个约束
dvar float+ Delivered [Forest][Destination][Products];
forall (p in Products)
forall (u in Forest)
sum (c in Destination)
Delivered[u][c][p] <= Stock[u][p];
你可以试试
{string} Forest = {"A","B","C","D","E"};
{string} Destination = {"D1" , "D2"};
{string} Products = {"Pinus","Eucalyptus"};
float Demand [Destination][Products]= [[3,1],[4,5]];
float Distance [Forest][Destination]=[[21,52],[42,12],[25,15],[52,31],[9,42]];
float Stock [Forest][Products]= [[0.94,0],[0,8.62],[0,1.21],[2.6,0],[8.77,0]];
//Decision Variables
dvar float+ Delivered [Products][Forest][Destination];
//Função Objetivo
minimize sum (p in Products,u in Forest, c in Destination) Distance[u][c] * Delivered[p][u][c];
//Constraints
subject to {
forall (u in Forest,p in Products) sum (c in Destination) Delivered[p][u][c] <= Stock [u][p];
forall (p in Products,c in Destination) sum (u in Forest) Delivered[p][u][c] >= Demand[c][p];
}
我是 CPLEX 的初学者,我很难在我的项目中添加更多约束。当我有多个起点和终点且只有一个产品时,该脚本运行良好
我想在每个目的地有更多的产品需求,但我不知道如何写约束。
{string} Forest = {"A","B","C","D","E"};
{string} Destination = {"D1" , "D2"};
{string} Products = {"Pinus","Eucalyptus"};
float Demand [Destination][Products]= [[3,1],[4,5]];
float Distance [Forest][Destination]=[[21,52],[42,12],[25,15],[52,31],[9,42]];
float Stock [Forest][Products]= [[0.94,0],[0,8.62],[0,1.21],[2.6,0],[8.77,0]];`
//Decision Variables
dvar float+ Delivered [Forest][Destination];
//Função Objetivo
minimize
sum (u in Forest, c in Destination) Distance[u][c] * Delivered[u][c];
//Constraints
subject to {
forall (u in Forest)
sum (c in Destination)
Delivered[u][c] <= Stock [u];
forall (c in Destination)
sum (u in Forest)
Delivered[u][c] >= Demand[c];
}
您还需要按产品扩展您的决策变量(就像您对需求和库存所做的那样),以便您可以了解每种产品的交付量。
然后您可以通过添加 "forall (p in Products)".
为每个产品复制每个约束dvar float+ Delivered [Forest][Destination][Products];
forall (p in Products)
forall (u in Forest)
sum (c in Destination)
Delivered[u][c][p] <= Stock[u][p];
你可以试试
{string} Forest = {"A","B","C","D","E"};
{string} Destination = {"D1" , "D2"};
{string} Products = {"Pinus","Eucalyptus"};
float Demand [Destination][Products]= [[3,1],[4,5]];
float Distance [Forest][Destination]=[[21,52],[42,12],[25,15],[52,31],[9,42]];
float Stock [Forest][Products]= [[0.94,0],[0,8.62],[0,1.21],[2.6,0],[8.77,0]];
//Decision Variables
dvar float+ Delivered [Products][Forest][Destination];
//Função Objetivo
minimize sum (p in Products,u in Forest, c in Destination) Distance[u][c] * Delivered[p][u][c];
//Constraints
subject to {
forall (u in Forest,p in Products) sum (c in Destination) Delivered[p][u][c] <= Stock [u][p];
forall (p in Products,c in Destination) sum (u in Forest) Delivered[p][u][c] >= Demand[c][p];
}