Now, consider the following practical problem. Suppose that you\'re in charge of
ID: 3792218 • Letter: N
Question
Now, consider the following practical problem. Suppose that you're in charge of picking a set of experiments to be launched into space. Each experiment has an ID number, an associated equipment mass in kilograms, and a "Value rating" that approximates how important to science the collected data will be. The following table lists the set E of all experiments: Unfortunately, not all of the experiments can be flown due to mass constraints - there's only 700 kg of payload available for the experiments. Launching stuff into orbit is expensive! Thus, the challenge is to pick the subset of E whose elements have the highest possible combined value rating but at the same time have a combined mass of 700 kg or less. One way to solve this problem is to use a "brute force" approach. Consider ALL subsets of E. For each subset, determine its overall mass and value rating. Keep track of the highest-value subset with a combined mass of 700 or less. Once all the subsets are considered, this highest-value subset will be the one that you want to fly! Write a program that uses your function from #1 and the brute force technique to find and display the optimal solution. Which experiments should be chosen? What is the total mass and value rating of the optimal solution? Even though it works fine for this problem, why would this brute force approach be terribly inefficient if you had a large number of experiments?Explanation / Answer
import itertools data = {36:5,264:9,188:6,203:8,104:8,7:6,92:2,65:8,25:3,170:6,80:7,22:4} mass = data.keys() value_ratings = data.values() value=list() temp=list() weightsum=list() valuesum=list() for L in range(1, len(value_ratings)+1): for subset in itertools.combinations(value_ratings, L): temp.append(str(subset).strip("()").split(",")) """for k in temp: if k!="": sum+=data(int(k))""" sum_w=0 sum=0 for i in temp: for j in i : if j!="": sum_w = sum_w + mass[value_ratings.index(int(j))] sum = sum + int(j) weightsum.append(sum_w) valuesum.append(sum) sum=0 sum_w=0 while 1 : max_value = max(valuesum) index=valuesum.index(max_value) if weightsum[index]Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.