# Bug in write\_to\_file for max-type problems in bilinear terms?

**URL:** <https://discourse.julialang.org/t/bug-in-write-to-file-for-max-type-problems-in-bilinear-terms/118781>\
**Category:** Optimization (Mathematical)\
**Tags:** jump\
**Created:** [August 29, 2024, 4:18pm UTC](https://discourse.julialang.org/t/bug-in-write-to-file-for-max-type-problems-in-bilinear-terms/118781 "2024-08-29T16:18:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![anogaja](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/anogaja/32/211670_2.png) [@anogaja](https://discourse.julialang.org/u/anogaja)\
**Post date:** [August 29, 2024, 4:18pm UTC](https://discourse.julialang.org/t/bug-in-write-to-file-for-max-type-problems-in-bilinear-terms/118781/1 "2024-08-29T16:18:11Z")

</div>

The max objective problem in JuMP when written to an mps file is converted to a min type objective by flipping the signs. However, it didn’t do it for the bilinear terms in the objective.

Am I missing something?

Following is the MWE

```julia
model = Model()

# Define variables x1 and x2
@variable(model, x1 >= 0)
@variable(model, x2 >= 0)

# Define the bilinear objective function
@objective(model, Max, 3*x1 + 2*x2 + x1 * x2)

# Add the constraints
@constraint(model, x1^2 + x2^2 <= 10)
@constraint(model, x1 + x2 >= 1)

# Write the model to an mps file
write_to_file(model, "my_model.mps")

# Read the saved model
new_model = read_from_file("my_model.mps")

print(model)

# Max x1*x2 + 3 x1 + 2 x2
# Subject to
# x1 + x2 >= 1.0
# x1² + x2² <= 10.0
# x1 >= 0.0
# x2 >= 0.0

print(new_model)

# Min x1*x2 - 3 x1 - 2 x2
# Subject to
# c1 : x1 + x2 >= 1.0
# c1_1 : x1² + x2² <= 10.0
# x1 >= 0.0
# x2 >= 0.0

```

---

<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:** [August 29, 2024, 8:20pm UTC](https://discourse.julialang.org/t/bug-in-write-to-file-for-max-type-problems-in-bilinear-terms/118781/2 "2024-08-29T20:20:26Z")

</div>

Hi @anogaja, welcome to the forum 😄

That’s a nasty bug that you have found. Sorry!

I’ll get it fixed ASAP: [[FileFormats.MPS] quadratic maximization objectives · Issue #2538 · jump-dev/MathOptInterface.jl · GitHub](https://github.com/jump-dev/MathOptInterface.jl/issues/2538)

p.s., Thanks for the MWE. It was very helpful

---

<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:** [August 29, 2024, 9:16pm UTC](https://discourse.julialang.org/t/bug-in-write-to-file-for-max-type-problems-in-bilinear-terms/118781/3 "2024-08-29T21:16:50Z")

</div>

This bug was my fault, and the oversight was pretty embarrassing: [[FileFormats.MPS] fix MAX\_SENSE with quadratic objective by odow · Pull Request #2539 · jump-dev/MathOptInterface.jl · GitHub](https://github.com/jump-dev/MathOptInterface.jl/pull/2539)

I’ll get a new release tagged in the next day or so.
