我对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 。
但我仍然收到此错误:
MiniZinc:类型错误:找不到带有此签名的函数或谓词:`exactly(int,var int,int)'
基本上,我要实现的是在“ OpenWarehouses”数组中仅将一个元素初始化为1
答案 0 :(得分:1)
这是一个sintax错误... constraint exactly(1,OpenWarehouses,1);
显然,这是正确的sintax。