# Tools to optimize the handling of moves by the {hotpath} heuristic. # Last edited on 2021-05-22 10:16:39 by jstolfi import move_hp_IMP import move; from move import Move import path; from path import Path import block; from block import Block import move_parms import path import pyx # These prcedures are meant to accelerate the {hotpath} heuristic by # using additional attributes of {Move} objects: either "static" # attributes, that are set only once during pre-processing of the input # data set, and "dynamic" atributes that are modified during the # heuristic. # # These attributes are NOT defined automatically by the functions in the # {move} module. Their values must be initialized by # {preprocess_input_data} and {initialize_state} at the start of the # procedure, and updated as needed by the {set_*} procedures below. # STATIC HOTPATH-RELATED ATTRIBUTES def preprocess_input_data(BCS): # Sets all static {hotpath}-related static attributes of moves given the list # {BCS} of input {block.Block} objects. # # This procedure runs in time proportional to {nmv}, the sum of the move counts # of all choices of all blocks of {BCS}. move_hp_IMP.preprocess_input_data(BCS) def input_paths(omv): # Given a non-jump oriented move {omv}, returns a list {L} of all pairs {(oph,imv)} # where {oph} is a choice of a block of {BCS}, and {path.elem(oph,imv)} is {omv} or # its reverse. # # Note that the same {Move} object often occurs in several choices of the same # block, and each choice will appear in a separate element of {L}. # However, a move must not occur twice in the same path, or in two # difference blocks. # # The procedure returns {None} if {omv} is not a trace, or if neither # it nor its reverse occur in any of he input blocks {BCS}. It runs in # {O(1)} time since it uses information stored in the {Move} object by # {preprocess}. return move_hp_IMP.input_paths(omv) def clear_input_data(BCS): # Clears all the fields that were set by {set_input_data} so that the # {hotpath} heuristic can be run again on a differen input data set. move_hp_IMP.clear_input_data(BCS) # DYNAMIC HOTPATH-RELATED ATTRIBUTES def initialize_state(BCS): # Sets all dynamic {hotath}-related move attributes to their proper # state at the beginning of its execution. # There are no dynamic {hotpath}-related {Move} attributes in this version, # so this procedure is currently a no-op, proveided for documentaton purposes. move_hp_IMP.initialize_state(BCS)