Julia QPDA:无匹配四边形的方法

发布于 2025-02-13 14:29:24 字数 2250 浏览 0 评论 0原文

我正在尝试通过软件包QPDA解决数学问题。毫无疑问,每当我称之为此操作时,我都会收到以下错误:

    ERROR: LoadError: MethodError: no method matching QuadraticProgram(::Array{Float64,2}, ::Array{Float64,1}, ::Array{F loat64,2}, ::Array{Float64,1}, ::Array{Float64,1}, ::UniformScaling{Bool}; z=[1.0, 1.0, 1.0, 1.0, 1.0, 1.0], P=[5.0 9.0 … -6.0 -10.0; 9.0 17.0 … -8.0 -16.0; … ; -6.0 -8.0 … 17.0 19.0; -10.0 -16.0 … 19.0 25.0], semidefinite=true, ϵ=1.4901161193847656e-8, smartstart=true, scaling=true)
Closest candidates are:
  QuadraticProgram(::MT, ::VT, ::MT, ::VT, ::VT, ::Any; semidefinite, ϵ, smartstart, scaling) where {T, VT<:AbstractArray{T,1}, MT<:AbstractArray{T,2}} at .../.julia/packages/QPDAS/CvMCc/src/quadraticProgram.jl:38 got unsupported keyword arguments "z", "P"
  QuadraticProgram(::MT, ::VT, ::MT, ::VT, ::VT) where {T, VT<:AbstractArray{T,1}, MT<:AbstractArray{T,2}} at .../.julia/packages/QPDAS/CvMCc/src/quadraticProgram.jl:38 got unsupported keyword arguments "z", "P", "semidefinite", "ϵ", "smartstart", "scaling"
  QuadraticProgram(::MT, !Matched::MT, !Matched::VT, ::VT, ::VT, ::PT, !Matched::PFT, !Matched::VT, !Matched::VT, !Matched::Bool, !Matched::VT, !Matched::VT, !Matched::BoxConstrainedQP{T,GT,VT}) where {T, GT<:(QPDAS.AbstractCholeskySpecial{T,MT} where MT), VT<:AbstractArray{T,1}, MT<:AbstractArray{T,2}, PT, PFT} at .../.julia/packages/QPDAS/CvMCc/src/quadraticProgram.jl:22 got unsupported keyword arguments "z", "P", "semidefinite", "ϵ", "smartstart", "scaling"

这是我的代码:

function getSolution(points)    # array of tuples with a tuple and an Int64
    A = [points[i][2] for i=1:length(points)]
    A = reshape(A, 1, length(points))
    b = [0.0 for i=1:length(points)]
    C = diagm(-1 .* ones(length(points)))
    d = b
    M = constructMatrix(points)

    qp = QuadraticProgram(A, b, C, d, z = ones(length(points)), P = M;
            semidefinite = true, ϵ = sqrt(eps(Float64)), smartstart = true, scaling = true)

    sol, val = solve!(qp)
    return sol
end

我知道它的类型我的变量类型与方法QuadraticProgram所期望的变量不匹配,但是我可以't以什么方式弄清楚。 类型

matrix, vector, matrix, vector, vector, any; semidefinite, ϵ, smartstart, scaling

在我的理解中,它期望我应该拥有的 。我在做什么错?

I'm trying to solve a mathematical problem via the package QPDAS. Howevery, every time I call the function to do that, I get the following error:

    ERROR: LoadError: MethodError: no method matching QuadraticProgram(::Array{Float64,2}, ::Array{Float64,1}, ::Array{F loat64,2}, ::Array{Float64,1}, ::Array{Float64,1}, ::UniformScaling{Bool}; z=[1.0, 1.0, 1.0, 1.0, 1.0, 1.0], P=[5.0 9.0 … -6.0 -10.0; 9.0 17.0 … -8.0 -16.0; … ; -6.0 -8.0 … 17.0 19.0; -10.0 -16.0 … 19.0 25.0], semidefinite=true, ϵ=1.4901161193847656e-8, smartstart=true, scaling=true)
