View the step-by-step solution to:

submitted_file_path = "test_knapsack_solution.csv" def Evaluate_Sol(file_path): student_id = file_path.split("_")[0] df_solution...

Hey tutors, please help me out !!!

it is a python problem and I am not allowed to import packages .


I am solving a knapsack problem with python,However, my problem is much more complex:

1) 500 knapsack instance, each one has 50 items

2) weight and reward of each item in each knapsack is given

3) the capacity (C)is not a fixed number but a variable follow uniform distribution, U【100,150】

4) only find out C once choose which items to put in the knapsack

5) if we go over C, get nothing for that instance


The screen shot of test cell is in the attachment testcell.jpeg

testcell.jpeg

submitted_file_path = "test_knapsack_solution.csv" def Evaluate_Sol(file_path):
student_id = file_path.split("_")[0]
df_solution = pd.read_csv(file_path, header = None)
df_solution.reset_index(inplace = True, drop = True)
current_obj = O for i in range(0,300,3):
sizes = list(df_solution.loc[i, 0:49])
rewards = list(df_solution.loc[i+1, 0:491)
solution = [bool(i) for i in list(df_solution.loc[i+2, 0:49])]
C = knap_sizes[int(i/3)]
#print(sizes)
#print(solution)
total_size = np.dot(sizes,solution)
total_reward = np.dot(rewards,solution)
#print(totai_size)
if total_size <= C: current_obj+=tota1_reward
return {student_id: current_obj} final_resu1ts = Evaluate_Sol(submitted_fi1e_path)
fina1_results

Recently Asked Questions

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

-

Educational Resources
  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question