Wrong objective definition/transcription #381
-
|
Hi, @expression(model, ΔSoC[n ∈ 1:nEV], SoCev[n] .- SoCdep[n])
@objective(model, Min, ∫(cgrid,t)/Dt[end] +
WSoCDep * ∫(sum(γf .* ΔSoC[n].^2 for n ∈ 1:nEV),t)/Dt[end] +
Wlims*∫(sTin .* 𝒪,t)/Dt[end])the first and third parts are linear objectives and are transcribed correctly but the second part =======================================
Academic License
(NOT FOR COMMERCIAL USE)
Artelys Knitro 14.2.0
=======================================
Knitro presolve eliminated 443 variables and 61 constraints.
algorithm 1
datacheck 0
hessian_no_f 1
maxtime_real 900
mip_maxtime_real 900
mip_numthreads 1
ms_enable 1
ms_maxsolves 20
ms_numthreads 1
numthreads 1
outlev 3
The problem is identified as an MPEC.
Problem Characteristics ( Presolved)
-----------------------
Objective goal: Minimize
Objective type: general <----- WHY GENERAL?
Number of variables: 2784 ( 2341)what am I doing wrong? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
|
Can you provide a minimum working example? I don't have a license for Knitro, but it is possible this is just a quirk of the Knitro.jl wrapper. The wrapper might just pass any quadratic objective as a general one. |
Beta Was this translation helpful? Give feedback.
-
|
here's the MWE: model = InfiniteModel(KNITRO.Optimizer);
@infinite_parameter(model, t ∈ [0., 24.], supports = collect(0.:1.:24.),
derivative_method = FiniteDifference(Backward()))
@variable(model, 0.2 .≤ SoCev[n ∈ 1:2] .≤ 1, Infinite(t))
@expression(model, ΔSoC[n ∈ 1:2], SoCev[n] .- 0.85)
γ = ones(2,length(0.:1.:24.)); γ[:,10:15] .= 0.;
@parameter_function(model, γf[n ∈ 1:2] == (t) -> γ[n, round(Int,t+1)])
@objective(model, Min, ∫(sum((γf[n].* ΔSoC[n]).^2 for n ∈ 1:2), t))
optimize!(model)
=======================================
Academic License
(NOT FOR COMMERCIAL USE)
Artelys Knitro 14.2.0
=======================================
No start point provided -- Knitro computing one.
Knitro presolve eliminated 0 variables and 0 constraints.
datacheck 0
hessian_no_f 1
mip_numthreads 1
ms_numthreads 1
numthreads 1
The problem is identified as bound constrained only.
Problem Characteristics ( Presolved)
-----------------------
Objective goal: Minimize
Objective type: general
Number of variables: 50 ( 50)
bounded below only: 0 ( 0)
bounded above only: 0 ( 0)
bounded below and above: 50 ( 50)
fixed: 0 ( 0)
free: 0 ( 0)
Number of constraints: 0 ( 0)
linear equalities: 0 ( 0)
quadratic equalities: 0 ( 0)
gen. nonlinear equalities: 0 ( 0)
linear one-sided inequalities: 0 ( 0)
quadratic one-sided inequalities: 0 ( 0)
gen. nonlinear one-sided inequalities: 0 ( 0)
linear two-sided inequalities: 0 ( 0)
quadratic two-sided inequalities: 0 ( 0)
gen. nonlinear two-sided inequalities: 0 ( 0)
Number of nonzeros in Jacobian: 0 ( 0)
Number of nonzeros in Hessian: 38 ( 38)
Knitro using the Interior-Point/Barrier Direct algorithm.
Iter Objective FeasError OptError ||Step|| CGits
-------- -------------- ---------- ---------- ---------- -------
0 3.522340e+00 0.000e+00
5 4.584285e-20 0.000e+00 1.086e-11 3.385e-05 0
EXIT: Locally optimal solution found.
Final Statistics
----------------
Final objective value = 4.58428486647783e-20
Final feasibility error (abs / rel) = 0.00e+00 / 0.00e+00
Final optimality error (abs / rel) = 1.09e-11 / 1.09e-11
# of iterations = 5
# of CG iterations = 0
# of function evaluations = 7
# of gradient evaluations = 7
# of Hessian evaluations = 5
Total program time (secs) = 0.015 ( 0.000 CPU time)
Time spent in evaluations (secs) = 0.002
===============================================================================when removing the model = InfiniteModel(KNITRO.Optimizer);
@infinite_parameter(model, t ∈ [0., 24.], supports = collect(0.:1.:24.),
derivative_method = FiniteDifference(Backward()))
@variable(model, 0.2 .≤ SoCev[n ∈ 1:2] .≤ 1, Infinite(t))
@expression(model, ΔSoC[n ∈ 1:2], SoCev[n] .- 0.85)
γ = ones(2,length(0.:1.:24.)); γ[:,10:15] .= 0.;
@parameter_function(model, γf[n ∈ 1:2] == (t) -> γ[n, round(Int,t+1)])
@objective(model, Min, ∫(sum(ΔSoC[n].^2 for n ∈ 1:2), t))
optimize!(model)
=======================================
Academic License
(NOT FOR COMMERCIAL USE)
Artelys Knitro 14.2.0
=======================================
No start point provided -- Knitro computing one.
Knitro presolve eliminated 0 variables and 0 constraints.
datacheck 0
hessian_no_f 1
The problem is identified as a convex QP.
The problem is identified as bound constrained only.
Problem Characteristics ( Presolved)
-----------------------
Objective goal: Minimize
Objective type: quadratic <--- HERE it's fine
Number of variables: 50 ( 50)
bounded below only: 0 ( 0)
bounded above only: 0 ( 0)
bounded below and above: 50 ( 50)
fixed: 0 ( 0)
free: 0 ( 0)
Number of constraints: 0 ( 0)
linear equalities: 0 ( 0)
quadratic equalities: 0 ( 0)
gen. nonlinear equalities: 0 ( 0)
linear one-sided inequalities: 0 ( 0)
quadratic one-sided inequalities: 0 ( 0)
gen. nonlinear one-sided inequalities: 0 ( 0)
linear two-sided inequalities: 0 ( 0)
quadratic two-sided inequalities: 0 ( 0)
gen. nonlinear two-sided inequalities: 0 ( 0)
Number of nonzeros in Jacobian: 0 ( 0)
Number of nonzeros in Hessian: 50 ( 50)
Knitro using the Interior-Point/Barrier Direct algorithm.
Iter Objective FeasError OptError ||Step|| CGits
-------- -------------- ---------- ---------- ---------- -------
0 4.629723e+00 0.000e+00
7 3.663736e-15 0.000e+00 8.161e-10 4.356e-04 0
EXIT: Optimal solution found.
Final Statistics
----------------
Final objective value = 3.66373598126302e-15
Final feasibility error (abs / rel) = 0.00e+00 / 0.00e+00
Final optimality error (abs / rel) = 8.16e-10 / 8.16e-10
# of iterations = 7
# of CG iterations = 0
# of function evaluations = 0
# of gradient evaluations = 0
# of Hessian evaluations = 0
Total program time (secs) = 0.009 ( 0.000 CPU time)
Time spent in evaluations (secs) = 0.000
===============================================================================The thing is that I don't think in my application I can remove the |
Beta Was this translation helpful? Give feedback.
-
|
thanks! that solved the issue! the idea was for the solver to recognize the problem as quadratic and enable parallelism. In KNITRO internal parallelism is desabled for general NLP because it is not thread-safe |
Beta Was this translation helpful? Give feedback.
here's the MWE: