(static, tour_indices, save_path)
Plots the found solution.
Plots the found solution.
Plots the found solution .
def render(static, tour_indices, save_path):
    """Plots the found solution."""

    plt.close('all')

    num_plots = 3 if int(np.sqrt(len(tour_indices))) >= 3 else 1

    _, axes = plt.subplots(nrows=num_plots, ncols=num_plots,
                           sharex='col', sharey='row')

    if num_plots == 1:
        axes = [[axes]]
    axes = [a for ax in axes for a in ax]

    for i, ax in enumerate(axes):

        # Convert the indices back into a tour
        idx = tour_indices[i]
        if len(idx.size()) == 1:
            idx = idx.unsqueeze(0)

        idx = idx.expand(static.size(1), -1)
        data = torch.gather(static[i].data, 1, idx).cpu().numpy()

        start = static[i, :, 0].cpu().data.numpy()
        x = np.hstack((start[0], data[0], start[0]))
        y = np.hstack((start[1], data[1], start[1]))

        # Assign each subtour a different colour & label in order traveled
        idx = np.hstack((0, tour_indices[i].cpu().numpy().flatten(), 0))
        where = np.where(idx == 0)[0]

        for j in range(len(where) - 1):

            low = where[j]
            high = where[j + 1]

            if low + 1 == high:
                continue

            ax.plot(x[low: high + 1], y[low: high + 1], zorder=1, label=j)

        ax.legend(loc="upper right", fontsize=3, framealpha=0.5)
        ax.scatter(x, y, s=4, c='r', zorder=2)
        ax.scatter(x[0], y[0], s=20, c='k', marker='*', zorder=3)

        ax.set_xlim(0, 1)
        ax.set_ylim(0, 1)

    plt.tight_layout()
    plt.savefig(save_path, bbox_inches='tight', dpi=200)
def render ( static , tour_indices , save_path ) : plt . close ( 'all' ) num_plots = 3 if int ( np . sqrt ( len ( tour_indices ) ) ) >= 3 else 1 _ , axes = plt . subplots ( nrows = num_plots , ncols = num_plots , sharex = 'col' , sharey = 'row' ) if num_plots == 1 : axes = [ [ axes ] ] axes = [ a for ax in axes for a in ax ] for i , ax in enumerate ( axes ) : # Convert the indices back into a tour idx = tour_indices [ i ] if len ( idx . size ( ) ) == 1 : idx = idx . unsqueeze ( 0 ) idx = idx . expand ( static . size ( 1 ) , - 1 ) data = torch . gather ( static [ i ] . data , 1 , idx ) . cpu ( ) . numpy ( ) start = static [ i , : , 0 ] . cpu ( ) . data . numpy ( ) x = np . hstack ( ( start [ 0 ] , data [ 0 ] , start [ 0 ] ) ) y = np . hstack ( ( start [ 1 ] , data [ 1 ] , start [ 1 ] ) ) # Assign each subtour a different colour & label in order traveled idx = np . hstack ( ( 0 , tour_indices [ i ] . cpu ( ) . numpy ( ) . flatten ( ) , 0 ) ) where = np . where ( idx == 0 ) [ 0 ] for j in range ( len ( where ) - 1 ) : low = where [ j ] high = where [ j + 1 ] if low + 1 == high : continue ax . plot ( x [ low : high + 1 ] , y [ low : high + 1 ] , zorder = 1 , label = j ) ax . legend ( loc = "upper right" , fontsize = 3 , framealpha = 0.5 ) ax . scatter ( x , y , s = 4 , c = 'r' , zorder = 2 ) ax . scatter ( x [ 0 ] , y [ 0 ] , s = 20 , c = 'k' , marker = '*' , zorder = 3 ) ax . set_xlim ( 0 , 1 ) ax . set_ylim ( 0 , 1 ) plt . tight_layout ( ) plt . savefig ( save_path , bbox_inches = 'tight' , dpi = 200 )