Esempio n. 1
0
def main():
    """Main function"""

    # Dictionary that stores all the nodes of the graph
    # in which the keys are the nodes' IDs
    dataNodes = {}

    # Readin data
    readInput(dataNodes)

    # Using Greedy algorithm
    Greedy.greedySearch(dataNodes, INITIAL_NODE, FINAL_NODE)

    # Using A* algorithm
    AStar.aStarSearch(dataNodes, INITIAL_NODE, FINAL_NODE)
Esempio n. 2
0
def run(args, argv):
    # Parse Values
    row = 3
    col = 3
    mult = 1 / max(row, col)
    const = (RUN_CONSTANT // max(row, col)) + 1
    dictname = 'default_dict.txt'
    exportname = None

    index = 2
    #print(args)
    while index < args:
        # parse tags
        tag = argv[index]
        index += 1
        if tag == '-r' or tag == '--row':  # SET ROW LENGTH
            if index == args:
                print('No value given for row')
                return
            try:
                row = int(argv[index])
            except ValueError:
                print(  # ERROR: param not integer
                    f'Error setting row: \'{argv[index]}\' not integer.')
                return
        elif tag == '-c' or tag == '--col':  # SET COL LENGTH
            if index == args:
                print('No value given for column')
                return
            try:
                col = int(argv[index])
            except ValueError:
                print(  # ERROR: param not integer
                    f'Error setting col: \'{argv[index]}\' not integer.')
                return
        elif tag == '-k' or tag == '--ChoiceConstant':  # SET CONSTANT
            if index == args:
                print('No value given for column')
                return
            try:
                const = int(argv[index])
            except ValueError:
                print(  # ERROR: param not integer
                    f'Error setting col: \'{argv[index]}\' not integer.')
                return
        elif tag == '-m' or tag == '--ChoiceMultiplier':  # SET MULTIPLIER
            if index == args:
                print('No value given for column')
                return
            try:
                mult = int(argv[index])
            except ValueError:
                print(  # ERROR: param not integer
                    f'Error setting col: \'{argv[index]}\' not integer.')
                return
        elif tag == '-d' or tag == '--dictionary':  # SET BACKING DICTIONARY
            if index == args:
                print('No value given for dictionary')
                return
            dictname = argv[index]
        elif tag == '-e' or tag == '--export':  # SET EXPORT FILE
            if index == args:
                print('No value given for export file')
                return
            exportname = argv[index]
        else:  # INCORRECT TAG (ERROR)
            print(f'Tag \'{tag}\' does not exist.')
            print()
            help_run()
            return
        index += 1

    # Setup run
    dictionary = WordFinder.WordFinder()
    try:
        dictionary.importFromFile(dictname, max(row, col))
    except FileNotFoundError:
        print(f'Error reading dictionary: File {dictname} could not be read.')
        return

    # print(f'{row}, {col}')
    grid, iterations = AStar.aStarSearch(Grid.Grid(row, col),
                                         dictionary,
                                         choiceMin=const,
                                         choiceMult=mult)
    if exportname is None:
        print(f'Crossword created after {iterations} iterations.')
        print(str(grid))
    else:
        export(exportname)