# Why the results of my model remain the same even if the objective value changes?

**URL:** <https://discourse.julialang.org/t/why-the-results-of-my-model-remain-the-same-even-if-the-objective-value-changes/46817>\
**Category:** Optimization (Mathematical)\
**Created:** [September 18, 2020, 2:05am UTC](https://discourse.julialang.org/t/why-the-results-of-my-model-remain-the-same-even-if-the-objective-value-changes/46817 "2020-09-18T02:05:59Z")\
**Posts on this page:** 1\
**Showing post:** 2

<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:** [September 18, 2020, 2:39am UTC](https://discourse.julialang.org/t/why-the-results-of-my-model-remain-the-same-even-if-the-objective-value-changes/46817/2 "2020-09-18T02:39:01Z")

</div>

This is the same issue as [Condition in @objective - #5 by odow](https://discourse.julialang.org/t/condition-in-objective/46526/5).

You cannot put conditions like this in the objective, because they get evaluated with JuMP `VariableRef` rather than the _value_ of the variable.

You need to use a mixed-integer reformulation.

```nohighlight
# Instead of
model = Model()
@variable(model, x[1:2], Bin)
@show sum(x) == 0 # false! because x[1] + x[2] != 0
@objective(model, Min, sum(x) == 0 ? 0 : 1)
@show objective_value(model) # 1.0 <-- a constant!

# Use
model = Model()
@variable(model, x[1:2] >= 0, Int)
@variable(model, y, Bin)
M = 10_000 # A number bigger than optimal `sum(x)`.
@constraint(model, sum(x) - M * y <= 0)
@objective(model, Min, 1 * y)

```

MIP-modelling is an art, and there are a lot of tradeoffs and tractability issues you need to consider. e.g., how big is M? You’re going to run into issues if you model is large.

---

_[View the full topic](https://discourse.julialang.org/t/why-the-results-of-my-model-remain-the-same-even-if-the-objective-value-changes/46817)._
