MethodError:没有与parseNLExpr_runtime

时间:2018-11-12 03:48:08

标签: matrix nlp sum julia

Julia中的以下代码为解决NLP问题而出现错误。

using JuMP
using Ipopt
using DataFrames,ConditionalJuMP
m = Model(solver=IpoptSolver())

#importing data 

 xi=[-1.016713795   0.804447648 0.932137661 1.064136698  -0.963217531
     -1.048396778   1.076371484 1.099027177 1.061556926  -0.95185481
     -0.980261302   0.271253807 0.184946729 1.062838197  -0.958794505
     -0.980703191   0.278820569 0.231132677 1.062967459  -0.959302488
     -0.953074503   -0.00768112 0.128808175 1.067743779  -0.978524489
     -1.014866259   0.815325963 1.065956208 1.067059122  -0.974682291
     -0.995088119   0.550359991 0.845087207 1.066556784 -0.973154887]
 xj=xi
 pii=[-300
     -259.6530828
     -284.3708955
     -291.3387625
     -342.4479859
     -356.5031603
     -351.0154738]

 sample_size=7
 bus_num=5
 tempsum=0
 #define variables
 @variable(m,aij[1:2*bus_num,1:2*bus_num]) # define  matrix by 
                                             2bus_num*2bus_num

 for n=1:sample_size
    for i=1:bus_num
       for j=1:bus_num
        tempsum=(aij[i,j]*xi[n,i]*xj[n,j]-pii[n,2])^2+tempsum
       end
    end
 end

 #define constraints
 @constraint(m, [i=1:2*bus_num,j=2*bus_num],aij[i,j]==aij[j,i])
 @constraint(m, [i=1:2*bus_num,j=2*bus_num],aij[i,j]*aij[i,j]<=aij   
 [i,i]*aij[j,j])
 @constraint(m, [i=1:2*bus_num,j=2*bus_num],aij[i,i]*aij[j,j]<=0.25*
 (aij[i,i]+aij[j,j])*(aij[i,i]+aij[j,j]))

 #define NLP objective function

 @NLobjective(m, Min, tempsum)

 solve(m)
 println("m = ",getobjectivevalue(m))
 println("Aij = ", getvalue(aij))

但是操作后,显示错误如下。

  

MethodError:没有与parseNLExpr_runtime(:: JuMP.Model,   :: JuMP.GenericQuadExpr {Float64,JuMP.Variable},   :: Array {ReverseDiffSparse.NodeData,1},:: Int64,:: Array {Float64,1})

该错误发生在@NLobjective(m, Min, tempsum)上,但是我不知道如何修改代码。可以请任何人帮我吗?

此外,由于我想获得正定矩阵aij,因此我也为如何在矩阵aij中添加正定约束感到困惑。

1 个答案:

答案 0 :(得分:0)

@NLobjective(m,Min,tempsum)此代码中的tempsum必须是由Jump.register(***)注册的函数。