Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from gurobipy import Model, GRB
- # Създаване на модела
- model = Model("Nonlinear Constraints Example")
- # Променливи
- x1 = model.addVar(name="x1")
- x2 = model.addVar(name="x2")
- # Целева функция
- model.setObjective(x1 + x2, GRB.MAXIMIZE)
- # Ограничения
- model.addConstr(x1**2 + x2**2 <= 1, "CircleConstraint") # Квадратично ограничение
- model.addConstr(x1 + x2 <= 1, "LinearConstraint") # Линейно ограничение
- # Оптимизация
- model.optimize()
- # Резултати
- for v in model.getVars():
- print(f"{v.varName}: {v.x}")
- print(f"Objective Value: {model.ObjVal}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement