jmyrberg / mknapsack

Algorithms for solving knapsack problems with Python

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ValueError: Solution not valid

yutozh opened this issue · comments

commented

When I test a case, it raise a "ValueError: Solution not valid". It seems like a bug when doing "Ensure solution validity".

from mknapsack.algorithms import mtm
profits = [1,1]
weights = [1,1]
capacities = [2,2]

z, x, bt, glopt = mtm(profits, weights, capacities)
print('Total profit: %d' % z)
print('Solution: %s' % x)
print('Number of backtracks performed: %d' % bt)
print('Global optimum: %s' % glopt)

The error is:
ValueError: Solution not valid:
p w c valid
i
0 2 2.0 2 1

How to solve this problem?

Resolved.