Exemplo n.º 1
0
    def run(self):
        while True:
            inp = input('input command: ')
            inpsplit = inp.split(' ')

            if inp == 'productlist':
                product_list = self.checkoutSystem.get_product_id()
                print('\nproducts: ')
                for product_entry in product_list:
                    methods.print_padded('id: {} name: {} in stock: {}'.format(
                        product_entry[0], product_entry[1], product_entry[2]))
            elif inpsplit[0] == 'cartridgeamount':
                print('{}: {}'.format(
                    self.checkoutSystem.get_product_name(inpsplit[1]),
                    self.checkoutSystem.get_amount_in_cartridge(inpsplit[1])))
            elif inpsplit[0] == 'incrproduct':
                self.checkoutSystem.increment_product(inpsplit[1])
            elif inpsplit[0] == 'decrproduct':
                self.checkoutSystem.decrement_product(inpsplit[1])
            elif inp == 'help':
                commands = [
                    'productlist', 'cartridgeamount [productid]',
                    'incrproduct [productid]', 'decrproduct [productid]',
                    'help', 'exit'
                ]
                methods.print_list('commands', commands)
            elif inp == 'exit':
                break
Exemplo n.º 2
0
    def run(self):
        while True:
            inp = input('input command: ')
            inpsplit = inp.split(' ')

            if inp == 'list':
                methods.print_list('products:', self.get_product_data())
            elif inpsplit[0] == 'et' and len(inpsplit) == 3:
                self.empty_tray(inpsplit[1], inpsplit[2])
            elif inpsplit[0] == 'ft' and len(inpsplit) == 3:
                self.fill_tray(inpsplit[1], inpsplit[2])
            elif inpsplit[0] == 'cs' and len(inpsplit) == 3:
                self.change_stock(inpsplit[1], inpsplit[2])
            elif inp == 'help':
                commands = [
                    'list (show a list of all products in shelves)',
                    'et [productid] [shelfid] (empty tray)',
                    'ft [productid] [shelfid] (fill tray)',
                    'cs [productid] [amount] (change amount in stock)', 'help',
                    'exit'
                ]
                methods.print_list('available commands', commands)
            elif inp == 'exit':
                break
Exemplo n.º 3
0
    def shortest_way_multiple_points(self, node_list):
        permutations = list(itertools.permutations(node_list))
        length = 0
        shortest_permutation = 0
        for permutation in permutations:
            permutation += (0, )
            #print('permutation: ', permutation)
            direction_dicts_list = []
            last_node = 0
            temp_length = 0
            for node_id in permutation:
                curr_dict, distance_list = self.dijkstra(last_node)
                direction_dicts_list.append((node_id, curr_dict))
                last_node = node_id
                temp_length += distance_list[node_id]

            #print('length: ', length, 'temp_length: ', temp_length)
            if temp_length < length or shortest_permutation == 0:
                shortest_permutation = direction_dicts_list
                length = temp_length

        dir_list = []
        for item in shortest_permutation:
            #print('items:', item)
            dir_list.append(self.dijkstra_to_directions(item[0], item[1]))

        methods.print_list('dir_list: ', dir_list)
        for i in range(
                0, len(dir_list)
        ):  #add the initial move command to each of the movement directions array
            if i == 0:  #the first element always starts at 0 and thus needs to add a forward direction to get to 1 from where on the dijkstra will tel the directions
                dir_list[i] = [(((0, 0), (0, 1)), 0)] + dir_list[i]
            index = len(dir_list[i - 1]) - 1
            if type(
                    dir_list[i][0][0]
            ) is int:  #check if the robot needs to only move 1 node, the method dijkstra_to_directions will give only a single tuple back in this case instead of the (((), ()), num), this means that the first element is a int instead of another tuple
                if dir_list[i - 1][index][0][1] == dir_list[i][
                        0]:  #checks if the robot needs to turn 180 degrees or just drive forward
                    dir_list[i] = [((dir_list[i - 1][index][0][1],
                                     dir_list[i][0]), 180)]
                else:
                    dir_list[i] = [((dir_list[i - 1][index][0][1],
                                     dir_list[i][0]), 0)]
            elif i == 0 and type(
                    dir_list[i][1][0]
            ) is int:  #same as previous if statement but filters out if its the first element which would mean that the first if statment has added an item to the list even though the single tuple still needs replacing
                if dir_list[i - 1][index][0][1] == dir_list[i][
                        0]:  #checks if the robot needs to turn 180 degrees or just drive forward
                    dir_list[i] = [((dir_list[i - 1][index][0][1],
                                     dir_list[i][1]), 180)]
                else:
                    dir_list[i] = [((dir_list[i - 1][index][0][1],
                                     dir_list[i][1]), 0)]
            elif not i == 0:  # cant make this an else statement since i need to check both if statements and both if statements also need to be false to be able to do this statement
                if dir_list[i - 1][index][0][1] == dir_list[i][0][0][
                        0]:  #checks if the robot needs to turn 180 degrees or just drive forward
                    dir_list[i] = [((dir_list[i - 1][index][0][1],
                                     dir_list[i][0][0][0]), 180)] + dir_list[i]
                else:
                    dir_list[i] = [((dir_list[i - 1][index][0][1],
                                     dir_list[i][0][0][0]), 0)] + dir_list[i]

            if i == len(
                    dir_list
            ) - 1:  #turn the robot around when arriving back at the starting point
                dir_list[i].append((((0, 0), (0, 0)), 180))

        return shortest_permutation, dir_list
Exemplo n.º 4
0
                    dir_list[i] = [((dir_list[i - 1][index][0][1],
                                     dir_list[i][0][0][0]), 180)] + dir_list[i]
                else:
                    dir_list[i] = [((dir_list[i - 1][index][0][1],
                                     dir_list[i][0][0][0]), 0)] + dir_list[i]

            if i == len(
                    dir_list
            ) - 1:  #turn the robot around when arriving back at the starting point
                dir_list[i].append((((0, 0), (0, 0)), 180))

        return shortest_permutation, dir_list

    def robot_directions(self, node_list):
        return_list = []
        #print('node list:', node_list)
        shortest_permutation, dir_list = self.shortest_way_multiple_points(
            node_list)
        for dir_list in dir_list:
            temp_list = []
            for item in dir_list:
                temp_list.append(item[1])
            return_list.append(temp_list)
        return shortest_permutation, return_list


if __name__ == '__main__':
    finder = PathFinding(DatabaseConnector())
    methods.print_list('path for 19, 20 and 7 is',
                       finder.robot_directions([19, 20, 7]))