Exemplo n.º 1
0
def update_rps_01(lattice, x_len, y_len):
    #temp_lattice = [row[:] for row in lattice]
    new_lattice = [[cell() for y in range(y_len)] for x in range(x_len)]

    for i in range(x_len):
        for j in range(y_len):
            i_up, i_down, j_left, j_right = determine_ij(i, j, x_len, y_len)

            neighbor_types = [
                lattice[i][j_left].type, lattice[i][j_right].type,
                lattice[i_up][j].type, lattice[i_down][j].type,
                lattice[i_up][j_left].type, lattice[i_up][j_right].type,
                lattice[i_down][j_left].type, lattice[i_down][j_right].type
            ]

            type_0 = neighbor_types.count(0)
            type_1 = neighbor_types.count(1)
            type_2 = neighbor_types.count(2)

            types = [type_0, type_1, type_2]

            max_value = max(types)
            max_index = types.index(max_value)

            new_lattice[i][j].type = max_index

    return new_lattice
Exemplo n.º 2
0
def update_binary(lattice, x_len, y_len):
    for i in range(x_len):
        for j in range(y_len):
            i_up, i_down, j_left, j_right = determine_ij(i, j, x_len, y_len)
            sum = lattice[i][j_left].type
            sum += lattice[i][j_right].type
            sum += lattice[i_up][j].type
            sum += lattice[i_down][j].type
            sum += lattice[i_up][j_left].type
            sum += lattice[i_up][j_right].type
            sum += lattice[i_down][j_left].type
            sum += lattice[i_down][j_right].type
            #if sum >= 3 and sum <= 5:
            #if sum >= 3 and sum <= 4:
            #if sum >= 2 and sum <= 7:
            if sum >= 1 and sum <= 3:
                lattice[i][j].type = 1
            else:
                lattice[i][j].type = 0
            #if lattice[i][j].type == 0 and sum >= 1 and sum <= 5:
            #    lattice[i][j].type = 1
            #elif lattice[i][j].type == 1 and sum == 3:
            #    lattice[i][j].type = 0

    return lattice
Exemplo n.º 3
0
def update_rps_03(lattice, x_len, y_len, num_coors):
    coors = get_rand_coors(x_len, y_len, num_coors)

    for coor in coors:
        i, j = coor[0], coor[1]
        i_up, i_down, j_left, j_right = determine_ij(i, j, x_len, y_len)

        cell_1 = lattice[i][j]

        direction = np.random.randint(0, 3)
        if direction == 0:  # Take the above cell.
            cell_2 = lattice[i_up][j]
            cell_1, cell_2 = combat(cell_1, cell_2)
            lattice[i_up][j] = cell_2

        elif direction == 1:  # Take the right cell.
            cell_2 = lattice[i][j_right]
            cell_1, cell_2 = combat(cell_1, cell_2)
            lattice[i][j_right] = cell_2

        elif direction == 2:  # Take the below cell.
            cell_2 = lattice[i_down][j]
            cell_1, cell_2 = combat(cell_1, cell_2)
            lattice[i_down][j] = cell_2

        elif direction == 3:  # Take the left cell.
            cell_2 = lattice[i][j_left]
            cell_1, cell_2 = combat(cell_1, cell_2)
            lattice[i][j_left] = cell_2

    return lattice
Exemplo n.º 4
0
def move_organisms(lattice, i, j, x_len, y_len):
    i_up, i_down, j_left, j_right = determine_ij(i, j, x_len, y_len)

    organism_move_list = []

    for organism in lattice[i][j].organism_list:
        r = np.random.random()

        if r <= 4. / 5:
            # Config A. -10 energy.
            organism.energy = organism.energy - 10
            organism_move_list.append(organism)

        ### Move north.
        if r <= 1. / 5:
            lattice[i_up][j].organism_list.append(organism)

        ### Move east.
        elif 1. / 5 < r <= 2. / 5:
            lattice[i][j_right].organism_list.append(organism)

        ### Move south.
        elif 2. / 5 < r <= 3. / 5:
            lattice[i_down][j].organism_list.append(organism)

        ### Move west.
        elif 3. / 5 < r <= 4. / 5:
            lattice[i][j_left].organism_list.append(organism)

        ### Otherwise, stay in place.

    lattice[i][j].organism_list = [
        organism for organism in lattice[i][j].organism_list
        if organism not in organism_move_list
    ]
Exemplo n.º 5
0
def update_rps_02(lattice, x_len, y_len):
    new_lattice = [row[:] for row in lattice]
    #new_lattice = [ [cell() for y in range(y_len)] for x in range(x_len) ]

    for i in range(x_len):
        for j in range(y_len):
            i_up, i_down, j_left, j_right = determine_ij(i, j, x_len, y_len)

            neighbor_types = [
                lattice[i][j_left].type, lattice[i][j_right].type,
                lattice[i_up][j].type, lattice[i_down][j].type,
                lattice[i_up][j_left].type, lattice[i_up][j_right].type,
                lattice[i_down][j_left].type, lattice[i_down][j_right].type
            ]

            type_1 = neighbor_types.count(1)
            type_2 = neighbor_types.count(2)
            type_3 = neighbor_types.count(3)

            if lattice[i][j].type == 1:
                if type_2 > type_1:
                    new_lattice[i][j].type = 2
                #else:
                #    new_lattice[i][j].type = 0

            elif lattice[i][j].type == 2:
                if type_3 > type_2:
                    new_lattice[i][j].type = 3
                #else:
                #    new_lattice[i][j].type = 0

            elif lattice[i][j].type == 3:
                if type_1 > type_3:
                    new_lattice[i][j].type = 1
                #else:
                #    new_lattice[i][j].type = 0

    return new_lattice
Exemplo n.º 6
0
################################

data = []

time = 10

for t in range(time):
    w = np.zeros((n, n))
    for i in range(n):
        for j in range(n):
            for p in v[i][j]:
                if p.moved == False:
                    r = random.random()
                    if r >= diffuse_prob:
                        i_up, i_down, j_left, j_right = determine_ij(
                            i, j, n, n)

                        north = len(v[i_up][j])
                        south = len(v[i_down][j])
                        west = len(v[i][j_left])
                        east = len(v[i][j_right])

                        total = float(north + south + west + east)

                        if total == 0:
                            north, south, west, east = 1, 1, 1, 1
                            total = 4.

                        xf = (a * xn + c) % m
                        xn = float(xf)
                        xnm = xn / m