Skip to content

Commit

Permalink
Implement knapsack evaluation
Browse files Browse the repository at this point in the history
  • Loading branch information
wederbn committed Jan 12, 2024
1 parent 5eac4d6 commit 5bffcf3
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions app/services/objective_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,26 @@ def generate_knapsack_objective_response(input: KnapsackObjectiveEvaluationReque
result_list = problem.interpret(most_likely_result)
print("List of items to use: ", result_list)

# TODO: calculate costs
objective_value = -100000

print("value: ", objective_value)
return ObjectiveResponse(objective_value, None, None)
objective_value = sum(values)
overall_weight = 0
for i in range(len(result_list)):
print("Selected package with ID: ", i)

if i > (len(values) - 1):
print("Package with index not available...")
objective_value += 50
else:
print("Value: ", values[i])
objective_value -= values[i]
overall_weight += weights[i]

print ("Overall weight: ", overall_weight)
if overall_weight > input.max_weights:
print ("Penalty as weight is higher than allowed max weight!")
objective_value += input.max_weights - overall_weight

print("Objective value: ", objective_value)
return ObjectiveResponse(objective_value, {most_likely_result: objective_value}, None)


def getObjectiveFunction(objFun, costFun, **kwargs):
Expand Down

0 comments on commit 5bffcf3

Please sign in to comment.