# Read Gurobi's .sol file format with JuMP

**URL:** <https://discourse.julialang.org/t/read-gurobis-sol-file-format-with-jump/122387>\
**Category:** Optimization (Mathematical)\
**Tags:** question, jump, gurobi\
**Created:** [November 7, 2024, 5:57pm UTC](https://discourse.julialang.org/t/read-gurobis-sol-file-format-with-jump/122387 "2024-11-07T17:57:13Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jean\_F](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jean_f/32/213253_2.png) [@Jean\_F](https://discourse.julialang.org/u/Jean_F)\
**Post date:** [November 7, 2024, 5:57pm UTC](https://discourse.julialang.org/t/read-gurobis-sol-file-format-with-jump/122387/1 "2024-11-07T17:57:13Z")

</div>

Is there a way to read with JuMP , a .sol file with as ones produced by Gurobi?

---

<div class="post-metadata">

**Author:** ![Palli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palli/32/3380_2.png) [@Palli](https://discourse.julialang.org/u/Palli)\
**Post date:** [November 7, 2024, 6:33pm UTC](https://discourse.julialang.org/t/read-gurobis-sol-file-format-with-jump/122387/2 "2024-11-07T18:33:17Z")

</div>

I would think yes with JuMP, since Gurobi (and CPLEX) are supported with JuMP:

> **[Installation Guide · JuMP](https://jump.dev/JuMP.jl/stable/installation/#Supported-solvers)**
>
> Documentation for JuMP.

Since those are both proprietary, then what I think you meant is can you use JuMP and only open source software for:

> **[SOL file format: solution files](https://www.ibm.com/docs/en/icos/20.1.0?topic=cplex-sol-file-format-solution-files)**
>
> The SOL file format supports solution files.

and I don’t ~~really~~ know. How complex/readable is this format? Is Gurobi’s .sol completely different, or somewhat or fully compatible with IBM’s CPLEX? Some other software might also be able to read it.

> [@JuMP: save SOL file for MILP](https://discourse.julialang.org/t/jump-save-sol-file-for-milp/101101/4):
>
> Gurobi’s .sol file is not the same as IBM’s: But sure, there are probably solver-specific ways of writing a solution file, but none that are solver-independent. You’re better off writing something like this: import JSON solution = Dict(name(x) =\> value(x) for x in all\_variables(model)) write("solution.json", JSON.json(solution))

EDIT: It seems with free software, there’s something to read SOL (right format?), see:

> <https://github.com/jump-dev/MathOptInterface.jl/blob/f6f8a09cedb3d8b2e10e18a4ff6e2440ec6954cb/src/FileFormats/NL/sol.jl#L284-L284>

> <https://github.com/jump-dev/AmplNLWriter.jl/commit/1bcb89cbf966ed6c3585cb962ea0776b689e6e4c>

I was shocked to see how expensive those solvers are and if you’re long for alternatives for that then I would first find software that can read the files or replace them in any language:

> <https://or.stackexchange.com/questions/11146/non-proprietary-python-friendly-alternatives-to-cplex-and-gurobi>

---

<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:** [November 7, 2024, 8:17pm UTC](https://discourse.julialang.org/t/read-gurobis-sol-file-format-with-jump/122387/3 "2024-11-07T20:17:59Z")

</div>

Hi @Jean_F, welcome to the forum 😄

> Is there a way to read with JuMP , a .sol file with as ones produced by Gurobi?

Nope.

A better question is: why do you want to do this?

---

<div class="post-metadata">

**Author:** ![Jean\_F](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jean_f/32/213253_2.png) [@Jean\_F](https://discourse.julialang.org/u/Jean_F)\
**Post date:** [November 7, 2024, 11:02pm UTC](https://discourse.julialang.org/t/read-gurobis-sol-file-format-with-jump/122387/4 "2024-11-07T23:02:29Z")

</div>

Thank you @odow,  
That’s what i thought. Recently I submitted a request on Gurobi support. I would like share the link but it seems that I’m not allowed to do . So the topic on Gurobi support is :" Gurobi stucks even after the time limit ". I hope you can find it.

Finally, as I couldn’t get the result with JuMP, I used the Gurobi command line from the Windows terminal to perform the optimisation. This worked, so I produced the .sol file to save the solution. Now I want to ‘read’ the solution obtained and use it as a starting solution with JuMP. My aim is to be able to access the values of the solutions via a JuMP model because I need to post-process them and my post-processing code is made for a JuMP solved model from which I can access the variables values.

For the issue I raised about Gurobi, perhaps that could be a topic in its own right. But if you have any idea why this is happening, I’d love to hear your opinion.

---

<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:** [November 7, 2024, 11:10pm UTC](https://discourse.julialang.org/t/read-gurobis-sol-file-format-with-jump/122387/5 "2024-11-07T23:10:09Z")

</div>

The `.sol` file seems simple enough. You should be able to parse it manually?

> For the issue I raised about Gurobi, perhaps that could be a topic in its own right. But if you have any idea why this is happening, I’d love to hear your opinion.

I don’t understand what the problem is. You set a time limit and Gurobi didn’t terminate? Didn’t terminate with a feasible solution?

Do you have a reproducible example?

---

<div class="post-metadata">

**Author:** ![Jean\_F](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jean_f/32/213253_2.png) [@Jean\_F](https://discourse.julialang.org/u/Jean_F)\
**Post date:** [November 8, 2024, 12:23pm UTC](https://discourse.julialang.org/t/read-gurobis-sol-file-format-with-jump/122387/6 "2024-11-08T12:23:58Z")

</div>

> [@odow](#):
>
> The `.sol` file seems simple enough. You should be able to parse it manually?

Yes I finally did it like that :

```julia
# sol file loading
a= readlines("model1_solution.sol")
b=zeros(Float64,length(a)-1) 
i=1
for txt in a[2:end] # the first line of .sol is about the objective value, we don't need it
    b[i]=parse(Float64,split(txt, " ")[2])
    i+=1
end

# set start values for the model 1
x = all_variables(model1)
set_start_value.(x, b)

```

Maybe this can be usefull to someone else.

> [@odow](#):
>
> I don’t understand what the problem is. You set a time limit and Gurobi didn’t terminate? Didn’t terminate with a feasible solution?
> 
> Do you have a reproducible example?

I don’t have a reproducible example yet . I can share you the .mps file, but i’m not sure that’s enough to reproduce the issue. So, in order not to waste your time, i will try to clarify the example ( and the issue) and post it on this forum.
