def get_segregation(model):
    """Find the fraction of agents that only have neighbors of their same type."""
    segregated_agents = 0
    for agent in model.schedule.agents:
        segregated = True
        for neighbor in model.grid.neighbor_iter(agent.pos):
            if neighbor.type != agent.type:
                segregated = False
                break
        if segregated:
            segregated_agents += 1

    if model.schedule.get_agent_count() == 0:
        return 0.0

    return segregated_agents / model.schedule.get_agent_count()