Reputation: 57
I have a quesiton on "exactly" predicate in 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)"];
This is my code... i checked at this link how it is supposed to work: https://www.minizinc.org/downloads/doc-0.11/mzn-globals.html#exactly .
But i still get this error:
MiniZinc: type error: no function or predicate with this signature found: `exactly(int,var int,int)'
basically what i'm trying to achieve is to have only one element initialized as 1 in the "OpenWarehouses" array
Upvotes: 1
Views: 74
Reputation: 57
It was a sintax error... constraint exactly(1,OpenWarehouses,1);
This is the correct sintax apparently.
Upvotes: 1