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/listing/back_knapsack.mzn

16 lines
567 B
MiniZinc

% Problem parameters
enum TOYS;@\Vlabel{line:back:knap:toys}@
array[TOYS] of int: toy_joy;@\Vlabel{line:back:knap:joy}@
array[TOYS] of int: toy_space;@\Vlabel{line:back:knap:space}@
int: total_space;@\Vlabel{line:back:knap:left}@
% Decision variables
var set of TOYS: selection;@\Vlabel{line:back:knap:sel}@
var int: total_joy = sum(toy in selection)(toy_joy[toy]);@\Vlabel{line:back:knap:tj}@
% Constraints
constraint sum(toy in selection)(toy_space[toy]) <= total_space;@\Vlabel{line:back:knap:con}@
% Goal
solve maximize total_joy;@\Vlabel{line:back:knap:obj}@