# Implementation of module {path_plan}. # Last edited on 2021-10-02 16:32:19 by stolfi def make(OCRS, BCS, CTS, number_lines, mp_cont, mp_jump, parms, test_parms, tag, B, wr): input_data.describe_elis(wr, test_parms['o'], BCS, CTS, OCRS, number_lines, test_parms['delta'], test_parms['max_calls'], parms) org = test_parms['o'] if len(OCRS) > 0 and test_parms['contours']: OCRS = greedy_sort_contours(OCRS, org) path.compute_contour_nesting(OCRS) path.assign_blocks_to_contours(OCRS, BCS) Q = contour_raster_path(OCRS, BCS, CTS, mp_cont, mp_jump, parms, test_parms, tag, B, wr) else: Q = raster_path(org, BCS, CTS, mp_cont, mp_jump, parms, test_parms, tag, B, wr) return Q def greedy_sort_contours(OCRS, org): # Given a list {OCRS} of contours, returns # another list {OCRS_sort} with those contours reordered and cyclically shifted # (by {path.shift_contour}), in an attemt to minimize # the total execution time of the concatenation of those contours, by # a simple greedy heuristic. # # While the paths in {OCRS_sort} share the same moves with those in {OCRS}, # they will have new {Path} objects. Therefore, any information # precomputed with {path.assign_blocks_to_contours} and # {path.compute_contour_nesting} on the list {OCRS} may # will have to be computed again for {OCRS_sort}. OCRS_sort = [] # Contours sorted by greedy min path time. while len(OCRS) > 0: # Assumes that the execution time of a jump is a monotonic # function of the distance, independent of direction: iMin, kMin = path.find_nearest_contour(OCRS, qEnd) ocri = OCRS[iMin] OCRS_aux = OCRS[0:iMin] + OCRS[iMin+1:] ocrk = path.shift_contour(ocri, kMin) OCRS_sort.append(ocrk) org = path.pfin(ocrk) return OCRS_sort # ---------------------------------------------------------------------- def contour_raster_path(OCRS, BCS, CTS, mp_cont, mp_jump, parms, test_parms, tag, B, wr): qEnd = test_parms['o'] OCRS_sort = [] # Contours sorted by greedy min path time. while len(OCRS) > 0: iMin, kMin = path.find_nearest(OCRS, qEnd) ocri = OCRS[iMin] OCRS_aux = OCRS[0:iMin] + OCRS[iMin+1:] OCRS_sort.append(path.shift_contour(ocri, kMin)) BCS = [] while len(OCRS_aux) > 0: ocrMin = contour.nearest(OCRS_aux, qEnd) P = contour.make_path(ocrMin, mp_cont, qEnd) qEnd = path.pfin(P) Q = concat_paths(Q, P, mp_jump) OCRS_aux = remove_contour(OCRS_aux, ocrMin) BCS += contour.get_blocks(ocrMin) CTS = select_contacts(BCS) Q_raster = raster_path(qEnd, BCS, CTS, mp_cont, mp_jump, parms, test_parms, tag, B, wr) Q = concat_paths(Q, Q_raster, mp_jump) Q = path.make_empty(qEnd) return Q def raster_path(qEnd, BCS, CTS, mp_cont, mp_jump, parms, test_parms, tag, B, wr): Q = None if test_parms['heuristic'] == 'original': Q = original_path.make(wr, qEnd, BCS, CTS, mp_jump) elif test_parms['heuristic'] == 'greedy': Q = simple_greedy(wr, qEnd, BCS, CTS, mp_jump) elif test_parms['heuristic'] == 'scan_line': Q = scan_line_path.make(wr, qEnd, BCS_aux, CTS, mp_jump, test_parms['delta'], parms, False) elif test_parms['heuristic'] == 'alternating_scan_line': Q = scan_line_path.make(wr, qEnd, BCS_aux, CTS, mp_jump, test_parms['delta'], parms, True) elif test_parms['heuristic'] == 'hotpath': Q = best_path(qEnd, qEnd, BCS, CTS, mp_cont, mp_jump, test_parms['delta'], test_parms['max_calls'], parms, test_parms['debug'], tag, B, wr) return Q def describe_solution(wr, Qbest, CTS, Delta, o, qEnd, ncalls): wr.write("Delta: %f\n" % Delta) wr.write("StartPoint: ") if o == qEnd: wr.write("Original\n") else: wr.write("New\n") wr.write("ncalls = %d\n" % ncalls) Q_max_rc = contact.max_rcool(Qbest, CTS) wr.write("max_rcool = %.3f\n" % Q_max_rc) Q_fabtime = path.fabtime(Qbest) wr.write("fabtime = %.3f\n" % Q_fabtime) # Report contact coverage and cooling times: wr.write("coverage times and cooling time of each contact\n") for k in range(len(CTS)): ct = CTS[k] wr.write("CTS[%03d] (" % k) tcs = contact.covtimes(Qbest, ct) for i in range(2): wr.write(" "+ (" . " if tcs[i] == None else ("%7.3f" % tcs[i]))) rcool = contact.rcool(Qbest, ct) wr.write(" ) " + (" . " if rcool == None else ("%7.3f" % rcool))) wr.write("\n") wr.write("----------------------------------------------------------------------\n") return