Julia provides information of type: number of iterations, solution time, gap, number of variables, number of constraints
I am not sure what the context of your question is. Do you have some code to explain your situation to us? And finally, what is your question, what do you want to know?
I developed a mathematical code and need some information about the functions, and this information is the output data I mentioned earlier (number of iterations, solution time, interval, number of variables, number of constraints)
It would be much easier to help you if you provided an MWE, or at least linked the earlier discussion for context.
The profiler can help with iterations and time:
https://docs.julialang.org/en/v1/manual/profile/index.html
It sounds like you are using an optimization package, so I’m not sure about the other two questions.
In case it helps the original poster or anyone else, MWE == minimum working example, also known as minimum reproducible example. StackOverflow has a nice write-up about how to do this:
Also worth taking a look at this post
Based on a previous question you had related to optimization code (Jump?), I assume that you refer to such problems.
The Optim package solvers provide a nice resume of several of the things you ask for. Optim is nice in the sense of being written in Julia, and the developers can therefore provide lots of information about the inner workings of the code. Unfortunately, solvers for general constrained problems are lacking in Optim (I think). Probably, integer/mixed-integer solvers are also lacking?? (It takes time to write good code…!!)
Jump is more of an optimization modeling language and provides access to industry strength solvers, typically based on compiled C (or Fortran?) code. Because of that, the Jump solvers are probably more limited in the scope of information available.
You ask for “gap” information. Are you referring to the duality gap?
Solution time… can easily be found using the time
macro, i.e.:
julia> @time solve(...)
or:
julia> @time begin
solve(...)
....
end
if you want to time multiple commands.
Yes, I mean an optimization problem.
This is the code I am building, I have tried to summarize it to stay in MWE format (I do not know if it is correct).
If it is an optimization model, the answer I want to get is about the time that Julia takes to calculate the constraint function, the number of variables, and the time it took to generate the objective value.
This is the code.
I used the time macro as in the example, and it did not work.
using JuMP, GLPK
Model1 = Model(with_optimizer(GLPK.Optimizer))
L = [12; 60]
T = [0.25; 0.5]
D = [36]
@variable(Model1, Y[i=1:2] >=0)
@objective(Model1, Max, sum(Y[i]*L[i] for i ∈ 1:2))
Yy = transpose(Y)
for i in 1
@constraint(Model1,Yy*T[2*i-2+1:2*i] <= D[i])
end
print(Model1)
optimize!(Model1) #model status
println("Objective value: ", JuMP.objective_value(Model1))
println("Y[1] = ", JuMP.value(Y[1]))
println("Y[2] = ", JuMP.value(Y[2]))
OK… I think this counts as MWE (eh – tp
?)… at least your code runs on my PC, and I get:
Max 12 Y[1] + 60 Y[2]
Subject to
Y[1] >= 0.0
Y[2] >= 0.0
0.25 Y[1] + 0.5 Y[2] <= 36.0
Objective value: 4320.0
Y[1] = 0.0
Y[2] = 72.0
Regarding timing – perhaps my suggestion missed what you are interested in – but here is what I get:
julia> @time optimize!(Model1) #model status
0.000054 seconds (10 allocations: 576 bytes)
Next step: check documentation of JuMP and GLPK, and see if there is an information flag to provide the rest of the information you need.
By googling GLPK
, I found the following link: https://en.wikibooks.org/wiki/GLPK/Using_GLPSOL
, which may provide you with an answer to whether the underlying GLPK algorithm has the information you need. If it doesn’t, you may need to consider other solvers.
Ok, thanks very much!!
You can also do MOI.get(Model1, MOI.SolveTime())
Thank you for your help.
Still about the optimization code I’m building, I’d like to get an output with the relative difference of the final optimization.
I need to find the gap between the best value and the best possible target value. I tried to use RelativeGap (), but I did not succeed.
I would also like to output from my code the cumulative number of iterations during the optimization process in resolving the problem. I tried using the BarrierIterations (), but it did not force success.
This is the code:
using JuMP, GLPK
Model1 = Model(with_optimizer(GLPK.Optimizer))
L = [12 ;60]
T = [0.25 0.1 0.1; 0.5 0.75 0.4]
D = [36; 22; 15]
@variable(Model1, Y[i=1:2] >=0)
@objective(Model1, Max, sum(Y[i]*L[i] for i ∈ 1:2))
Yy = transpose(Y)
for i in 1:3
@constraint(Model1,Yy*T[2*i-2+1:2*i] <= D[i])
end
print(Model1)
optimize!(Model1) #model status
println("Objective value: ", JuMP.objective_value(Model1))
println("Y[1] = ", JuMP.value(Y[1]))
println("Y[2] = ", JuMP.value(Y[2]))
@time optimize!(Model1)
[Model1]
MOI.get(Model1, MOI.SolveTime())
The RelativeGap is not implemented yet for the GLPK interface but @odow is adding it in https://github.com/JuliaOpt/GLPK.jl/pull/101