【问题标题】:cvxpy, no cplex attributecvxpy,没有 cplex 属性
【发布时间】:2019-02-17 07:16:22
【问题描述】:

我无法为 cvxpy 选择 cplex 求解器。 cvxpy 网站指出,如果您能够将 cplex 导入 python,您也可以将 cplex 用于 cvxpy。然而,事实并非如此。

CPLEX 不是 cvxpy 的参数之一。请参阅下面的 cvxpy 参数列表。

如何解决?

dir(cp)
Out[8]: 
['Bool',
 'CBC',
 'CVXOPT',
 'CallbackParam',
 'Constant',
 'ECOS',
 'ECOS_BB',
 'ELEMENTAL',
 'GLPK',
 'GLPK_MI',
 'GUROBI',
 'INFEASIBLE',
 'INFEASIBLE_INACCURATE',
 'Int',
 'JULIA_OPT',
 'LS',
 'MOSEK',
 'Maximize',
 'Minimize',
 'NonNegative',
 'OPTIMAL',
 'OPTIMAL_INACCURATE',
 'Parameter',
 'Problem',
 'ROBUST_KKTSOLVER',
 'SCS',
 'SOLVER_ERROR',
 'Semidef',
 'SolverError',
 'Symmetric',
 'UNBOUNDED',
 'UNBOUNDED_INACCURATE',
 'Variable',
 '__builtins__',
 '__cached__',
 '__doc__',
 '__file__',
 '__loader__',
 '__name__',
 '__package__',
 '__path__',
 '__spec__',
 '__version__',
 'abs',
 'affine',
 'affine_prod',
 'atom',
 'atoms',
 'axis_atom',
 'bmat',
 'constraints',
 'conv',
 'cumsum',
 'diag',
 'diff',
 'elementwise',
 'entr',
 'error',
 'exp',
 'expressions',
 'geo_mean',
 'harmonic_mean',
 'hstack',
 'huber',
 'installed_solvers',
 'interface',
 'inv_pos',
 'kl_div',
 'kron',
 'lambda_max',
 'lambda_min',
 'lambda_sum_largest',
 'lambda_sum_smallest',
 'lin_ops',
 'linearize',
 'log',
 'log1p',
 'log_det',
 'log_sum_exp',
 'logistic',
 'matrix_frac',
 'max_elemwise',
 'max_entries',
 'min_elemwise',
 'min_entries',
 'mixed_norm',
 'mul_elemwise',
 'neg',
 'norm',
 'norm1',
 'norm2',
 'normInf',
 'normNuc',
 'norm_inf',
 'norm_nuc',
 'partial_optimize',
 'pnorm',
 'pos',
 'power',
 'problems',
 'quad_form',
 'quad_over_lin',
 'reshape',
 'scalene',
 'semidefinite',
 'settings',
 'sigma_max',
 'sqrt',
 'square',
 'sum_entries',
 'sum_largest',
 'sum_smallest',
 'sum_squares',
 'total_variation',
 'trace',
 'transforms',
 'tv',
 'upper_tri',
 'utilities',
 'vec',
 'vstack']

【问题讨论】:

  • 你用的是什么版本的cvxpy?
  • 您需要版本 >= 1.0.8 的 cvxpy。
  • 我相信在 1.0.8 之前对 CPLEX 的支持有限。
  • 您的打印输出表明您使用的是 CVXPY 0.4。你至少需要 1.0。

标签: python cplex cvxpy


【解决方案1】:

zoo and bus example:

# Import packages.
import cvxpy as cp

# Define and solve the CVXPY problem.
nbBus40 = cp.Variable(integer=True)
nbBus30 = cp.Variable( integer=True)
cost = 500*nbBus40+400*nbBus30
prob = cp.Problem(cp.Minimize(cost),[40*nbBus40+30*nbBus30>=300,
                                     nbBus40>=0,nbBus30>=0
                                     ])
prob.solve(solver=cp.CPLEX,verbose=True)
# Print result.
print("\nThe minimal cost is", prob.value)
print("number buses 40 seats = ",nbBus40.value)
print("number buses 30 seats = ",nbBus30.value)

工作正常

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-19
    • 1970-01-01
    • 1970-01-01
    • 2016-11-12
    • 2023-04-08
    相关资源
    最近更新 更多