Exemplo n.º 1
0
def main():
    try:
        solve()
    except KeyboardInterrupt:
        print('\nKeyboardInterrupt handled')
    except:
        print('Form issue in equation.')
Exemplo n.º 2
0
    def test_low_corrected_weight(self):
        with self.assertRaises(ParseException) as cm:
            solve('invalid_inputs/low_corrected_weight', self.TEST_FILE)

        self.assertTrue(
            cm.exception.msg.startswith(
                ErrorMessages.LOW_CORRECTED_WEIGHT[:10]))
def main():
    argc = len(sys.argv)
    if argc < 2:
        print(
            'Use "python minesweeper.py <input filename> [<output filename>=\'out\']"'
        )
        return

    input_file = sys.argv[1]
    output_file = sys.argv[2] if argc > 2 else 'out'
    try:
        solve(input_file, output_file)
    except ParseException as e:
        print(e.msg)
        return
    except SolveException as e:
        print(e.msg)
        return
    except FileNotFoundError:
        print('No such file')
        return
Exemplo n.º 4
0
def solve_task(task):
    time_list = list()
    iter_param = list()
    block_param = list()
    schedule_list = list()
    start = time.time()
    machines = list()
    for i in range(task.machine_count):
        machines.append(Machine(i))
    schedule = Schedule(task.jobs, machines)

    # try some parameters to compare wich is faster
    for i in range(from_iteration, to_iterations):
        for block in range(from_block_time, to_block_time):
            start = time.time()
            schedule_list.append(solve(schedule, i, block))
            end = time.time()
            time_list.append(end - start)
            iter_param.append(i)
            block_param.append(block)
        # print(f"Iteration with {i} Iterations is over")

    shortest_schedule = min(schedule_list)
    shortest_schedule_indizes = list()
    # search for all the schedules that have same (minimal) length
    for x in schedule_list:
        if shortest_schedule == x:
            shortest_schedule_indizes.append(schedule_list.index(x))

    # list the times that the shortest schedules needed to compute
    shortest_times = list()
    for i in range(0, len(time_list) - 1):
        if i in shortest_schedule_indizes:
            shortest_times.append(time_list[i])

    # get shortest needed time
    shortest_time = min(shortest_times)
    # get shortest schedule with smallest time needed
    fastest_schedule_index = time_list.index(shortest_time)
    stop = time.time()
    print(f"finisch task {task.name} in {stop-start}s")
    print(f"Fastest Schedule drawn took {shortest_time}s " +
          f"to calculate and had follwoing params:")
    print(f"Iterations: {iter_param[fastest_schedule_index]}")
    print(f"Block length: {block_param[fastest_schedule_index]}")
    print(schedule_list[fastest_schedule_index])
    def test_correct_program_output(self):
        solve('inputs/000', FunctionalTest.TEST_FILE)
        self.assertTrue(filecmp.cmp('outputs/000', FunctionalTest.TEST_FILE, shallow=False))

        solve('inputs/001', FunctionalTest.TEST_FILE)
        self.assertTrue(filecmp.cmp('outputs/001', FunctionalTest.TEST_FILE, shallow=False))

        solve('inputs/002', FunctionalTest.TEST_FILE)
        self.assertTrue(filecmp.cmp('outputs/002', FunctionalTest.TEST_FILE, shallow=False))

        solve('inputs/003', FunctionalTest.TEST_FILE)
        self.assertTrue(filecmp.cmp('outputs/003', FunctionalTest.TEST_FILE, shallow=False))

        solve('inputs/004', FunctionalTest.TEST_FILE)
        self.assertTrue(filecmp.cmp('outputs/004', FunctionalTest.TEST_FILE, shallow=False))

        solve('inputs/005', FunctionalTest.TEST_FILE)
        self.assertTrue(filecmp.cmp('outputs/005', FunctionalTest.TEST_FILE, shallow=False))
Exemplo n.º 6
0
from src.solver import solve, equations

names = list(equations.keys())

print('Welcome!')

for number, name in enumerate(names, start=1):
    print('\t%d: %s' % (number, name))

while True:
    choice = input('Tenliyi sec >>> ')

    try:
        choice = int(choice)
    except ValueError:
        print('Reqem daxil et')
        continue

    try:
        x = solve(names[choice - 1])
    except IndexError:
        print('Sece bilersen %d den %d ye kimi' % (1, len(names)))
        continue

    print(x)
