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 initialise the knapsack instance.

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")