最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - CVXPY with MOSEK: "MOSEK solver is not installed or failed - Stack Overflow

programmeradmin15浏览0评论

Problem Description: I am using CVXPY on Google Colab and trying to use MOSEK as the solver for a Second-Order Cone Program (SOCP). However, when I run the following command:

prob.solve(solver=cp.MOSEK, verbose=True)

I get the error: MOSEK solver is not installed or failed. What I've Tried:

  1. Checking Installed Solvers I checked the available solvers in CVXPY using:
import cvxpy as cp
print(cp.installed_solvers())

Output:

['CLARABEL', 'CVXOPT', 'GLPK', 'GLPK_MI', 'HIGHS', 'MOSEK', 'OSQP', 'SCIPY', 'SCS'] MOSEK appears in the installed solvers list, but I still cannot use it.

  1. Testing a Simple SOCP Problem I ran a simple Second-Order Cone Problem (SOCP) to check if MOSEK works:
import cvxpy as cp

# Define variables
x = cp.Variable(2)

# Objective function
objective = cp.Minimize(x[0] + x[1])

# Constraints
constraints = [
    cp.SOC(1, x),  # Second-order cone constraint: sqrt(x1² + x2²) <= 1
    x >= 0         # Non-negativity constraint: x1 >= 0, x2 >= 0
]

# Create and solve the problem
prob = cp.Problem(objective, constraints)

# Solve with MOSEK
try:
    prob.solve(solver=cp.MOSEK, verbose=True)
    print(f"Optimal value: {prob.value}")
    print(f"Optimal solution: x1 = {x.value[0]}, x2 = {x.value[1]}")
except cp.error.SolverError:
    print("MOSEK solver failed.")

Error Message:

MOSEK solver is not installed or failed. Questions: MOSEK appears in cp.installed_solvers(), so why is it still not working? Do I need additional configurations (e.g., environment variables, license setup) to activate MOSEK? How can I correctly set up CVXPY to use MOSEK on Google Colab?

发布评论

评论列表(0)

  1. 暂无评论