def min_conflicts(problem, initial_assignment=None, iterations_limit=0):
    """
    Min conflicts search.

    initial_assignment the initial assignment, or None to generate a random
    one.
    If iterations_limit is specified, the algorithm will end after that
    number of iterations. Else, it will continue until if finds an assignment
    that doesn't generate conflicts (a solution).
    """
    assignment = {}
    if initial_assignment:
        assignment.update(initial_assignment)
    else:
        for variable in problem.variables:
            value = _min_conflicts_value(problem, assignment, variable)
            assignment[variable] = value

    iteration = 0
    run = True
    while run:
        conflicts = _find_conflicts(problem, assignment)

        conflict_variables = [v for v in problem.variables
                              if any(v in conflict[0] for conflict in conflicts)]

        if conflict_variables:
            variable = random.choice(conflict_variables)
            value = _min_conflicts_value(problem, assignment, variable)
            assignment[variable] = value

        iteration += 1

        if iterations_limit and iterations_limit >= iteration:
            run = False
        elif not _count_conflicts(problem, assignment):
            run = False

    return assignment
dataset/ETHPy150Open simpleai-team/simpleai/simpleai/search/csp.py/min_conflicts/swapped operands of `>=`