def pivot(constraints: List[LinearFunction], objective_fn: LinearFunction, callback: Callable[[int, int], None]) -> None: """ >>> from linear_function import LinearFunction >>> constraints = [ \ LinearFunction(18, [-2, -1, -1]), \ LinearFunction(30, [-1, -2, -2]), \ LinearFunction(24, [-2, -2, -2]), \ ] >>> objective_fn = LinearFunction(0, [6, 5, 4]) >>> _pivot(constraints, objective_fn) >>> print(objective_fn) 54 + -3*x₀ + 2*x₁ + 1*x₂ >>> for i in constraints: print(i) 9 + -1/2*x₀ + -1/2*x₁ + -1/2*x₂ 21 + 1/2*x₀ + -3/2*x₁ + -3/2*x₂ 6 + 1*x₀ + -1*x₁ + -1*x₂ """ arg_number = first_index(objective_fn.coefs, lambda x: x > 0) index = tightest_constraint(constraints, arg_number) assert -constraints[index].free / constraints[index].coefs[arg_number] > 0 constraints[index].rearrange(arg_number) for c in skip_at(constraints, index): c.substitute(arg_number, constraints[index]) objective_fn.substitute(arg_number, constraints[index]) callback(arg_number, index)