1
0
This repository has been archived on 2025-03-06. You can view files and clone it, but cannot push or open issues or pull requests.
on-restart-benchmarks/tests/examples/multidimknapsack_simple.mzn
Jip J. Dekker f2a1c4e389 Squashed 'software/mza/' content from commit f970a59b17
git-subtree-dir: software/mza
git-subtree-split: f970a59b177c13ca3dd8aaef8cc6681d83b7e813
2021-07-11 16:34:30 +10:00

49 lines
1.2 KiB
MiniZinc

% RUNS ON mzn20_fd
% RUNS ON mzn-fzn_fd
% RUNS ON mzn20_fd_linear
% RUNS ON mzn20_mip
%------------------------------------------------------------------------------%
% The classical 0/1 multidimensional knapsack problem.
%
% There is a knapsack with m different capacity constraints and n items with
% profits and weights. The goal is to maximise the total profit of the items
% in the knapsack while not violating any of the capacity constraints.
%------------------------------------------------------------------------------%
int: n;
int: m;
array[1..n] of int: Profits;
array[1..n,1..m] of int: Weights;
array[1..m] of int: Capacities;
array[1..n] of var 0..1: x;
constraint
forall(i in 1..m) (
sum([Weights[j,i] * x[j] | j in 1..n]) <= Capacities[i]
);
solve maximize
sum([x[j] * Profits[j] | j in 1..n]);
output [ "multidimknapsack_simple " ] ++
[ show(x[i]) ++ if i = n then "\n" else " " endif | i in 1..n ];
%------------------------------------------------------------------------------%
% data
n = 5;
m = 3;
Profits = [5,6,3,7,4];
Capacities = [5,10,15];
Weights = [| 2, 3, 2
| 1, 4, 4
| 1, 2, 5
| 3, 2, 3
| 1, 3, 5 |];