diff --git a/src/sage/numerical/interactive_simplex_method.py b/src/sage/numerical/interactive_simplex_method.py index 2da9fa85057..a4ce0a7a9c5 100644 --- a/src/sage/numerical/interactive_simplex_method.py +++ b/src/sage/numerical/interactive_simplex_method.py @@ -3910,8 +3910,36 @@ def __init__(self, A, b, c, objective_value, c = copy(c) B = vector(basic_variables) N = vector(nonbasic_variables) + # Issue #29101: vector does not guarantee that the result is freshly allocated + # if the input was already a vector + if B is basic_variables: + B = copy(B) + if N is nonbasic_variables: + N = copy(N) self._AbcvBNz = [A, b, c, objective_value, B, N, polygen(ZZ, objective_name)] + def __copy__(self): + r""" + TESTS: + + Test that copies do not share state with the original:: + + sage: A = ([1, 1], [3, 1]) + sage: b = (1000, 1500) + sage: c = (10, 5) + sage: P = InteractiveLPProblemStandardForm(A, b, c) + sage: D = P.initial_dictionary() + sage: D_2 = copy(D) + sage: D is D_2 + False + sage: D.enter('x1') + sage: D.leave('x3') + sage: D.update() + sage: D_2 == D + False + """ + return type(self)(*self._AbcvBNz) + @staticmethod def random_element(m, n, bound=5, special_probability=0.2): r"""