pykp.solvers.greedy#

Provides an implementation of the greedy algorithm for solving the knapsack problem.

Example

Solve a knapsack problem using the greedy algorithm:

import numpy as np
from pykp import Item, solvers

items = np.array([
        Item(weight = 10, value = 60),
        Item(weight = 20, value = 100),
        Item(weight = 30, value = 120),
])
capacity = 50
arrangement = solvers.greedy(items, capacity