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 in order. Each slice is a list of size containing the next elements in . The last slice may contain fewer than elements in order to make sure that the returned list contains all elements in .

2. find best addition to group: Find the best student in to add to the group , i.e., the student that increases the group's score the most (or decreases it the least).Preconditions: len(non_members) > 0

3. random swap: Swap two random elements from distinct sublists of . Uses a random seed to allow for repeatable results. Note: This function mutates Preconditions: len(lst) >= 2, each sub list has length >= 1

4. total score: Return the total score of the grouping of students in according to . Note: This function does the same thing as the following:

g = Grouping()

for group in groups:

g.add_group(Group(group))

return survey.score_grouping(g)

Preconditions: len(groups) > 0

5. Accept: If is at least as high as , return True. Otherwise, return True with probability

exp(( - ) / )

unless is 0, in which case, return False.

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

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 thereis any part that you are unsure about, mark it out ifpossible. Please upload answers in the form of screenshots or in properindentation if possible. 1. Can add any private attribute or functions needed2. Can add an __eq__ if needed Thank you so much! Explanationof helper functions: 1. slice list: Return a list containing slices ofin order. Each slice is a list of size containing the nextelements in . The last slice may contain fewer than elements inorder to make sure that the returned list contains all elements in. 2. find best addition to group: Find the best student in

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!