Exemplo n.º 7
0
from src.solver import solve
from src.defines import VALID_MOVES

error_snapshot = [
    5, 5, 5, 2, 0, 5, 4, 1, 4, 0, 4, 2, 0, 1, 3, 3, 0, 3, 4, 3, 1, 0, 2, 5, 2,
    1, 1, 0, 0, 0, 3, 3, 1, 5, 4, 2, 1, 4, 0, 2, 4, 4, 2, 5, 5, 4, 2, 3, 1, 5,
    3, 3, 2, 1
]
cube = Rubik()
cube.restore_snapshot(error_snapshot)
value = ''
while (True):
    cube.draw(-150, 50, 50)
    print()
    print("[enter valid move or: scramble, solve, exit]")
    value = input("Enter move: ")
    if value == "solve":
        solve(cube)
    elif value == "scramble":
        cube.scramble(25, verbose=True)
    elif value == "exit":
        break
    elif value == "eval":
        solve(cube, eval=True)
    else:
        for move in value.split():
            if move in VALID_MOVES:
                cube.move(move)
            else:
                print("Incorrect move:", move)
Exemplo n.º 8
0
import yaml
import os.path
from src.parser import parse
from src.solver import solve

for x in range(1,5):
  file_path = "%s.yaml" % x
  if os.path.exists(file_path):
    tree = parse(file_path)
    ans = solve(tree)
    print "Solution to problem %s is %s" % (x, ans)
Exemplo n.º 9
0
    def test_negative_weight(self):
        with self.assertRaises(ParseException) as cm:
            solve('invalid_inputs/negative_weight', self.TEST_FILE)

        self.assertTrue(
            cm.exception.msg.startswith(ErrorMessages.UNKNOWN_SYMBOL[:10]))
Exemplo n.º 10
0
    def test_too_big_weight(self):
        with self.assertRaises(ParseException) as cm:
            solve('invalid_inputs/too_big_weight', self.TEST_FILE)

        self.assertTrue(
            cm.exception.msg.startswith(ErrorMessages.WEIGHT_BOUNDS[:10]))
Exemplo n.º 11
0
    def test_unknown_symbol(self):
        with self.assertRaises(ParseException) as cm:
            solve('invalid_inputs/unknown_symbol', self.TEST_FILE)

        self.assertTrue(
            cm.exception.msg.startswith(ErrorMessages.UNKNOWN_SYMBOL[:10]))
Exemplo n.º 12
0
    def test_short_row(self):
        with self.assertRaises(ParseException) as cm:
            solve('invalid_inputs/short_row', self.TEST_FILE)

        self.assertTrue(
            cm.exception.msg.startswith(ErrorMessages.SHORT_ROW[:20]))
Exemplo n.º 13
0
    def test_negative_properties(self):
        with self.assertRaises(ParseException) as cm:
            solve('invalid_inputs/negative_properties', self.TEST_FILE)

        self.assertEqual(ErrorMessages.NEGATIVE_PROPERTIES, cm.exception.msg)
Exemplo n.º 14
0
    def test_too_many_properties(self):
        with self.assertRaises(ParseException) as cm:
            solve('invalid_inputs/too_many_properties', self.TEST_FILE)

        self.assertEqual(ErrorMessages.PROPERTIES, cm.exception.msg)
Exemplo n.º 15
0
    data_source = None
    try:
        if args.input_mode == "cmd":
            if not args.numbers_lists:
                logger.info(
                    f"EXIT - Please specify input data with the argument --l for the cmd input mode"
                )
                exit(1)
            data_source = CmdInput(args.numbers_lists)
        elif args.input_mode == "file":
            data_source = FileInput(args.file_path)

        if data_source is None:
            logger.error("Exit - Cannot get input data")
            exit(1)

    except Exception:
        exit(1)

    return strategy, data_source


if __name__ == "__main__":
    logger.info("START")
    arguments = get_console_arguments()
    logger.info(pretty_args(arguments.__dict__))
    processed_args = process_args(arguments)  # Process console arguments
    solve(*processed_args)  # Solve puzzle
    logger.info("DONE")