Closest candidates are:
  QuadraticProgram(::MT, ::VT, ::MT, ::VT, ::VT, ::Any; semidefinite, ϵ, smartstart, scaling) where {T, VT<:AbstractArray{T,1}, MT<:AbstractArray{T,2}} at .../.julia/packages/QPDAS/CvMCc/src/quadraticProgram.jl:38 got unsupported keyword arguments "z", "P"
  QuadraticProgram(::MT, ::VT, ::MT, ::VT, ::VT) where {T, VT<:AbstractArray{T,1}, MT<:AbstractArray{T,2}} at .../.julia/packages/QPDAS/CvMCc/src/quadraticProgram.jl:38 got unsupported keyword arguments "z", "P", "semidefinite", "ϵ", "smartstart", "scaling"
  QuadraticProgram(::MT, !Matched::MT, !Matched::VT, ::VT, ::VT, ::PT, !Matched::PFT, !Matched::VT, !Matched::VT, !Matched::Bool, !Matched::VT, !Matched::VT, !Matched::BoxConstrainedQP{T,GT,VT}) where {T, GT<:(QPDAS.AbstractCholeskySpecial{T,MT} where MT), VT<:AbstractArray{T,1}, MT<:AbstractArray{T,2}, PT, PFT} at .../.julia/packages/QPDAS/CvMCc/src/quadraticProgram.jl:22 got unsupported keyword arguments "z", "P", "semidefinite", "ϵ", "smartstart", "scaling"

Here is my code:

function getSolution(points)    # array of tuples with a tuple and an Int64
    A = [points[i][2] for i=1:length(points)]
    A = reshape(A, 1, length(points))
    b = [0.0 for i=1:length(points)]
    C = diagm(-1 .* ones(length(points)))
    d = b
    M = constructMatrix(points)

    qp = QuadraticProgram(A, b, C, d, z = ones(length(points)), P = M;
            semidefinite = true, ϵ = sqrt(eps(Float64)), smartstart = true, scaling = true)

    sol, val = solve!(qp)
    return sol
end

I understand that it says that the types of my variables don't match the ones that are expected by the method QuadraticProgram but I can't figure out in what way. In my understanding it expects the types

matrix, vector, matrix, vector, vector, any; semidefinite, ϵ, smartstart, scaling

which is what I should have. What am I doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜灵血窟げ 2025-02-20 14:29:24

第一个“候选”方法(长)线的末端说明了问题是什么:

获得了不支持的关键字参数“ z”,“ p”

,即使它们处于正确的位置,也不能按名称传递位置参数。即,在此调用中,

    qp = QuadraticProgram(A, b, C, d, z = ones(length(points)), P = M;
        semidefinite = true, ϵ = sqrt(eps(Float64)), smartstart = true, scaling = true)

z =p =使其不再被视为位置参数。因此,错误,因为朱莉娅(Julia)试图在匹配这些功能定义中找到关键字参数,并且在其中失败。 (即使无法通过名称传递的位置论据 - 甚至是选择 - 是我与朱莉娅的小宠儿之一。关键字参数的半彩龙定界符是可选的,而是可以成为逗号,也可以使它成为逗号在这种情况下,问题不太明显。)

将该行更改为:

qp = QuadraticProgram(A, b, C, d, ones(length(points)), M;
        semidefinite = true, ϵ = sqrt(eps(Float64)), smartstart = true, scaling = true)

IE只是删除z =p =应该解决问题并调用正确的方法。

The end of the (long) line for the first "Candidate" method says what the problem is:

got unsupported keyword arguments "z", "P"

In Julia, positional arguments cannot be passed by name, even if they're in the correct position. I.e., in this call

    qp = QuadraticProgram(A, b, C, d, z = ones(length(points)), P = M;
        semidefinite = true, ϵ = sqrt(eps(Float64)), smartstart = true, scaling = true)

The z = and P = make it so that those are no longer seen as positional arguments. Hence the error, since Julia tries to find keyword arguments in the function definition that match these, and fails in that. (The fact that positional arguments can't be passed via names - even optionally - is one of my minor pet peeves with Julia. The fact that the semi-colon delimiter for keyword arguments is optional and can instead be a comma, also makes the issue non-obvious in this case.)

Changing that line to:

qp = QuadraticProgram(A, b, C, d, ones(length(points)), M;
        semidefinite = true, ϵ = sqrt(eps(Float64)), smartstart = true, scaling = true)

i.e. just removing z = and P = should fix the issue and call the right method.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文