<commit_before>"""
Baggage Bin Problem using A* Algorithm
--------------------------------------
@author: <NAME>
"""
from heapq import heappush

from .state import BaggageState
from .manager import BaggageManager

EMPTY_SPACE_TOKEN = '*'


class Solver(object):
    def __init__(self, start):
        self.start = start
        self.goal = None
        self.baggage_manager = BaggageManager(start.num_of_bin_sets)

        self.to_visit = []
        self.cost_so_far = {self.start.text: 0}
        self.came_from = {self.start.text: None}

    def heuristic(self, state):
        return self.baggage_manager.distance_from_goal(state)

    def _add_to_open_set(self, state, priority):
        heappush(self.to_visit, (priority, state))

    def shortest_path_to_goal(self):
        # Traverse the states
        self._traverse()

        # Now retrace the path
        current = self.goal
        path = [current]
        while current != self.start:
            current = self.came_from[current.text]
            path.insert(0, current)

        unsigned_to_signed = len(path[-1].configuration)/2 - 1

        return [(each.src-unsigned_to_signed, each.dest-unsigned_to_signed) for
                each in path if each != self.start]

    def _traverse(self):
        closed_set = []
        self._add_to_open_set(self.start, 0)

        while self.to_visit:<commit_msg>Added more docs to solver<commit_after>"""
Baggage Bin Problem using A* Algorithm
--------------------------------------
@author: <NAME>
"""
from heapq import heappush

from .state import BaggageState
from .manager import BaggageManager

EMPTY_SPACE_TOKEN = '*'


class Solver(object):
    """
    Runs the A* algorithm to find the optimum moves.
    """
    def __init__(self, start):
        self.start = start
        self.goal = None
        self.baggage_manager = BaggageManager(start.num_of_bin_sets)

        self.to_visit = []
        self.cost_so_far = {self.start.text: 0}
        self.came_from = {self.start.text: None}

    def heuristic(self, state):
        """
        Lesser the heuristic, closer the given state is to the goal. Uses
        Manhattan distance.
        
        :type return: int
        """
        return self.baggage_manager.distance_from_goal(state)

    def _add_to_open_set(self, state, priority):
        """
        Open set is a priority queue maintained as a heap.
        """
        heappush(self.to_visit, (priority, state))

    def shortest_path_to_goal(self):
        """
        Finds the shortest path and returns the optimum moves as tuples. Eg:
        
        """
        # Traverse the states
        self._traverse()

        # Now retrace the path
        current = self.goal
        path = [current]
        while current != self.start:
            current = self.came_from[current.text]
            path.insert(0, current)

        unsigned_to_signed = len(path[-1].configuration)/2 - 1

        return [(each.src-unsigned_to_signed, each.dest-unsigned_to_signed) for
                each in path if each != self.start]

    def _traverse(self):
        closed_set = []
        self._add_to_open_set(self.start, 0)

        while self.to_visit:
{'fraction_non_alphanumeric': 0.11905511811023622, 'fraction_numerical': 0.003779527559055118, 'mean_word_length': 2.1570576540755466, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6398140', 'n_tokens_mistral': 992, 'n_tokens_neox': 928, 'n_words': 237}