# Get results from CBC solver for optimization

**URL:** <https://discourse.julialang.org/t/get-results-from-cbc-solver-for-optimization/81135>\
**Category:** Optimization (Mathematical)\
**Tags:** question, jump\
**Created:** [May 16, 2022, 8:42am UTC](https://discourse.julialang.org/t/get-results-from-cbc-solver-for-optimization/81135 "2022-05-16T08:42:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ayodyas](https://avatars.discourse-cdn.com/v4/letter/a/90db22/32.png) [@ayodyas](https://discourse.julialang.org/u/ayodyas)\
**Post date:** [May 16, 2022, 8:42am UTC](https://discourse.julialang.org/t/get-results-from-cbc-solver-for-optimization/81135/1 "2022-05-16T08:42:07Z")

</div>

I would like to know how to access the results (constraints value, variable value) from the model created using Cbc and Jump model in Julia

---

<div class="post-metadata">

**Author:** ![math\_opt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/math_opt/32/25317_2.png) [@math\_opt](https://discourse.julialang.org/u/math_opt)\
**Post date:** [May 16, 2022, 8:57am UTC](https://discourse.julialang.org/t/get-results-from-cbc-solver-for-optimization/81135/2 "2022-05-16T08:57:02Z")

</div>

You can find all information on accessing solutions (objective values, variable values, etc.)  
[here](https://jump.dev/JuMP.jl/stable/manual/solutions/#jump_solutions).

For example, for a JuMP model with name `model`, variables `x`, and constraint `c`:  
Objective value can be accessed as `objective_value(model)`. [See [here](https://jump.dev/JuMP.jl/stable/manual/solutions/#Objective-values)]  
Variable values can be accessed as `value.(x)`. [See [here](https://jump.dev/JuMP.jl/stable/manual/solutions/#Primal-solution-values)]  
Constraint value at the solution can be accessed as `value(c)`.

---

<div class="post-metadata">

**Author:** ![ayodyas](https://avatars.discourse-cdn.com/v4/letter/a/90db22/32.png) [@ayodyas](https://discourse.julialang.org/u/ayodyas)\
**Post date:** [May 16, 2022, 9:25am UTC](https://discourse.julialang.org/t/get-results-from-cbc-solver-for-optimization/81135/3 "2022-05-16T09:25:24Z")

</div>

Thank you for the quick support. As I can extract the variable value from the model, but the same is not working for constraints  
tried this command

value.(model[:con\_ineflow\_lower])

getting like this “” no method matching value(::Vector{ConstraintRef{Model, MathOptInterface.ConstraintIndex{MathOptInterface.ScalarAffineFunction{Float64}, MathOptInterface.GreaterThan{Float64}}, ScalarShape}})“”

---

<div class="post-metadata">

**Author:** ![math\_opt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/math_opt/32/25317_2.png) [@math\_opt](https://discourse.julialang.org/u/math_opt)\
**Post date:** [May 16, 2022, 10:05am UTC](https://discourse.julialang.org/t/get-results-from-cbc-solver-for-optimization/81135/4 "2022-05-16T10:05:23Z")

</div>

It is working fine for me:  
If we take the following example:

```julia
using JuMP
using Gurobi

model = Model()
set_optimizer(model, Gurobi.Optimizer)

#Define variables
@variable(model, x>=0)
@variable(model, y>=0)

#Define Constraints
@constraint(model, c1, 3x+2y<=66)
@constraint(model, c2, 9x+4y<=180)
@constraint(model, c3, 2x+10y<=200)

#Define Objective
@objective(model, Max, 90x+75y)

optimize!(model)

```

Now, to extract values:

```julia
objective_value(model) #returns 2250.0
value(x) # returns 10.0
value(y) #returns 18.0
value(c1) #returns 66.0 
value(c2) #returns 162.0 
value(c3) #returns 200.0 

```

This [link](https://discourse.julialang.org/t/please-read-make-it-easier-to-help-you/14757) helps explain what makes it easier for others to help you out. Maybe you want to share an MWE(minimal working example) which would make it easier for others to debug.

Also, update your `JuMP` version if you are using an old version.

---

<div class="post-metadata">

**Author:** ![ayodyas](https://avatars.discourse-cdn.com/v4/letter/a/90db22/32.png) [@ayodyas](https://discourse.julialang.org/u/ayodyas)\
**Post date:** [May 16, 2022, 11:43am UTC](https://discourse.julialang.org/t/get-results-from-cbc-solver-for-optimization/81135/5 "2022-05-16T11:43:43Z")

</div>

Thanks and I am able to get the results for most constraints except 1 and I will crosscheck again if there is some errors in the constraints

Thanks again!
