我对minizinc中的“完全”谓词有一个疑问。
include "exactly.mzn";
%Scalar data
int: Warehouses;
int: Stores;
%Vectors
array [1..Stores, 1..Warehouses] of int: SupplyCost; %delivery price
array [1..Warehouses] of int: Capacity; %warehouse capacity
array [1..Warehouses] of int: FixedCost; %cost of warehouses to be open.
array [1..Stores] of int: Goods; %request of goods from each store
%Decision Variables
array [1..Stores, 1..Warehouses] of var 0..max(Goods): GoodsMoved;
array [1..Warehouses] of var 0..1: OpenWarehouses;
var 0..sum(SupplyCost): TransportationCost;
var 0..sum(FixedCost): OpeningCost;
var int: TotalCost;
%Constraints
%quantity of goods requested equal to request
constraint forall(r in 1..Stores)
(sum (c in 1..Warehouses)
(GoodsMoved[r,c]) = Goods[r]);
%total quantity of goods taken from a warehouse cannot exceed capacity
constraint forall(y in 1..Warehouses)
(sum (x in 1..Stores)
(GoodsMoved[x,y]) <= Capacity[y]);
%Exactly one 1 in OpenWarehouses: only one warehouse is open
constraint forall (c in 1..Warehouses) (exactly(1,OpenWarehouses[c],1));
%Which warehouses are open
constraint forall (c in 1..Warehouses)
(if (sum(r in 1..Stores) (GoodsMoved[r,c]))=0
then OpenWarehouses[c]=0
else OpenWarehouses[c]=1
endif);
%Assignment 2
constraint TotalCost = sum (r in 1..Stores) (sum(c in 1..Warehouses) (SupplyCost[r,c]*GoodsMoved[r,c])) + sum(x in 1..Warehouses) (OpenWarehouses[x]*FixedCost[x]);
solve minimize TotalCost;
output ["\(GoodsMoved[s,w])" ++ if w=Warehouses then "\n" else " " endif | s in 1..Stores, w in 1..Warehouses];
output["\(OpenWarehouses)" ++ "\n"];
output["\(TotalCost)"];
这是我的代码...我在此链接上检查了它应该如何工作:https://www.minizinc.org/downloads/doc-0.11/mzn-globals.html#exactly
。
但我仍然收到此错误:
基本上我想要实现的是在“OpenWarehouses”数组中只有一个元素初始化为1
最佳答案
这是语法错误... constraint exactly(1,OpenWarehouses,1);
这显然是正确的正税。
关于compiler-errors - Minizinc “Exactly”问题。编译时出错,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53123165/