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.
dekker-phd-thesis/assets/mzn/2_knapsack.mzn

16 lines
429 B
MiniZinc

% Problem parameters
enum TOYS = {football, tennisball, stuffed_lama, stuffed_elephant};
array[TOYS] of int: toy_joy = [63, 12, 50, 100];
array[TOYS] of int: toy_space = [32, 8, 16, 40];
int: space_left = 64;
% Decision variables
var set of TOYS: selection;
var int: total_joy = sum(toy in selection)(toy_joy[toy]);
% Constraints
constraint sum(toy in selection)(toy_space[toy]) < space_left;
% Goal
solve maximize total_joy;