# Modular implementation of optimization problems with JuMP

**URL:** <https://discourse.julialang.org/t/modular-implementation-of-optimization-problems-with-jump/116261>\
**Category:** Optimization (Mathematical)\
**Tags:** jump, energy\
**Created:** [June 26, 2024, 2:06pm UTC](https://discourse.julialang.org/t/modular-implementation-of-optimization-problems-with-jump/116261 "2024-06-26T14:06:27Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![pierre-haessig](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pierre-haessig/32/217129_2.png) [@pierre-haessig](https://discourse.julialang.org/u/pierre-haessig)\
**Post date:** [June 27, 2024, 8:42am UTC](https://discourse.julialang.org/t/modular-implementation-of-optimization-problems-with-jump/116261/3 "2024-06-27T08:42:20Z")

</div>

Yes, this doc section was part of my “literature review” since you had already mentioned it on Stack Overflow or here, so it’s in the “References” section of my notebook.

Most parts (wrapping the model in a function, having subfunctions to create variables or constraints) do apply (and are applied) to my use case. Only I didn’t need dedicated data structures like [`KnapsackObject`](https://jump.dev/JuMP.jl/stable/tutorials/getting_started/design_patterns_for_larger_models/#Create-better-data-structures).

So the only aspect I didn’t find in that doc (and that was my motivation for making this code design study and posting it here) was the ability to _instantiate several replicas of more or less the same inner problem inside one larger problem_. Thus my interest in [dynamic variable naming](https://discourse.julialang.org/t/using-anonymous-and-or-symbols-to-create-dynamic-varible-names/83095). I the end, I decided to use anonynous variables, identified by their `String` key in a `Dict`. Having one `Dict` per inner problem is like having a dedicated namespace for each inner subproblem, so this solves the duplicate name clashes. Still, as a bonus, I append an optional “stage” suffix to the `base_name` of each variable, so that the String/Latex representation is less ambiguous.

---

_[View the full topic](https://discourse.julialang.org/t/modular-implementation-of-optimization-problems-with-jump/116261)._
