def parse_pomdp_solve_output(alpha_path, pg_path=None):
    """Parse the output of pomdp_solve, given
    by an .alpha file and a .pg file.

    Given a path to a .alpha file, read and interpret its contents.
    The file formats are specified at:
    https://www.pomdp.org/code/alpha-file-spec.html
    https://www.pomdp.org/code/pg-file-spec.html

    Note on policy graph (from the official website): To use this first requires
    knowing which of the policy graph states to start in. This can be achieved
    by finding the alpha vector with the maximal dot product with the initial
    starting state.

    Note: Parsing the .alpha file is required. The .pg path is optional (this
        is because I noticed some errors in the .pg file produced)

    Returns:
        alphas: [(alpha_vector, action_number) ...]
        policy_graph: a mapping from node number to (action_number, edges)
    """
    alphas = []  # (alpha_vector, action_number) tuples
    with open(alpha_path, 'r') as f:
        action_number = None
        alpha_vector = None
        mode = "action"
        for line in f:
            line = line.rstrip()
            if len(line) == 0:
                continue

            if mode == "action":
                action_number = int(line)
                mode = "alpha"
            elif mode == "alpha":
                alpha_vector = tuple(map(float, line.split(" ")))
                alphas.append((alpha_vector, action_number))
                mode = "action"
                action_number = None
                alpha_vector = None

    policy_graph = {}  # a mapping from node number to (action_number, edges)
    if pg_path is None:
        return alphas
    else:
        with open(pg_path, 'r') as f:
            for line in f:
                line = line.rstrip()
                if len(line) == 0:
                    continue
                parts = list(map(int, line.split()))  # Splits on whitespace
                assert parts[0] not in policy_graph,\
                    "The node id %d already exists. Something wrong" % parts[0]
                policy_graph[parts[0]] = (parts[1], parts[2:])
        return alphas, policy_graph