def calculate_gains(circuit: Circuit, data: Data): """ calculate the gain for each node """ for cell in circuit.cells: data.reset_node_gain(cell) F = data.get_node_block_id(cell) # from block id T = (F + 1) % 2 # to block id for net in cell.nets: if data.get_net_distribution(net, F) == 1: data.inc_node_gain(cell) if data.get_net_distribution(net, T) == 0: data.dec_node_gain(cell) data.unlock_node(cell, F)
def move_node_another_block(cell: Cell, data: Data): """ move the max gain node to another block """ F = data.get_node_block_id(cell) # from block id T = (F + 1) % 2 # to block id # lock the node data.lock_node(cell, T) for net in cell.nets: # check critical nets before the move if data.get_net_distribution(net, T) == 0: for nei in net.cells: if data.is_node_unlocked(nei): data.update_node_gain(nei, 1) elif data.get_net_distribution(net, T) == 1: for nei in net.cells: if data.is_node_unlocked(nei) and data.get_node_block_id( nei) == T: data.update_node_gain(nei, -1) # change the net distribution to reflect the move data.dec_net_distribution(net, F) data.inc_net_distribution(net, T) # check the critical nets after the move if data.get_net_distribution(net, F) == 0: for nei in net.cells: if data.is_node_unlocked(nei): data.update_node_gain(nei, -1) elif data.get_net_distribution(net, F) == 1: for nei in net.cells: if data.is_node_unlocked(nei) and data.get_node_block_id( nei) == F: data.update_node_gain(nei, 1) data.update_cutsize_by_gain(cell)
def is_cut(net: Net, data: Data) -> bool: """ :return: True if the given net is a cut, otherwiese False """ return (data.get_net_distribution(net, 0) > 0) and (data.get_net_distribution(net, 1) > 0)