# Mismatch in the cost function in MOSEK with Convex.jl

**URL:** https://discourse.julialang.org/t/mismatch-in-the-cost-function-in-mosek-with-convex-jl/115374
**Category:** Optimization (Mathematical)
**Created:** [June 9, 2024, 2:12am UTC](https://discourse.julialang.org/t/mismatch-in-the-cost-function-in-mosek-with-convex-jl/115374 "2024-06-09T02:12:30Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![CaG21](https://avatars.discourse-cdn.com/v4/letter/c/c2a13f/32.png) [@CaG21](https://discourse.julialang.org/u/CaG21)
#### Post date: [June 9, 2024, 2:12am UTC](https://discourse.julialang.org/t/mismatch-in-the-cost-function-in-mosek-with-convex-jl/115374/1 "2024-06-09T02:12:30Z")

</div>

I am using Convex.jl and MOSEK to solve a mixed integer second-order cone programming problem.  
The cost function is encoded as  
`minimize(-x + μ * sum(abs.(v)) - a * sum(γ))`  
where `x` (real value), `v` (real vector), and `γ` (binary vector) are the problem variables, and `a` and `μ` are parameters. I noticed that for high values of `μ` there is a mismatch between the log of MOSEK and the cost function computed using the results of the variables. Specifically, MOSEK log reports  
`Objective of best integer solution : -1.342072779625e+01`  
`Best objective bound : -1.342072779625e+01 `  
while if I try to compute the cost function using the results its value is -6.28. Additionally, a cost function having a value lower than -7.21 should be impossible due to the bounds on `x` and `γ`.  
Is there any explanation for this?

PS: the original problem is quite complex and long. I am trying to find a MWE.

---

<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: [June 9, 2024, 3:07am UTC](https://discourse.julialang.org/t/mismatch-in-the-cost-function-in-mosek-with-convex-jl/115374/2 "2024-06-09T03:07:01Z")

</div>

Some questions to help debug:

- Do you have the solution log? What is the status? Did Mosek terminate normally?
- What are the bounds on `x` and `γ`? Did you verify that the solution to `x` and `γ` are actually feasible in their bounds?
- What is a “large” `μ`?

---

<div class="post-metadata">

### Author: ![CaG21](https://avatars.discourse-cdn.com/v4/letter/c/c2a13f/32.png) [@CaG21](https://discourse.julialang.org/u/CaG21)
#### Post date: [June 9, 2024, 4:14pm UTC](https://discourse.julialang.org/t/mismatch-in-the-cost-function-in-mosek-with-convex-jl/115374/3 "2024-06-09T16:14:19Z")

</div>

I’ll reply point by point:

- Yes, it terminates normally, the log is

```julia
An optimal solution satisfying the relative gap tolerance of 1.00e+00(%) has been located.
The relative gap is 0.00e+00(%).
An optimal solution satisfying the absolute gap tolerance of 0.00e+00 has been located.
The absolute gap is 0.00e+00.

Objective of best integer solution : -1.342072779625e+01     
Best objective bound : -1.342072779625e+01
Initial feasible solution objective: Undefined
Construct solution objective : Not employed
User objective cut value : Not employed
Number of cuts generated : 0
Number of branches : 611
Number of relaxations solved : 615
Number of interior point iterations: 18831
Number of simplex iterations : 0
Time spend presolving the root : 0.20
Time spend optimizing the root : 0.30
Mixed integer optimizer terminated. Time: 66.23

```

- `x` must be lower than log(500)=6.21, while the term `a * sum(γ)` is at maximum 1, since the parameter `a` is selected to be 1/length(γ). And yes, the solution is feasible, and the bounds and constraints are well respected.
- Higher than 10000. And it gets worse incresing the value.

---

<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: [June 9, 2024, 9:11pm UTC](https://discourse.julialang.org/t/mismatch-in-the-cost-function-in-mosek-with-convex-jl/115374/4 "2024-06-09T21:11:20Z")

</div>

> the solution is feasible, and the bounds and constraints are well respected.

To clarify: you have checked the value of `x.value`, `v.value` and `γ.value`, and these are okay. But `problem.optval` gives the wrong answer?

Do you have a reproducible example? It’s hard to identify what is going on without one.

---

<div class="post-metadata">

### Author: ![CaG21](https://avatars.discourse-cdn.com/v4/letter/c/c2a13f/32.png) [@CaG21](https://discourse.julialang.org/u/CaG21)
#### Post date: [June 11, 2024, 12:22am UTC](https://discourse.julialang.org/t/mismatch-in-the-cost-function-in-mosek-with-convex-jl/115374/5 "2024-06-11T00:22:02Z")

</div>

Exactly, `x.value`, `v.value`, and `γ.value` are okay, but `problem.optval` gives the wrong answer.

I’ll try to get a MWE and get back here
