Question: Can you read the following code and try to finish class Grouping, complete the TODO in class AlphaGrouper(Grouper), class GreedyGrouper(Grouper), class SimulatedAnnealingGrouper(Grouper). If there is
Can you read the following code and try to finish class Grouping, complete the TODO in class AlphaGrouper(Grouper), class GreedyGrouper(Grouper), class SimulatedAnnealingGrouper(Grouper). If there is any part that you are unsure about, mark it out if possible. Please upload answers in the form of screenshots or in proper indentation if possible.
1. Can add any private attribute or functions needed
2. Can add an __eq__ if needed
Thank you so much!
Explanation of helper functions:
1. slice list: Return a list containing slices of
2. find best addition to group: Find the best student in
3. random swap: Swap two random elements from distinct sublists of
4. total score: Return the total score of the grouping of students in
g = Grouping()
for group in groups:
g.add_group(Group(group))
return survey.score_grouping(g)
Preconditions: len(groups) > 0
5. Accept: If
exp((
unless
rough explanation on the three grouper that needs to be accomplished:
AlphaGrouper: completely sorted according to the names of the students and then cut out the groups
Greedy Grouper: to select the students who try to improve their scores the most to group
SimulatedAnnealingGrouper: randomly select the grouping method with the highest score











if TYPE_CHECKING: from survey import Survey from course import Course, Student \# Provided helper def slice_list(Lst: list[Any], n : int) List[List[Any]]:... \# Provided helper def find_best_addition_to_group(survey: Survey, members: Zist[Student], non_members: list[Student]) Student:... \# Provided helper def random_swap(lst: list[Zist[Any]], seed: int = 0) None:... \# Provided helper def total_score(survey: Survey, groups: list[list[Student]]) float: " \# Provided helper def accept(old_score: float, new_score: float, temperature: float, seed: int ) bool:... class Group:... oad with pre-built Python packages shared indexes // Always download // Download once // Don't show again // Config... (2023/3/1,22:57) P. Python Consolems Derminal Services ad with pre-built Python packages shared indexes // Always download // Download once // Don't show again // Config... (2023/3/1, 22:57) 479:42 LF UTF-8 4 spaces Python 3.10 2 Python packages shared indexes // Always download // Download once // Don't show again // Config... (2023/3/1, 22:57) 479:42 LF UTF-8 4 spaces Python 3.10 has any randomness, but it is still an acceptable starting point for simulated annealing. using the function. Then, repeat the following steps for each iteration of this grouper, keeping track of the best list of groups you have found so far: helper function with the current iteration as the seed. 2. Compute the total score of the new list of groups. 3. Compute the temperature based on the iteration number, as described in the Grouping Algorithms document. 3. Use the function to determine if the list of groups will be accepted. The function always accepts the new list of groups if the score is better than the old one. If it is not, it is accepted with probability exp(( new_score - old_score )/ temperature ). Use the current iteration as the seed for . If the new list of groups is not accepted, revert to the previous one. After all the iterations are complete, temperature will be very close to 0 . (It may not equal exactly, due to imprecision in floating point calculations; this is not a problem, it's just an inherent reality of working with floating point numbers.) Return a grouping that contains the best list of groups found. NOTES: - Iteration numbers go from to (\# iterations) - 1 - Throughout the process, keep track of the best list of groups so far - To make a copy of the current list of groups (so that you can do a random swap and compare the old and new versions)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
