/// An example implementation of the `KnapsackItem` protocol. struct Example: KnapsackItem, CustomStringConvertible { var name: String var weight: Int var value: Int var description: String { name } } let problemSetting = ZeroOneKnapsackProblem(with: [ Example(name: "map", weight: 9, value: 150), Example(name: "compass", weight: 13, value: 35), Example(name: "water", weight: 153, value: 200), Example(name: "sandwich", weight: 50, value: 160), Example(name: "glucose", weight: 15, value: 60), Example(name: "tin", weight: 68, value: 45), Example(name: "banana", weight: 27, value: 60), Example(name: "apple", weight: 39, value: 40), Example(name: "cheese", weight: 23, value: 30), Example(name: "beer", weight: 52, value: 10), Example(name: "suntan cream", weight: 11, value: 70), Example(name: "camera", weight: 32, value: 30), Example(name: "t-shirt", weight: 24, value: 15), Example(name: "trousers", weight: 48, value: 10), Example(name: "umbrella", weight: 73, value: 40), Example(name: "waterproof trousers", weight: 42, value: 70), Example(name: "waterproof overclothes", weight: 43, value: 75), Example(name: "note-case", weight: 22, value: 80), Example(name: "sunglasses", weight: 7, value: 20), Example(name: "towel", weight: 18, value: 12), Example(name: "socks", weight: 4, value: 50), Example(name: "books", weight: 30, value: 10), ], computeResultsUpTo: 400) let result = problemSetting(limit: 400) let (totalValue, totalWeight) = (result.value, result.weight) print("Kept:") result.contents.forEach { print(" \($0)") } print("For a total value of \(totalValue) and a total weight of \(totalWeight)")