pykp.knapsack.Knapsack.
write_to_json#
- Knapsack.write_to_json(path: str)#
Write the knapsack configuration to a JSON file.
The output file can be used to load the knapsack instance at a later time using the load_from_json method.
- Parameters:
- pathstr
The file path for the output JSON file.
Examples
>>> knapsack = Knapsack(items=[Item(10, 2), Item(20, 4)], capacity=6) >>> knapsack.solve() >>> knapsack.write_to_json("output.json")