示例#1
0
def get_cell_of_facility_by_num(cells, facility_num):
    for cell in cells:
        if cell.occupied_by and cell.occupied_by.kind == 'f' and cell.occupied_by.num == facility_num:
            new_cell = Cell(cell.cell_size, cell.surf_center, cell.ord_number, cell.cost)
            new_cell.add_facility(cell.occupied_by)

            return new_cell
    return None
示例#2
0
def get_cell_of_facility(cells, facility):
    new_cell = None

    for cell in cells:
        if cell.occupied_by == facility:
            new_cell = Cell(cell.cell_size, cell.surf_center, cell.ord_number, cell.cost)
            new_cell.add_facility(cell.occupied_by)

    return new_cell
def copy_cells(cells):
    copy_cells = []

    for cell in cells:
        new_cell = Cell(cell.cell_size, cell.surf_center, cell.ord_number, cell.cost)
        if cell.occupied_by:
            if cell.occupied_by.kind == 'c':
                new_cell.add_city(cell.occupied_by)
            elif cell.occupied_by.kind == 'f':
                new_cell.add_facility(cell.occupied_by)
        copy_cells.append(new_cell)

    return copy_cells
def create_next_solution_cells(cells, facility_to_move, new_random_location):
    next_solution_cells = []

    for cell in cells:
        new_cell = Cell(cell.cell_size, cell.surf_center, cell.ord_number, cell.cost)

        if cell.occupied_by:
            if cell.occupied_by.kind == 'c':
                new_cell.add_city(cell.occupied_by)
            elif cell.occupied_by.kind == 'f' and cell.occupied_by.num != facility_to_move.num:
                new_cell.add_facility(cell.occupied_by)

        if new_cell.get_pos() == new_random_location.get_pos():
            new_cell.add_facility(facility_to_move)

        next_solution_cells.append(new_cell)

    return next_solution_cells