Exemple #1
0
def analyse(in_files: str, out_file: str):
    """
    Creates a summary file for the passed-in in-files, at the out-file
    location. This file summarises all passed-in instances.
    """
    file = Path(out_file)

    if file.exists():
        last_modified = file.lstat().st_mtime
        timestamp = datetime.fromtimestamp(last_modified)

        print(f"Printing {out_file} (last modified {timestamp})")
        instances = pd.read_csv(out_file, skipfooter=1, engine="python")
    else:
        instances = pd.DataFrame()

        for location in glob.iglob(in_files):
            problem = Problem.from_file(location, delimiter=',')
            sol = Solution.from_file(f"solutions/oracs_{problem.instance}.csv")

            instance = dict([(func.__name__, func(sol))
                             for func in PARAMETERS + STATISTICS])

            instances = instances.append(instance, ignore_index=True)

    report = make_pivot_table(instances)

    if not file.exists():
        report.to_csv(out_file)

    print(report)
Exemple #2
0
def compute(parser, args):
    measures = []

    for instance in np.arange(1, 101):
        location = Path(f"experiments/{args.experiment}/"
                        f"{instance}-{args.method}.json")

        if not location.exists():
            print(f"{parser.prog}: {location} does not exist; skipping.")
            continue

        Problem.from_instance(args.experiment, instance)
        sol = Solution.from_file(location)

        measures.append({name: fn(sol) for name, fn in MEASURES.items()})

    return pd.DataFrame.from_records(measures, columns=MEASURES.keys())
Exemple #3
0
def main():
    if len(sys.argv) < 2:
        raise ValueError(f"{sys.argv[0]}: expected file location.")

    problem = Problem.from_file(sys.argv[1], delimiter=',')
    solution = Solution.from_file(f"solutions/oracs_{problem.instance}.csv")

    is_feasible = True

    for idx, rule in enumerate(RULES):
        result, message = rule(solution)

        print(f"{idx}: {message}")

        if not result:
            is_feasible = False

    exit(0 if is_feasible else 1)