def test_add_remove_in_context(self, model): v = model.variables new_var = model.problem.Variable("test_var", lb=-10, ub=-10) with model: su.add_cons_vars_to_problem(model, [new_var]) su.remove_cons_vars_from_problem(model, [v.PGM]) assert "test_var" in model.variables.keys() assert "PGM" not in model.variables.keys() assert "test_var" not in model.variables.keys() assert "PGM" in model.variables.keys()
def test_add_remove_in_context(model): v = model.variables new_var = model.problem.Variable("test_var", lb=-10, ub=-10) with model: su.add_cons_vars_to_problem(model, [new_var]) su.remove_cons_vars_from_problem(model, [v.PGM]) assert "test_var" in model.variables.keys() assert "PGM" not in model.variables.keys() assert "test_var" not in model.variables.keys() assert "PGM" in model.variables.keys()
def test_add_remove(self, model): v = model.variables new_var = model.problem.Variable("test_var", lb=-10, ub=-10) new_constraint = model.problem.Constraint( v.PGK - new_var, name="test_constraint", lb=0) su.add_cons_vars_to_problem(model, [new_var, new_constraint]) assert "test_var" in model.variables.keys() assert "test_constraint" in model.constraints.keys() su.remove_cons_vars_from_problem(model, [new_var, new_constraint]) assert "test_var" not in model.variables.keys() assert "test_constraint" not in model.constraints.keys()
def test_add_remove_in_context(model: "Model") -> None: """Test addition and removal of variables and constraints within context.""" v = model.variables new_var = model.problem.Variable("test_var", lb=-10, ub=-10) with model: su.add_cons_vars_to_problem(model, [new_var]) su.remove_cons_vars_from_problem(model, [v.PGM]) assert "test_var" in model.variables.keys() assert "PGM" not in model.variables.keys() assert "test_var" not in model.variables.keys() assert "PGM" in model.variables.keys()
def test_add_remove(self, model): v = model.variables new_var = model.problem.Variable("test_var", lb=-10, ub=-10) new_constraint = model.problem.Constraint( v.PGK - new_var, name="test_constraint", lb=0) su.add_cons_vars_to_problem(model, [new_var, new_constraint]) assert "test_var" in model.variables.keys() assert "test_constraint" in model.constraints.keys() su.remove_cons_vars_from_problem(model, [new_var, new_constraint]) assert "test_var" not in model.variables.keys() assert "test_constraint" not in model.constraints.keys()
def test_add_remove(model: "Model") -> None: """Test addition and removal of variables and constraints.""" v = model.variables new_var = model.problem.Variable("test_var", lb=-10, ub=-10) new_constraint = model.problem.Constraint(v.PGK - new_var, name="test_constraint", lb=0) su.add_cons_vars_to_problem(model, [new_var, new_constraint]) assert "test_var" in model.variables.keys() assert "test_constraint" in model.constraints.keys() su.remove_cons_vars_from_problem(model, [new_var, new_constraint]) assert "test_var" not in model.variables.keys() assert "test_constraint" not in model.constraints.keys()
def add_cons_vars(self, what, **kwargs): """Add constraints and variables to the model's mathematical problem. Useful for variables and constraints that can not be expressed with reactions and simple lower and upper bounds. Additions are reversed upon exit if the model itself is used as context. Parameters ---------- what : list or tuple of optlang variables or constraints. The variables or constraints to add to the model. Must be of class `optlang.interface.Variable` or `optlang.interface.Constraint`. **kwargs : keyword arguments Passed to solver.add() """ add_cons_vars_to_problem(self, what, **kwargs)
def add_cons_vars(self, what, **kwargs): """Add constraints and variables to the model's mathematical problem. Useful for variables and constraints that can not be expressed with reactions and simple lower and upper bounds. Additions are reversed upon exit if the model itself is used as context. Parameters ---------- what : list or tuple of optlang variables or constraints. The variables or constraints to add to the model. Must be of class `optlang.interface.Variable` or `optlang.interface.Constraint`. **kwargs : keyword arguments Passed to solver.add() """ add_cons_vars_to_problem(self, what, **kwargs)