# How to get rid of the error: "MethodError: no method matching optimize!(::AffExpr)"

**URL:** <https://discourse.julialang.org/t/how-to-get-rid-of-the-error-methoderror-no-method-matching-optimize-affexpr/109218>\
**Category:** Optimization (Mathematical)\
**Tags:** question, jump, gurobi\
**Created:** [January 24, 2024, 9:21pm UTC](https://discourse.julialang.org/t/how-to-get-rid-of-the-error-methoderror-no-method-matching-optimize-affexpr/109218 "2024-01-24T21:21:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aliaksandra\_Kizhyk](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aliaksandra_kizhyk/32/202801_2.png) [@Aliaksandra\_Kizhyk](https://discourse.julialang.org/u/Aliaksandra_Kizhyk)\
**Post date:** [January 24, 2024, 9:21pm UTC](https://discourse.julialang.org/t/how-to-get-rid-of-the-error-methoderror-no-method-matching-optimize-affexpr/109218/1 "2024-01-24T21:21:37Z")

</div>

Hello everyone!  
I urgently need some help with this code. I am getting the error “MethodError: no method matching optimize!(::AffExpr)”, and I can’t understand why it appears. I am not proficient with programming and need to write this code for my university project. Please help me.

“the code was deleted for copyright reasons”

---

<div class="post-metadata">

**Author:** ![adienes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adienes/32/37459_2.png) [@adienes](https://discourse.julialang.org/u/adienes)\
**Post date:** [January 24, 2024, 9:24pm UTC](https://discourse.julialang.org/t/how-to-get-rid-of-the-error-methoderror-no-method-matching-optimize-affexpr/109218/2 "2024-01-24T21:24:10Z")

</div>

maybe add `return model` at the end of your function

---

<div class="post-metadata">

**Author:** ![Aliaksandra\_Kizhyk](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aliaksandra_kizhyk/32/202801_2.png) [@Aliaksandra\_Kizhyk](https://discourse.julialang.org/u/Aliaksandra_Kizhyk)\
**Post date:** [January 24, 2024, 9:34pm UTC](https://discourse.julialang.org/t/how-to-get-rid-of-the-error-methoderror-no-method-matching-optimize-affexpr/109218/3 "2024-01-24T21:34:10Z")

</div>

Oh my God, it seems that it works.  
Thank you! I didn’t even think in this direction.
