Skip to content

Commit

Permalink
Fix multicsv app
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastian-quintero committed Sep 13, 2024
1 parent 3c58f78 commit 09ed314
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
24 changes: 12 additions & 12 deletions python-ortools-knapsack-multicsv/input/items.csv
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
"id","value","weight"
"cat",100,20
"dog",20,45
"water",40,2
"phone",6,1
"book",63,10
"rx",81,1
"tablet",28,8
"coat",44,9
"laptop",51,13
"keys",92,1
"nuts",18,4
id,value,weight
cat,100,20
dog,20,45
water,40,2
phone,6,1
book,63,10
rx,81,1
tablet,28,8
coat,44,9
laptop,51,13
keys,92,1
nuts,18,4
2 changes: 1 addition & 1 deletion python-ortools-knapsack-multicsv/input/weight_capacity.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"weight_capacity"
weight_capacity
50
6 changes: 3 additions & 3 deletions python-ortools-knapsack-multicsv/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ def solve(input: nextmv.Input, options: nextmv.Options) -> nextmv.Output:
for item in input.data["items"]:
item_variable = solver.IntVar(0, 1, item["id"])
items.append({"item": item, "variable": item_variable})
weights += item_variable * item["weight"]
values += item_variable * item["value"]
weights += item_variable * int(item["weight"])
values += item_variable * int(item["value"])

# This constraint ensures the weight capacity of the knapsack will not be
# exceeded.
capacity = input.data["weight_capacity"][0]["weight_capacity"] # Read as a CSV.
capacity = int(input.data["weight_capacity"][0]["weight_capacity"]) # Read as a CSV.
solver.Add(weights <= capacity)

# Sets the objective function: maximize the value of the chosen items.
Expand Down

0 comments on commit 09ed314

Please sign in to comment.