# Getting the upper bound of an objective function (MILP with HiGHS)

**URL:** <https://discourse.julialang.org/t/getting-the-upper-bound-of-an-objective-function-milp-with-highs/103890>\
**Category:** Optimization (Mathematical)\
**Tags:** jump\
**Created:** [September 15, 2023, 12:21pm UTC](https://discourse.julialang.org/t/getting-the-upper-bound-of-an-objective-function-milp-with-highs/103890 "2023-09-15T12:21:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![cf357](https://avatars.discourse-cdn.com/v4/letter/c/b4bc9f/32.png) [@cf357](https://discourse.julialang.org/u/cf357)\
**Post date:** [September 15, 2023, 12:21pm UTC](https://discourse.julialang.org/t/getting-the-upper-bound-of-an-objective-function-milp-with-highs/103890/1 "2023-09-15T12:21:39Z")

</div>

I’m working on an assignment problem where the solver maximizes

```julia
@objective(model, Max, sum(B[u] for u in U))

```

where `B` is a binary vector of entities satisfying some conditions in the assignment plan `A[u, f, t]`, which denotes a task assigned to user `u` at factory `f` at a time `t`.

In some cases, I’m not interested in getting the actual allocation plan but just to know how many users will actually satisfy my set of other constraints. I’d typically set a time limit or iteration limit, and HiGHS seems to be doing a good job at computing this upper bound, as I can tell when reading the “BestBound” column from the output.

However, I cannot find anything in the API that could return that value, as JuMP / HiGHS would trigger an error as the set of solutions is empty.

Did I miss anything?

I had a look at the HiGHS source code, and I believe I’d need to access this value:

```julia
// HighsMipSolverData.cpp

  std::array<char, 16> lb_string =
      convertToPrintString((int)mipsolver.orig_model_->sense_ * lb);

```

---

<div class="post-metadata">

**Author:** ![mike\_k](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mike_k/32/211864_2.png) [@mike\_k](https://discourse.julialang.org/u/mike_k)\
**Post date:** [September 15, 2023, 12:43pm UTC](https://discourse.julialang.org/t/getting-the-upper-bound-of-an-objective-function-milp-with-highs/103890/2 "2023-09-15T12:43:55Z")

</div>

There a function [ObjectiveBound](https://jump.dev/MathOptInterface.jl/stable/reference/models/#MathOptInterface.ObjectiveBound) in `MathOptInterface`. I typically use something like:

```julia
using MathOptInterface
const MOI = MathOptInterface
...
bestbound = MOI.get(model, MOI.ObjectiveBound())

```

This works at least with CPLEX.

---

<div class="post-metadata">

**Author:** ![cf357](https://avatars.discourse-cdn.com/v4/letter/c/b4bc9f/32.png) [@cf357](https://discourse.julialang.org/u/cf357)\
**Post date:** [September 15, 2023, 1:09pm UTC](https://discourse.julialang.org/t/getting-the-upper-bound-of-an-objective-function-milp-with-highs/103890/3 "2023-09-15T13:09:42Z")

</div>

Thanks. I’m actually already using the ` objective_bound()` function from the wrapper, but this fails if there’s no best solution found. e,g,

```julia
        Nodes | B&B Tree | Objective Bounds | Dynamic Constraints | Work
     Proc. InQueue | Leaves Expl. | [BestBound] BestSol Gap | Cuts InLp Confl. | LpIters Time

         0 0 0 0.00% (72 ) -inf inf 0 0 0 0 17.8s

```

Then, if I try to access `MOI.ObjectiveBound())` after the solver stops, I get

```julia
BestBound: Inf

ERROR: LoadError: Result index of attribute MathOptInterface.ObjectiveValue(1) out of bounds. There are currently 0 solution(s) in the model.

```

---

<div class="post-metadata">

**Author:** ![mike\_k](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mike_k/32/211864_2.png) [@mike\_k](https://discourse.julialang.org/u/mike_k)\
**Post date:** [September 15, 2023, 1:28pm UTC](https://discourse.julialang.org/t/getting-the-upper-bound-of-an-objective-function-milp-with-highs/103890/4 "2023-09-15T13:28:28Z")

</div>

Unfortunately, I forgot to mention that I only check for bounds if an integer solution already exists by `if result_count( model ) > 0 ... end`.  
I had several times a similar problem, namely to obtain the LP relaxation, for which I have not yet found a solution other then computing it manually by relaxing the integers constraints.

---

<div class="post-metadata">

**Author:** ![cf357](https://avatars.discourse-cdn.com/v4/letter/c/b4bc9f/32.png) [@cf357](https://discourse.julialang.org/u/cf357)\
**Post date:** [September 15, 2023, 5:02pm UTC](https://discourse.julialang.org/t/getting-the-upper-bound-of-an-objective-function-milp-with-highs/103890/5 "2023-09-15T17:02:47Z")

</div>

I’m working on a patch to extend the HiGHS API.  
Will report the results here.
