Ejemplo n.º 1
0
    print("j: ", j)
    fig, ax = plt.subplots()
    ax.set_aspect(aspect=1)
    #vis.lattice_grid(N,1,ax)#vis.lattice_grid(N,2,ax)

    #site = int(input("ch: "))#rd.randint(0,2*N+2)
    site = rd.randint(0, 2 * N + 2)
    #print(site)
    update_anim(site, ax)
    #print(update_par(site, 1,1,1,1,1,1,1,1))
    #print(stuck_position())
    DisplayNice()

    positions1_1, positions1_2, positions2_2, positions2_1 = vis.lattice2positions(
        L1, L2, ax)
    vis.lattice_points(positions1_1, 0, "b", ax)
    vis.lattice_points(positions1_2, 0, "r", ax)
    vis.lattice_points(N - 1 - positions2_2, 1, "r",
                       ax)  #to flip it N-1-positions_vect
    vis.lattice_points(N - 1 - positions2_1, 1, "b", ax)
    plt.close('all')
    #outpath = '../../img/visualiser/'
    #plt.savefig(path.join(outpath,"%s-.png"%(j)))###
    #j+=1###
'''
    positions1_1, positions1_2, positions2_2, positions2_1 = vis.lattice2positions(L1, L2,ax)
    vis.lattice_points(positions1_1, 0, "b", ax)
    vis.lattice_points(positions1_2, 0, "r", ax)
    vis.lattice_points(N-1-positions2_2, 1, "r", ax)#to flip it N-1-positions_vect
    vis.lattice_points(N-1-positions2_1, 1, "b", ax)
Ejemplo n.º 2
0
def update_anim(i, ax):
    global j
    #insertion a1
    if i == 0:
        if L1[0] == 0 and rd.rand() < a1:

            for k in range(frames):
                '''
                fig, ax = plt.subplots()
                ax.set_aspect(aspect=1)
                vis.lattice_grid(N,2,ax)

                positions1_1, positions1_2, positions2_2, positions2_1 = vis.lattice2positions(L1, L2,ax)
                '''
                L1[0] = 1
                positions1_1, positions1_2, positions2_2, positions2_1, ax = plot_init(
                )

                vis.lattice_points(positions1_2, 0, "r", ax)
                vis.lattice_points(N - 1 - positions2_2, 1, "r",
                                   ax)  #to flip it N-1-positions_vect
                vis.lattice_points(N - 1 - positions2_1, 1, "b", ax)
                positions1_1[0] = positions1_1[0] - 1 + (k + 1) / frames
                vis.lattice_points(positions1_1, 0, "b", ax)

                outpath = '../../img/visualiser/'
                plt.savefig(path.join(outpath, "%s-.png" % (j)))
                j += 1

            plt.close('all')

    #in case there site = 1 there is particle 2 which should leave
    elif i == 1 and L1[0] == 2 and rd.rand(
    ) < b2:  #in case there is particle 2 it leaves
        for k in range(frames):
            positions1_1, positions1_2, positions2_2, positions2_1, ax = plot_init(
            )

            vis.lattice_points(positions1_1, 0, "b", ax)
            vis.lattice_points(N - 1 - positions2_2, 1, "r", ax)
            vis.lattice_points(N - 1 - positions2_1, 1, "b", ax)
            positions1_2[-1] = positions1_2[-1] - (k + 1) / frames
            vis.lattice_points(positions1_2, 0, "r", ax)

            outpath = '../../img/visualiser/'
            plt.savefig(path.join(outpath, "%s-.png" % (j)))
            j += 1
        L1[0] = 0
        plt.close('all')

    #insertion a2
    elif i == N + 1:
        if L2[0] == 0 and rd.rand() < a2:
            L2[0] = 2
            for k in range(frames):
                positions1_1, positions1_2, positions2_2, positions2_1, ax = plot_init(
                )

                vis.lattice_points(positions1_1, 0, "b", ax)
                vis.lattice_points(positions1_2, 0, "r", ax)
                vis.lattice_points(N - 1 - positions2_1, 1, "b", ax)
                positions2_2[0] = positions2_2[0] - 1 + (k + 1) / frames
                vis.lattice_points(N - 1 - positions2_2, 1, "r", ax)

                outpath = '../../img/visualiser/'
                plt.savefig(path.join(outpath, "%s-.png" % (j)))
                j += 1

            plt.close('all')
    #in case site = 2N+1 and there is particle 1 it leaves
    elif i == N + 2 and L2[0] == 1 and rd.rand(
    ) < b2:  #in case there is particle 1 it leaves

        for k in range(frames):
            positions1_1, positions1_2, positions2_2, positions2_1, ax = plot_init(
            )

            vis.lattice_points(positions1_1, 0, "b", ax)
            vis.lattice_points(positions1_2, 0, "r", ax)
            vis.lattice_points(N - 1 - positions2_2, 1, "r", ax)
            positions2_1[-1] = positions2_1[-1] - (k + 1) / frames
            vis.lattice_points(N - 1 - positions2_1, 1, "b", ax)

            outpath = '../../img/visualiser/'
            plt.savefig(path.join(outpath, "%s-.png" % (j)))
            j += 1
        L2[0] = 0
        plt.close('all')
    #removal b1
    elif i == N and rd.rand() < b1:
        if L1[-1] > 0:

            for k in range(frames):
                positions1_1, positions1_2, positions2_2, positions2_1, ax = plot_init(
                )

                vis.lattice_points(N - 1 - positions2_2, 1, "r", ax)
                vis.lattice_points(positions1_2, 0, "r", ax)
                vis.lattice_points(N - 1 - positions2_1, 1, "b", ax)
                if np.size(positions1_1) > 0:
                    positions1_1[-1] = positions1_1[-1] + (k + 1) / frames
                vis.lattice_points(positions1_1, 0, "b", ax)

                outpath = '../../img/visualiser/'
                plt.savefig(path.join(outpath, "%s-.png" % (j)))
                j += 1
            L1[-1] = 0
            plt.close('all')
    #removal b2
    elif i == 2 * N + 1 and rd.rand() < b2:
        if L2[-1] > 0:
            for k in range(frames):
                positions1_1, positions1_2, positions2_2, positions2_1, ax = plot_init(
                )

                vis.lattice_points(positions1_1, 0, "b", ax)
                vis.lattice_points(positions1_2, 0, "r", ax)
                vis.lattice_points(N - 1 - positions2_1, 1, "b", ax)
                if np.size(positions2_2) > 0:
                    positions2_2[-1] = positions2_2[-1] + (k + 1) / frames
                vis.lattice_points(N - 1 - positions2_2, 1, "r", ax)

                outpath = '../../img/visualiser/'
                plt.savefig(path.join(outpath, "%s-.png" % (j)))
                j += 1
            L2[-1] = 0
            plt.close('all')
    #regular site lattice 1
    elif i > 0 and i < N:
        i = i - 1
        #update particle 1
        if L1[i] == 1:
            #make a step
            if L1[i + 1] == 0 and rd.rand() < k11:
                for k in range(frames):
                    positions1_1, positions1_2, positions2_2, positions2_1, ax = plot_init(
                    )

                    vis.lattice_points(N - 1 - positions2_2, 1, "r", ax)
                    vis.lattice_points(positions1_2, 0, "r", ax)
                    vis.lattice_points(N - 1 - positions2_1, 1, "b", ax)
                    if np.size(positions1_1) > 0:
                        ind = np.where(positions1_1 == i)
                        positions1_1[ind] = positions1_1[ind] + (k +
                                                                 1) / frames
                    vis.lattice_points(positions1_1, 0, "b", ax)

                    outpath = '../../img/visualiser/'
                    plt.savefig(path.join(outpath, "%s-.png" % (j)))
                    j += 1
                L1[i] = 0
                L1[i + 1] = 1
                plt.close('all')

            #overtake
            elif L1[i + 1] > 0 and L2[-i - 2] == 0 and rd.rand() < k12:
                for k in range(frames):
                    positions1_1, positions1_2, positions2_2, positions2_1, ax = plot_init(
                    )

                    vis.lattice_points(N - 1 - positions2_2, 1, "r", ax)
                    vis.lattice_points(positions1_2, 0, "r", ax)
                    vis.lattice_points(N - 1 - positions2_1, 1, "b", ax)
                    if np.size(positions1_1) > 0:
                        ind = np.where(positions1_1 == i)
                        positions1_1[ind] = positions1_1[ind] + (k +
                                                                 1) / frames
                        vis.lattice_points(positions1_1[ind], (k + 1) / frames,
                                           "b", ax)
                    vis.lattice_points(np.delete(positions1_1, ind), 0, "b",
                                       ax)
                    outpath = '../../img/visualiser/'
                    plt.savefig(path.join(outpath, "%s-.png" % (j)))
                    j += 1
                L1[i] = 0
                L2[-i - 2] = 1
                plt.close('all')

        #update particle 2
        if L1[i] == 2:

            #finish overtaking
            if L2[-i] == 0 and rd.rand() < k21:

                for k in range(frames):
                    positions1_1, positions1_2, positions2_2, positions2_1, ax = plot_init(
                    )

                    vis.lattice_points(N - 1 - positions2_2, 1, "r", ax)
                    vis.lattice_points(positions1_1, 0, "b", ax)
                    vis.lattice_points(N - 1 - positions2_1, 1, "b", ax)
                    if np.size(positions1_2) > 0:
                        ind = np.where(positions1_2 == i)
                        positions1_2[ind] = positions1_2[ind] - (k +
                                                                 1) / frames
                        vis.lattice_points(positions1_2[ind], (k + 1) / frames,
                                           "r", ax)
                    vis.lattice_points(np.delete(positions1_2, ind), 0, "r",
                                       ax)
                    outpath = '../../img/visualiser/'
                    plt.savefig(path.join(outpath, "%s-.png" % (j)))
                    j += 1

                L1[i] = 0
                L2[-i] = 2
                plt.close('all')
            #continue in the opposite lane
            elif L1[i - 1] == 0 and rd.rand() < k21:
                for k in range(frames):
                    positions1_1, positions1_2, positions2_2, positions2_1, ax = plot_init(
                    )

                    vis.lattice_points(N - 1 - positions2_2, 1, "r", ax)
                    vis.lattice_points(positions1_2, 0, "r", ax)
                    vis.lattice_points(N - 1 - positions2_1, 1, "b", ax)
                    if np.size(positions1_1) > 0:
                        ind = np.where(positions1_1 == i)
                        positions1_1[ind] = positions1_1[ind] + (k +
                                                                 1) / frames
                    vis.lattice_points(positions1_2, 0, "b", ax)

                    outpath = '../../img/visualiser/'
                    plt.savefig(path.join(outpath, "%s-.png" % (j)))
                    j += 1
                L1[i] = 0
                L1[i - 1] = 2
                plt.close('all')
    #regular site lattice 2
    elif i > N:
        i = i - N - 2
        print(i)
        assert (i >= 0)
        assert (i <= N)

        #update particle 2
        if L2[i] == 2:
            #make a step
            if L2[i + 1] == 0 and rd.rand() < k22:
                for k in range(frames):
                    positions1_1, positions1_2, positions2_2, positions2_1, ax = plot_init(
                    )

                    vis.lattice_points(positions1_1, 0, "b", ax)
                    vis.lattice_points(positions1_2, 0, "r", ax)
                    vis.lattice_points(N - 1 - positions2_1, 1, "b", ax)
                    if np.size(positions2_2) > 0:
                        ind = np.where(positions2_2 == i)
                        positions2_2[ind] = positions2_2[ind] + (k +
                                                                 1) / frames
                    vis.lattice_points(N - 1 - positions2_2, 1, "r", ax)

                    outpath = '../../img/visualiser/'
                    plt.savefig(path.join(outpath, "%s-.png" % (j)))
                    j += 1
                L2[i] = 0
                L2[i + 1] = 2
                plt.close('all')
            #overtake
            elif L2[i + 1] > 0 and L1[-i - 2] == 0 and rd.rand() < k21:
                for k in range(frames):
                    positions1_1, positions1_2, positions2_2, positions2_1, ax = plot_init(
                    )

                    vis.lattice_points(positions1_1, 0, "b", ax)
                    vis.lattice_points(positions1_2, 0, "r", ax)
                    vis.lattice_points(N - 1 - positions2_1, 1, "b", ax)
                    if np.size(positions2_2) > 0:
                        ind = np.where(positions2_2 == i)
                        positions2_2[ind] = positions2_2[ind] + (k +
                                                                 1) / frames
                        vis.lattice_points(N - 1 - positions2_2[ind],
                                           1 - (k + 1) / frames, "r", ax)
                    vis.lattice_points(N - 1 - np.delete(positions2_2, ind), 1,
                                       "r", ax)
                    outpath = '../../img/visualiser/'
                    plt.savefig(path.join(outpath, "%s-.png" % (j)))
                    j += 1
                L2[i] = 0
                L1[-i - 2] = 2
                plt.close('all')
        #update particle 1
        if L2[i] == 1:
            #finish overtaking
            if L1[-i] == 0 and rd.rand() < k12:
                for k in range(frames):
                    positions1_1, positions1_2, positions2_2, positions2_1, ax = plot_init(
                    )

                    vis.lattice_points(N - 1 - positions2_2, 1, "r", ax)
                    vis.lattice_points(positions1_1, 0, "b", ax)
                    vis.lattice_points(positions1_2, 0, "r", ax)
                    if np.size(positions2_1) > 0:
                        ind = np.where(positions2_1 == i)
                        positions2_1[ind] = positions2_1[ind] - (k +
                                                                 1) / frames
                        vis.lattice_points(N - 1 - positions2_1[ind],
                                           1 - (k + 1) / frames, "b", ax)
                    vis.lattice_points(N - 1 - np.delete(positions2_1, ind), 1,
                                       "b", ax)
                    outpath = '../../img/visualiser/'
                    plt.savefig(path.join(outpath, "%s-.png" % (j)))
                    j += 1
                L2[i] = 0
                L1[-i] = 1
                plt.close('all')

            #continue in the opposite lane
            elif L2[i - 1] == 0 and rd.rand() < k12:
                if not i == 0:
                    for k in range(frames):
                        positions1_1, positions1_2, positions2_2, positions2_1, ax = plot_init(
                        )

                        vis.lattice_points(N - 1 - positions2_2, 1, "r", ax)
                        vis.lattice_points(positions1_1, 0, "b", ax)
                        vis.lattice_points(positions1_2, 0, "r", ax)
                        if np.size(positions2_1) > 0:
                            ind = np.where(positions2_1 == i)
                            positions2_1[ind] = positions2_1[ind] - (
                                k + 1) / frames
                            vis.lattice_points(N - 1 - positions2_1[ind], 1,
                                               "b", ax)
                        vis.lattice_points(
                            np.delete(N - 1 - positions2_1, ind), 1, "b", ax)
                        outpath = '../../img/visualiser/'
                        plt.savefig(path.join(outpath, "%s-.png" % (j)))
                        j += 1
                    L2[i] = 0
                    L2[i - 1] = 1
                    plt.close('all')
Ejemplo n.º 3
0
def update_anim(i, ax1, ax2):
    global j

    #insertion a1
    if i == 0:
        if L1[0] == 0 and rd.rand() < a1:

            for k in range(frames):
                '''
                fig, ax = plt.subplots()
                ax.set_aspect(aspect=1)
                vis.lattice_grid(N,2,ax)

                positions1_1, positions1_2, positions2_2, positions2_1 = vis.lattice2positions(L1, L2,ax)
                '''
                L1[0] = 1
                positions1_1, positions1_2, positions2_2, positions2_1, fig, ax1, ax2 = plot_init(
                )

                vis.lattice_points(positions1_2, 0, "r", ax1)
                vis.lattice_points(N - 1 - positions2_2, 1, "r",
                                   ax1)  #to flip it N-1-positions_vect
                vis.lattice_points(N - 1 - positions2_1, 1, "b", ax1)
                positions1_1[0] = positions1_1[0] - 1 + (k + 1) / frames
                vis.lattice_points(positions1_1, 0, "b", ax1)

                #density plotting
                fig.suptitle(
                    'Two way lattice visualisation and corresponding density profile, sites=%s  \n parameters:  a1=%s, b1=%s, a2=%s, b2=%s, \n k11=%s, k12=%s, k22=%s, k21=%s'
                    % (N, a1, b1, a2, b2, k11, k12, k22, k21))
                ax2.plot(range(1, N + 1),
                         densities1,
                         linestyle='-',
                         color='blue',
                         label='Lattice 1')
                ax2.plot(range(1, N + 1),
                         np.flip(densities2),
                         linestyle='-',
                         color='red',
                         label='Lattice 2')
                ax2.set_ylim([d_low, d_high])
                #ax2.set_ylim([0,1.0])
                #ax2.set_xlim([0,N])
                ax2.set_xlabel('site')
                ax2.set_ylabel('average occupancy')
                ax2.legend(loc=1)

                outpath = '../../img/visualiser/'
                plt.savefig(path.join(outpath, "%s-.png" % (j)))
                j += 1

            plt.close('all')

    #in case there site = 1 there is particle 2 which should leave
    elif i == 1 and L1[0] == 2 and rd.rand(
    ) < b2:  #in case there is particle 2 it leaves
        for k in range(frames):
            positions1_1, positions1_2, positions2_2, positions2_1, fig, ax1, ax2 = plot_init(
            )

            vis.lattice_points(positions1_1, 0, "b", ax1)
            vis.lattice_points(N - 1 - positions2_2, 1, "r", ax1)
            vis.lattice_points(N - 1 - positions2_1, 1, "b", ax1)
            positions1_2[-1] = positions1_2[-1] - (k + 1) / frames
            vis.lattice_points(positions1_2, 0, "r", ax1)

            #density plotting
            fig.suptitle(
                'Two way lattice visualisation and corresponding density profile, sites=%s  \n parameters:  a1=%s, b1=%s, a2=%s, b2=%s, \n k11=%s, k12=%s, k22=%s, k21=%s'
                % (N, a1, b1, a2, b2, k11, k12, k22, k21))
            ax2.plot(range(1, N + 1),
                     densities1,
                     linestyle='-',
                     color='blue',
                     label='Lattice 1')
            ax2.plot(range(1, N + 1),
                     np.flip(densities2),
                     linestyle='-',
                     color='red',
                     label='Lattice 2')
            ax2.set_ylim([d_low, d_high])  #ax2.set_ylim([0,1.0])
            #ax2.set_xlim([0,N])
            ax2.set_xlabel('site')
            ax2.set_ylabel('average occupancy')
            ax2.legend(loc=1)

            outpath = '../../img/visualiser/'
            plt.savefig(path.join(outpath, "%s-.png" % (j)))
            j += 1
        L1[0] = 0
        plt.close('all')

    #insertion a2
    elif i == N + 1:
        if L2[0] == 0 and rd.rand() < a2:
            L2[0] = 2
            for k in range(frames):
                positions1_1, positions1_2, positions2_2, positions2_1, fig, ax1, ax2 = plot_init(
                )

                vis.lattice_points(positions1_1, 0, "b", ax1)
                vis.lattice_points(positions1_2, 0, "r", ax1)
                vis.lattice_points(N - 1 - positions2_1, 1, "b", ax1)
                positions2_2[0] = positions2_2[0] - 1 + (k + 1) / frames
                vis.lattice_points(N - 1 - positions2_2, 1, "r", ax1)

                fig.suptitle(
                    'Two way lattice visualisation and corresponding density profile, sites=%s  \n parameters:  a1=%s, b1=%s, a2=%s, b2=%s, \n k11=%s, k12=%s, k22=%s, k21=%s'
                    % (N, a1, b1, a2, b2, k11, k12, k22, k21))
                ax2.plot(range(1, N + 1),
                         densities1,
                         linestyle='-',
                         color='blue',
                         label='Lattice 1')
                ax2.plot(range(1, N + 1),
                         np.flip(densities2),
                         linestyle='-',
                         color='red',
                         label='Lattice 2')
                ax2.set_ylim([d_low, d_high])  #ax2.set_ylim([0,1.0])
                #ax2.set_xlim([0,N])
                ax2.set_xlabel('site')
                ax2.set_ylabel('average occupancy')
                ax2.legend(loc=1)

                outpath = '../../img/visualiser/'
                plt.savefig(path.join(outpath, "%s-.png" % (j)))
                j += 1

            plt.close('all')
    #in case site = 2N+1 and there is particle 1 it leaves
    elif i == N + 2 and L2[0] == 1 and rd.rand(
    ) < b2:  #in case there is particle 1 it leaves

        for k in range(frames):
            positions1_1, positions1_2, positions2_2, positions2_1, fig, ax1, ax2 = plot_init(
            )

            vis.lattice_points(positions1_1, 0, "b", ax1)
            vis.lattice_points(positions1_2, 0, "r", ax1)
            vis.lattice_points(N - 1 - positions2_2, 1, "r", ax1)
            positions2_1[0] = positions2_1[0] - (k + 1) / frames
            vis.lattice_points(N - 1 - positions2_1, 1, "b", ax1)

            fig.suptitle(
                'Two way lattice visualisation and corresponding density profile, sites=%s  \n parameters:  a1=%s, b1=%s, a2=%s, b2=%s, \n k11=%s, k12=%s, k22=%s, k21=%s'
                % (N, a1, b1, a2, b2, k11, k12, k22, k21))
            ax2.plot(range(1, N + 1),
                     densities1,
                     linestyle='-',
                     color='blue',
                     label='Lattice 1')
            ax2.plot(range(1, N + 1),
                     np.flip(densities2),
                     linestyle='-',
                     color='red',
                     label='Lattice 2')
            ax2.set_ylim([d_low, d_high])  #ax2.set_ylim([0,1.0])
            #ax2.set_xlim([0,N])
            ax2.set_xlabel('site')
            ax2.set_ylabel('average occupancy')
            ax2.legend(loc=1)

            outpath = '../../img/visualiser/'
            plt.savefig(path.join(outpath, "%s-.png" % (j)))
            j += 1
        L2[0] = 0
        plt.close('all')
    #removal b1
    elif i == N and rd.rand() < b1:
        if L1[-1] > 0:

            for k in range(frames):
                positions1_1, positions1_2, positions2_2, positions2_1, fig, ax1, ax2 = plot_init(
                )

                vis.lattice_points(N - 1 - positions2_2, 1, "r", ax1)
                vis.lattice_points(positions1_2, 0, "r", ax1)
                vis.lattice_points(N - 1 - positions2_1, 1, "b", ax1)
                if np.size(positions1_1) > 0:
                    positions1_1[-1] = positions1_1[-1] + (k + 1) / frames
                vis.lattice_points(positions1_1, 0, "b", ax1)

                fig.suptitle(
                    'Two way lattice visualisation and corresponding density profile, sites=%s  \n parameters:  a1=%s, b1=%s, a2=%s, b2=%s, \n k11=%s, k12=%s, k22=%s, k21=%s'
                    % (N, a1, b1, a2, b2, k11, k12, k22, k21))
                ax2.plot(range(1, N + 1),
                         densities1,
                         linestyle='-',
                         color='blue',
                         label='Lattice 1')
                ax2.plot(range(1, N + 1),
                         np.flip(densities2),
                         linestyle='-',
                         color='red',
                         label='Lattice 2')
                ax2.set_ylim([d_low, d_high])  #ax2.set_ylim([0,1.0])
                #ax2.set_xlim([0,N])
                ax2.set_xlabel('site')
                ax2.set_ylabel('average occupancy')
                ax2.legend(loc=1)

                outpath = '../../img/visualiser/'
                plt.savefig(path.join(outpath, "%s-.png" % (j)))
                j += 1
            L1[-1] = 0
            plt.close('all')
    #removal b2
    elif i == 2 * N + 1 and rd.rand() < b2:
        if L2[-1] > 0:
            for k in range(frames):
                positions1_1, positions1_2, positions2_2, positions2_1, fig, ax1, ax2 = plot_init(
                )

                vis.lattice_points(positions1_1, 0, "b", ax1)
                vis.lattice_points(positions1_2, 0, "r", ax1)
                vis.lattice_points(N - 1 - positions2_1, 1, "b", ax1)
                if np.size(positions2_2) > 0:
                    positions2_2[-1] = positions2_2[-1] + (k + 1) / frames
                vis.lattice_points(N - 1 - positions2_2, 1, "r", ax1)

                fig.suptitle(
                    'Two way lattice visualisation and corresponding density profile, sites=%s  \n parameters:  a1=%s, b1=%s, a2=%s, b2=%s, \n k11=%s, k12=%s, k22=%s, k21=%s'
                    % (N, a1, b1, a2, b2, k11, k12, k22, k21))
                ax2.plot(range(1, N + 1),
                         densities1,
                         linestyle='-',
                         color='blue',
                         label='Lattice 1')
                ax2.plot(range(1, N + 1),
                         np.flip(densities2),
                         linestyle='-',
                         color='red',
                         label='Lattice 2')
                ax2.set_ylim([d_low, d_high])  #ax2.set_ylim([0,1.0])
                #ax2.set_xlim([0,N])
                ax2.set_xlabel('site')
                ax2.set_ylabel('average occupancy')
                ax2.legend(loc=1)

                outpath = '../../img/visualiser/'
                plt.savefig(path.join(outpath, "%s-.png" % (j)))
                j += 1
            L2[-1] = 0
            plt.close('all')
    #regular site lattice 1
    elif i > 0 and i < N:
        i = i - 1
        #update particle 1
        if L1[i] == 1:
            #make a step
            if L1[i + 1] == 0 and rd.rand() < k11:
                for k in range(frames):
                    positions1_1, positions1_2, positions2_2, positions2_1, fig, ax1, ax2 = plot_init(
                    )

                    vis.lattice_points(N - 1 - positions2_2, 1, "r", ax1)
                    vis.lattice_points(positions1_2, 0, "r", ax1)
                    vis.lattice_points(N - 1 - positions2_1, 1, "b", ax1)
                    if np.size(positions1_1) > 0:
                        ind = np.where(positions1_1 == i)
                        positions1_1[ind] = positions1_1[ind] + (k +
                                                                 1) / frames
                    vis.lattice_points(positions1_1, 0, "b", ax1)

                    fig.suptitle(
                        'Two way lattice visualisation and corresponding density profile, sites=%s  \n parameters:  a1=%s, b1=%s, a2=%s, b2=%s, \n k11=%s, k12=%s, k22=%s, k21=%s'
                        % (N, a1, b1, a2, b2, k11, k12, k22, k21))
                    ax2.plot(range(1, N + 1),
                             densities1,
                             linestyle='-',
                             color='blue',
                             label='Lattice 1')
                    ax2.plot(range(1, N + 1),
                             np.flip(densities2),
                             linestyle='-',
                             color='red',
                             label='Lattice 2')
                    ax2.set_ylim([d_low, d_high])  #ax2.set_ylim([0,1.0])
                    #ax2.set_xlim([0,N])
                    ax2.set_xlabel('site')
                    ax2.set_ylabel('average occupancy')
                    ax2.legend(loc=1)

                    outpath = '../../img/visualiser/'
                    plt.savefig(path.join(outpath, "%s-.png" % (j)))
                    j += 1
                L1[i] = 0
                L1[i + 1] = 1
                plt.close('all')

            #overtake
            elif L1[i + 1] > 0 and L2[-i - 2] == 0 and rd.rand() < k12:
                for k in range(frames):
                    positions1_1, positions1_2, positions2_2, positions2_1, fig, ax1, ax2 = plot_init(
                    )

                    vis.lattice_points(N - 1 - positions2_2, 1, "r", ax1)
                    vis.lattice_points(positions1_2, 0, "r", ax1)
                    vis.lattice_points(N - 1 - positions2_1, 1, "b", ax1)
                    if np.size(positions1_1) > 0:
                        ind = np.where(positions1_1 == i)
                        positions1_1[ind] = positions1_1[ind] + (k +
                                                                 1) / frames
                        vis.lattice_points(positions1_1[ind], (k + 1) / frames,
                                           "b", ax1)
                    vis.lattice_points(np.delete(positions1_1, ind), 0, "b",
                                       ax1)

                    fig.suptitle(
                        'Two way lattice visualisation and corresponding density profile, sites=%s  \n parameters:  a1=%s, b1=%s, a2=%s, b2=%s, \n k11=%s, k12=%s, k22=%s, k21=%s'
                        % (N, a1, b1, a2, b2, k11, k12, k22, k21))
                    ax2.plot(range(1, N + 1),
                             densities1,
                             linestyle='-',
                             color='blue',
                             label='Lattice 1')
                    ax2.plot(range(1, N + 1),
                             np.flip(densities2),
                             linestyle='-',
                             color='red',
                             label='Lattice 2')
                    ax2.set_ylim([d_low, d_high])  #ax2.set_ylim([0,1.0])
                    #ax2.set_xlim([0,N])
                    ax2.set_xlabel('site')
                    ax2.set_ylabel('average occupancy')
                    ax2.legend(loc=1)

                    outpath = '../../img/visualiser/'
                    plt.savefig(path.join(outpath, "%s-.png" % (j)))
                    j += 1
                L1[i] = 0
                L2[-i - 2] = 1
                plt.close('all')

        #update particle 2
        if L1[i] == 2:

            #finish overtaking
            if L2[-i] == 0 and rd.rand() < k21:

                for k in range(frames):
                    positions1_1, positions1_2, positions2_2, positions2_1, fig, ax1, ax2 = plot_init(
                    )

                    vis.lattice_points(N - 1 - positions2_2, 1, "r", ax1)
                    vis.lattice_points(positions1_1, 0, "b", ax1)
                    vis.lattice_points(N - 1 - positions2_1, 1, "b", ax1)
                    if np.size(positions1_2) > 0:
                        ind = np.where(positions1_2 == i)
                        positions1_2[ind] = positions1_2[ind] - (k +
                                                                 1) / frames
                        vis.lattice_points(positions1_2[ind], (k + 1) / frames,
                                           "r", ax1)
                    vis.lattice_points(np.delete(positions1_2, ind), 0, "r",
                                       ax1)

                    fig.suptitle(
                        'Two way lattice visualisation and corresponding density profile, sites=%s  \n parameters:  a1=%s, b1=%s, a2=%s, b2=%s, \n k11=%s, k12=%s, k22=%s, k21=%s'
                        % (N, a1, b1, a2, b2, k11, k12, k22, k21))
                    ax2.plot(range(1, N + 1),
                             densities1,
                             linestyle='-',
                             color='blue',
                             label='Lattice 1')
                    ax2.plot(range(1, N + 1),
                             np.flip(densities2),
                             linestyle='-',
                             color='red',
                             label='Lattice 2')
                    ax2.set_ylim([d_low, d_high])  #ax2.set_ylim([0,1.0])
                    #ax2.set_xlim([0,N])
                    ax2.set_xlabel('site')
                    ax2.set_ylabel('average occupancy')
                    ax2.legend(loc=1)

                    outpath = '../../img/visualiser/'
                    plt.savefig(path.join(outpath, "%s-.png" % (j)))
                    j += 1

                L1[i] = 0
                L2[-i] = 2
                plt.close('all')
            #continue in the opposite lane
            elif L1[i - 1] == 0 and rd.rand() < k21:
                for k in range(frames):
                    positions1_1, positions1_2, positions2_2, positions2_1, fig, ax1, ax2 = plot_init(
                    )

                    vis.lattice_points(N - 1 - positions2_2, 1, "r", ax1)
                    vis.lattice_points(positions1_2, 0, "r", ax1)
                    vis.lattice_points(N - 1 - positions2_1, 1, "b", ax1)
                    if np.size(positions1_1) > 0:
                        ind = np.where(positions1_1 == i)
                        positions1_1[ind] = positions1_1[ind] + (k +
                                                                 1) / frames
                    vis.lattice_points(positions1_2, 0, "b", ax1)

                    fig.suptitle(
                        'Two way lattice visualisation and corresponding density profile, sites=%s  \n parameters:  a1=%s, b1=%s, a2=%s, b2=%s, \n k11=%s, k12=%s, k22=%s, k21=%s'
                        % (N, a1, b1, a2, b2, k11, k12, k22, k21))
                    ax2.plot(range(1, N + 1),
                             densities1,
                             linestyle='-',
                             color='blue',
                             label='Lattice 1')
                    ax2.plot(range(1, N + 1),
                             np.flip(densities2),
                             linestyle='-',
                             color='red',
                             label='Lattice 2')
                    ax2.set_ylim([d_low, d_high])  #ax2.set_ylim([0,1.0])
                    #ax2.set_xlim([0,N])
                    ax2.set_xlabel('site')
                    ax2.set_ylabel('average occupancy')
                    ax2.legend(loc=1)

                    outpath = '../../img/visualiser/'
                    plt.savefig(path.join(outpath, "%s-.png" % (j)))
                    j += 1
                L1[i] = 0
                L1[i - 1] = 2
                plt.close('all')
    #regular site lattice 2
    elif i > N and i < 2 * N + 1:
        i = i - N - 2
        #print(i)
        assert (i >= 0)
        assert (i <= N)

        #update particle 2
        if L2[i] == 2:
            #make a step
            if L2[i + 1] == 0 and rd.rand() < k22:
                for k in range(frames):
                    positions1_1, positions1_2, positions2_2, positions2_1, fig, ax1, ax2 = plot_init(
                    )

                    vis.lattice_points(positions1_1, 0, "b", ax1)
                    vis.lattice_points(positions1_2, 0, "r", ax1)
                    vis.lattice_points(N - 1 - positions2_1, 1, "b", ax1)
                    if np.size(positions2_2) > 0:
                        ind = np.where(positions2_2 == i)
                        positions2_2[ind] = positions2_2[ind] + (k +
                                                                 1) / frames
                    vis.lattice_points(N - 1 - positions2_2, 1, "r", ax1)

                    fig.suptitle(
                        'Two way lattice visualisation and corresponding density profile, sites=%s  \n parameters:  a1=%s, b1=%s, a2=%s, b2=%s, \n k11=%s, k12=%s, k22=%s, k21=%s'
                        % (N, a1, b1, a2, b2, k11, k12, k22, k21))
                    ax2.plot(range(1, N + 1),
                             densities1,
                             linestyle='-',
                             color='blue',
                             label='Lattice 1')
                    ax2.plot(range(1, N + 1),
                             np.flip(densities2),
                             linestyle='-',
                             color='red',
                             label='Lattice 2')
                    ax2.set_ylim([d_low, d_high])  #ax2.set_ylim([0,1.0])
                    #ax2.set_xlim([0,N])
                    ax2.set_xlabel('site')
                    ax2.set_ylabel('average occupancy')
                    ax2.legend(loc=1)

                    outpath = '../../img/visualiser/'
                    plt.savefig(path.join(outpath, "%s-.png" % (j)))
                    j += 1
                L2[i] = 0
                L2[i + 1] = 2
                plt.close('all')
            #overtake
            elif L2[i + 1] > 0 and L1[-i - 2] == 0 and rd.rand() < k21:
                for k in range(frames):
                    positions1_1, positions1_2, positions2_2, positions2_1, fig, ax1, ax2 = plot_init(
                    )

                    vis.lattice_points(positions1_1, 0, "b", ax1)
                    vis.lattice_points(positions1_2, 0, "r", ax1)
                    vis.lattice_points(N - 1 - positions2_1, 1, "b", ax1)
                    if np.size(positions2_2) > 0:
                        ind = np.where(positions2_2 == i)
                        positions2_2[ind] = positions2_2[ind] + (k +
                                                                 1) / frames
                        vis.lattice_points(N - 1 - positions2_2[ind],
                                           1 - (k + 1) / frames, "r", ax1)
                    vis.lattice_points(N - 1 - np.delete(positions2_2, ind), 1,
                                       "r", ax1)

                    fig.suptitle(
                        'Two way lattice visualisation and corresponding density profile, sites=%s  \n parameters:  a1=%s, b1=%s, a2=%s, b2=%s, \n k11=%s, k12=%s, k22=%s, k21=%s'
                        % (N, a1, b1, a2, b2, k11, k12, k22, k21))
                    ax2.plot(range(1, N + 1),
                             densities1,
                             linestyle='-',
                             color='blue',
                             label='Lattice 1')
                    ax2.plot(range(1, N + 1),
                             np.flip(densities2),
                             linestyle='-',
                             color='red',
                             label='Lattice 2')
                    ax2.set_ylim([d_low, d_high])  #ax2.set_ylim([0,1.0])
                    #ax2.set_xlim([0,N])
                    ax2.set_xlabel('site')
                    ax2.set_ylabel('average occupancy')
                    ax2.legend(loc=1)

                    outpath = '../../img/visualiser/'
                    plt.savefig(path.join(outpath, "%s-.png" % (j)))
                    j += 1
                L2[i] = 0
                L1[-i - 2] = 2
                plt.close('all')
        #update particle 1
        if L2[i] == 1:
            #finish overtaking
            if L1[-i] == 0 and rd.rand() < k12:
                for k in range(frames):
                    positions1_1, positions1_2, positions2_2, positions2_1, fig, ax1, ax2 = plot_init(
                    )

                    vis.lattice_points(N - 1 - positions2_2, 1, "r", ax1)
                    vis.lattice_points(positions1_1, 0, "b", ax1)
                    vis.lattice_points(positions1_2, 0, "r", ax1)
                    if np.size(positions2_1) > 0:
                        ind = np.where(positions2_1 == i)
                        positions2_1[ind] = positions2_1[ind] - (k +
                                                                 1) / frames
                        vis.lattice_points(N - 1 - positions2_1[ind],
                                           1 - (k + 1) / frames, "b", ax1)
                    vis.lattice_points(N - 1 - np.delete(positions2_1, ind), 1,
                                       "b", ax1)

                    fig.suptitle(
                        'Two way lattice visualisation and corresponding density profile, sites=%s  \n parameters:  a1=%s, b1=%s, a2=%s, b2=%s, \n k11=%s, k12=%s, k22=%s, k21=%s'
                        % (N, a1, b1, a2, b2, k11, k12, k22, k21))
                    ax2.plot(range(1, N + 1),
                             densities1,
                             linestyle='-',
                             color='blue',
                             label='Lattice 1')
                    ax2.plot(range(1, N + 1),
                             np.flip(densities2),
                             linestyle='-',
                             color='red',
                             label='Lattice 2')
                    ax2.set_ylim([d_low, d_high])  #ax2.set_ylim([0,1.0])
                    #ax2.set_xlim([0,N])
                    ax2.set_xlabel('site')
                    ax2.set_ylabel('average occupancy')
                    ax2.legend(loc=1)

                    outpath = '../../img/visualiser/'
                    plt.savefig(path.join(outpath, "%s-.png" % (j)))
                    j += 1
                L2[i] = 0
                L1[-i] = 1
                plt.close('all')

            #continue in the opposite lane
            elif L2[i - 1] == 0 and rd.rand() < k12:
                if not i == 0:
                    for k in range(frames):
                        positions1_1, positions1_2, positions2_2, positions2_1, fig, ax1, ax2 = plot_init(
                        )

                        vis.lattice_points(N - 1 - positions2_2, 1, "r", ax1)
                        vis.lattice_points(positions1_1, 0, "b", ax1)
                        vis.lattice_points(positions1_2, 0, "r", ax1)
                        if np.size(positions2_1) > 0:
                            ind = np.where(positions2_1 == i)
                            positions2_1[ind] = positions2_1[ind] - (
                                k + 1) / frames
                            vis.lattice_points(N - 1 - positions2_1[ind], 1,
                                               "b", ax1)
                        vis.lattice_points(
                            np.delete(N - 1 - positions2_1, ind), 1, "b", ax1)

                        fig.suptitle(
                            'Two way lattice visualisation and corresponding density profile, sites=%s  \n parameters:  a1=%s, b1=%s, a2=%s, b2=%s, \n k11=%s, k12=%s, k22=%s, k21=%s'
                            % (N, a1, b1, a2, b2, k11, k12, k22, k21))
                        ax2.plot(range(1, N + 1),
                                 densities1,
                                 linestyle='-',
                                 color='blue',
                                 label='Lattice 1')
                        ax2.plot(range(1, N + 1),
                                 np.flip(densities2),
                                 linestyle='-',
                                 color='red',
                                 label='Lattice 2')
                        ax2.set_ylim([d_low, d_high])  #ax2.set_ylim([0,1.0])
                        #ax2.set_xlim([0,N])
                        ax2.set_xlabel('site')
                        ax2.set_ylabel('average occupancy')
                        ax2.legend(loc=1)

                        outpath = '../../img/visualiser/'
                        plt.savefig(path.join(outpath, "%s-.png" % (j)))
                        j += 1
                    L2[i] = 0
                    L2[i - 1] = 1
                    plt.close('all')