# Why the @objective value is negative?

**URL:** <https://discourse.julialang.org/t/why-the-objective-value-is-negative/46781>\
**Category:** Optimization (Mathematical)\
**Created:** [September 17, 2020, 2:26pm UTC](https://discourse.julialang.org/t/why-the-objective-value-is-negative/46781 "2020-09-17T14:26:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sogrbilja](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sogrbilja/32/17521_2.png) [@sogrbilja](https://discourse.julialang.org/u/sogrbilja)\
**Post date:** [September 17, 2020, 2:26pm UTC](https://discourse.julialang.org/t/why-the-objective-value-is-negative/46781/1 "2020-09-17T14:26:13Z")

</div>

I have this model (using cbc solver):

```julia

        @variable(premex, PRODAMOUNT[op_k in keys(_ORDER_PRODUCTs_ALL), u_k in keys(UNITS), t in TIME], Int, lower_bound = 0)

        @objective(
            premex,
            Min,
            sum(
                sum(
                        (
                            (iszero(
                                    sum(
                                        PRODAMOUNT[op_k, u_k, t] * _PRODUCTs_ALL[op["product"]]["bagSize"] 
                                        for (op_k, op) in _ORDER_PRODUCTs_ALL
                                    )
                                ) ? 0 : u["cap"]
                            ) - 
                            sum(
                                PRODAMOUNT[op_k, u_k, t] * _PRODUCTs_ALL[op["product"]]["bagSize"] 
                                for (op_k, op) in _ORDER_PRODUCTs_ALL
                            )
                        ) * u["util_cost1"]
                        for (u_k, u) in UNITS
                    )  
                    for t in TIME
                )
        )

            for t in TIME
                @constraint(
                    premex, 
                    [u_k in keys(UNITS)],
                    sum(
                        PRODAMOUNT[op_k, u_k, t] * _PRODUCTs_ALL[op["product"]]["bagSize"]
                        for (op_k, op) in _ORDER_PRODUCTs_ALL
                        ) 
                        <= UNITS[u_k]["cap"]
                )
            end

```

Objective value: -461275000.00000000

How? Why negative value?

UNITS[u\_k][“cap”] and u[“cap”] are the same

---

<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 17, 2020, 8:20pm UTC](https://discourse.julialang.org/t/why-the-objective-value-is-negative/46781/2 "2020-09-17T20:20:33Z")

</div>

Because you haven’t fixed the `iszero` issue: [Condition in @objective - #5 by odow](https://discourse.julialang.org/t/condition-in-objective/46526/5)

Look at your objective function use `objective_function(premex)`. It won’t be what you think it is.

---

<div class="post-metadata">

**Author:** ![sogrbilja](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sogrbilja/32/17521_2.png) [@sogrbilja](https://discourse.julialang.org/u/sogrbilja)\
**Post date:** [September 18, 2020, 1:18am UTC](https://discourse.julialang.org/t/why-the-objective-value-is-negative/46781/3 "2020-09-18T01:18:31Z")

</div>

Oh, this with Objective value is so confusing, but thanx for clarifying this for me too. I am not using iszero any more.
