# Query Solution Time

**URL:** <https://discourse.julialang.org/t/query-solution-time/22263>\
**Category:** Optimization (Mathematical)\
**Created:** [March 24, 2019, 1:00am UTC](https://discourse.julialang.org/t/query-solution-time/22263 "2019-03-24T01:00:49Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![octavia9](https://avatars.discourse-cdn.com/v4/letter/o/97f17d/32.png) [@octavia9](https://discourse.julialang.org/u/octavia9)\
**Post date:** [March 24, 2019, 1:00am UTC](https://discourse.julialang.org/t/query-solution-time/22263/1 "2019-03-24T01:00:49Z")

</div>

Hello,

I am very new to Julia and JuMP. I am using CPLEX 12.8 together with my optimization problem.

Instead of using self-defined time function to capture the total time spent in the optimization process, is there a direct way to print out the total time (root+branch-and-cut) of CPLEX?

I try to use SolveTime() in MathOptInterface (v0.8.4) but it didn’t work.

When I typed MathOptInterface.SolveTime(), the result just give me

MathOptInterface.SolveTime().

And when I typed MathOptInterface.SolveTime(problem1), the error said

MethodError: no method matching MathOptInterface.SolveTime(::Model)  
Closest candidates are:  
MathOptInterface.SolveTime() at path

It would be nice if someone can show me how to correctly use the code since I also need to get the information of relative gap as well.

Thank you so much.

---

<div class="post-metadata">

**Author:** ![leethargo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/leethargo/32/6004_2.png) [@leethargo](https://discourse.julialang.org/u/leethargo)\
**Post date:** [March 24, 2019, 9:07am UTC](https://discourse.julialang.org/t/query-solution-time/22263/2 "2019-03-24T09:07:01Z")

</div>

In MathOptInterface, you should use the `get` method to query different results from a model (or variable etc.). See the [example in the docs](http://www.juliaopt.org/MathOptInterface.jl/v0.8/apimanual/#Solving-and-retrieving-the-results-1) where `TerminationStatus` is queried. `SolveTime` should work in the same way.

---

<div class="post-metadata">

**Author:** ![octavia9](https://avatars.discourse-cdn.com/v4/letter/o/97f17d/32.png) [@octavia9](https://discourse.julialang.org/u/octavia9)\
**Post date:** [March 24, 2019, 2:17pm UTC](https://discourse.julialang.org/t/query-solution-time/22263/3 "2019-03-24T14:17:58Z")

</div>

Thank you for your reply. However, I tried the example code, it gave me error again.

Here is what I typed

`optimize!(problem1)`  
`status = MOI.get(problem1, TerminationStatus())`  
`total_time = MOI.get(problem1, SolveTime())`

The error is like this:

`UndefVarError: TerminationStatus not defined`  
`UndefVarError: SolveTime not defined`

I am pretty sure I declare the package already, but I don’t know why I can’t use the get method of MathOptInterface. Could you give me some insight? Thank you.

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [March 24, 2019, 4:58pm UTC](https://discourse.julialang.org/t/query-solution-time/22263/4 "2019-03-24T16:58:08Z")

</div>

You need to prepend `MOI.`.

```julia
MOI.get(model, MOI.SolveTime())

```

---

<div class="post-metadata">

**Author:** ![octavia9](https://avatars.discourse-cdn.com/v4/letter/o/97f17d/32.png) [@octavia9](https://discourse.julialang.org/u/octavia9)\
**Post date:** [March 24, 2019, 5:08pm UTC](https://discourse.julialang.org/t/query-solution-time/22263/5 "2019-03-24T17:08:44Z")

</div>

Oh that explains it!!! Thank you so much! Now I can move on…thank you!!

---

<div class="post-metadata">

**Author:** ![octavia9](https://avatars.discourse-cdn.com/v4/letter/o/97f17d/32.png) [@octavia9](https://discourse.julialang.org/u/octavia9)\
**Post date:** [March 24, 2019, 5:28pm UTC](https://discourse.julialang.org/t/query-solution-time/22263/6 "2019-03-24T17:28:11Z")

</div>

Hello sorry to bother again,

The `SolveTime()` works.

When I tried the same way to retrieve MIP relative gap, it gave me error again.

`gap_info = MOI.get(model, MOI.RelativeGap())`

The error message is

`MethodError: no method matching get_relative_mip_gap(::CPLEX.Optimizer)`  
`Closest candidates are:`  
`get_relative_mip_gap(!Matched::LinQuadOptInterface.MockLinQuadOptimizer) at`

However, I used the same code to retrieve `ObjectiveBound()` it works. It seems like some of the attributes are not working. Could you give me some insight about why would this happen? Thank you.

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [March 24, 2019, 11:25pm UTC](https://discourse.julialang.org/t/query-solution-time/22263/7 "2019-03-24T23:25:25Z")

</div>

`RelativeGap` isn’t implemented for CPLEX yet.

I’ve opened an issue: [MOI: implement RelativeGap · Issue #228 · jump-dev/CPLEX.jl · GitHub](https://github.com/JuliaOpt/CPLEX.jl/issues/228)

---

<div class="post-metadata">

**Author:** ![angeloaliano1](https://avatars.discourse-cdn.com/v4/letter/a/7ea924/32.png) [@angeloaliano1](https://discourse.julialang.org/u/angeloaliano1)\
**Post date:** [March 31, 2019, 1:14pm UTC](https://discourse.julialang.org/t/query-solution-time/22263/8 "2019-03-31T13:14:06Z")

</div>

How can I obtain the relative Gap, If are not implemented?

---

<div class="post-metadata">

**Author:** ![octavia9](https://avatars.discourse-cdn.com/v4/letter/o/97f17d/32.png) [@octavia9](https://discourse.julialang.org/u/octavia9)\
**Post date:** [March 31, 2019, 5:53pm UTC](https://discourse.julialang.org/t/query-solution-time/22263/9 "2019-03-31T17:53:02Z")

</div>

I guess we need to calculate by ourselves. Just use the definition of Gap and manually record the best incumbent and best bound.

I really hope this issue can be solved. It would make things easier to get the value of incumbent, best bound, root relaxation gap and computational time for people who work in MIP problems…Is there anything I can do?

---

<div class="post-metadata">

**Author:** ![angeloaliano1](https://avatars.discourse-cdn.com/v4/letter/a/7ea924/32.png) [@angeloaliano1](https://discourse.julialang.org/u/angeloaliano1)\
**Post date:** [March 31, 2019, 9:09pm UTC](https://discourse.julialang.org/t/query-solution-time/22263/10 "2019-03-31T21:09:28Z")

</div>

I can’t to implement in CPLEX.jl.  
I made a issue in [https://github.com/JuliaOpt/CPLEX.jl](https://github.com/JuliaOpt/CPLEX.jl) and requested to implement in a new version. Let go to wait.
