print_input_footer(num_verts, num_edges, about, out) print_if_not_quiet('graph saved to ' + ppinput(options.output_file)) if out != sys.stdout: out.close() # generate output with correctness checker, if desired if options.correctness: if options.dont_track: print >> sys.stderr, "warning: skipping correctness output (only done when -t is not specified)" return 0 try: mst_weight = compute_mst_weight(options.output_file) except CheckerError, e: print >> sys.stderr, e # record this new input in our input log if not options.dont_track: data = InputSolution(options.precision, dimensionality, min_val, max_val, num_verts, num_edges, __RND_SEED, mst_weight) path = data.get_path( ) if options.inputs_list_file is None else options.inputs_list_file DataSet.add_data_to_log_file(data, path) print_if_not_quiet('logged to ' + path) return 0 if __name__ == "__main__": sys.exit(main())
str_ans_corr = fmt % ans_corr str_ans_out = fmt % ans_out if str_ans_corr == str_ans_out: outcome = CORRECT else: print >> sys.stderr, "correctness FAILED: %s (correct is %s, output had %s)" % (ppinput(input_graph), str_ans_corr, str_ans_out) outcome = INCORRECT # log the result of the correctness check if rev is not None and run is not None: if ti is None: ti = __get_ti(input_graph) data = CorrResult(ti.dims, ti.min, ti.max, ti.num_verts, ti.num_edges, ti.seed, rev, run, outcome) try: DataSet.add_data_to_log_file(data) print 'logged correctness result to ' + data.get_path() except DataError, e: fmt = "Unable to log result to file %s (correct is %s, output had %s): %s" print >> sys.stderr, fmt % (ppinput(input_graph), str_ans_corr, str_ans_out, e) return outcome def main(argv=sys.argv[1:]): usage = """usage: %prog [options] INPUT_GRAPH OUTPUT_TO_CHECK Checks the validity of an MST. Exits with code 0 on success. Otherwise, it prints an error message and exits with a non-zero code. Does not log the result.""" parser = OptionParser(usage) parser.add_option("-f", "--force-recompute", action="store_true", default=False, help="recomputes the MST weight with the checker even if we have a cached value")
mst_weight = -1 if options.dont_generate: print_if_not_quiet('graph not saved (as requested)') else: print_input_footer(num_verts, num_edges, about, out) print_if_not_quiet('graph saved to ' + ppinput(options.output_file)) if out != sys.stdout: out.close() # generate output with correctness checker, if desired if options.correctness: if options.dont_track: print >> sys.stderr, "warning: skipping correctness output (only done when -t is not specified)" return 0 try: mst_weight = compute_mst_weight(options.output_file) except CheckerError, e: print >> sys.stderr, e # record this new input in our input log if not options.dont_track: data = InputSolution(options.precision, dimensionality, min_val, max_val, num_verts, num_edges, __RND_SEED, mst_weight) path = data.get_path() if options.inputs_list_file is None else options.inputs_list_file DataSet.add_data_to_log_file(data, path) print_if_not_quiet('logged to ' + path) return 0 if __name__ == "__main__": sys.exit(main())