# JuMP takes long time to load the problem/model

**URL:** <https://discourse.julialang.org/t/jump-takes-long-time-to-load-the-problem-model/118593>\
**Category:** Optimization (Mathematical)\
**Tags:** question, jump\
**Created:** [August 25, 2024, 5:55pm UTC](https://discourse.julialang.org/t/jump-takes-long-time-to-load-the-problem-model/118593 "2024-08-25T17:55:55Z")\
**Posts on this page:** 1\
**Showing post:** 14

<div class="post-metadata">

**Author:** ![slwu89](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/slwu89/32/217323_2.png) [@slwu89](https://discourse.julialang.org/u/slwu89)\
**Post date:** [August 28, 2024, 4:34pm UTC](https://discourse.julialang.org/t/jump-takes-long-time-to-load-the-problem-model/118593/14 "2024-08-28T16:34:33Z")

</div>

Very nice new tutorial. Being interested in model building for these things, I typed up a quick tutorial of using acsets (attributed C-sets, a data structure from applied category theory, but in practice something akin to an in-memory relational database with additional equations on paths possible) for generating this type of model. They are exported from the Catlab.jl package. The full script is here [https://jump.dev/JuMP.jl/dev/tutorials/getting\_started/sum\_if/ with acsets (github.com)](https://gist.github.com/slwu89/6adf107fb345a31101545520362789e7)

The data structure which powers this is this acset whose schema is in the screenshot below (produced by `to_graphviz`). The ovals are finite Sets (edges and verticies), and the arrows are Functions. The dots are “attributes” which map to Julia types, in this case `Int` for the demand, and `JuMP.VariableRef` for the flows. The arrows between finite sets are indexed so that reverse lookup is fast.

 ![schema](https://global.discourse-cdn.com/julialang/original/3X/6/3/63863a86300d0c885504b8d229a632108e5a0a03.png)

In the code I used some convenience functions for acsets that are “graph-like”, such as `inedges` but they are just wrappers for the generic way to do inverse lookup on arrows, see the source at: [Catlab.jl/src/graphs/BasicGraphs.jl at main · AlgebraicJulia/Catlab.jl (github.com)](https://github.com/AlgebraicJulia/Catlab.jl/blob/main/src/graphs/BasicGraphs.jl#L116)

```julia
@present SchDemandGraph <: SchGraph begin
    Demand::AttrType
    Flows::AttrType
    d::Attr(V,Demand)
    x::Attr(E,Flows)
end

to_graphviz(SchDemandGraph)

@abstract_acset_type AbstractDemandGraph <: AbstractGraph

@acset_type DemandGraph(SchDemandGraph, index=[:src,:tgt]) <: AbstractDemandGraph

acs_graph = @acset DemandGraph{Int,JuMP.VariableRef} begin
    V=length(nodes)
    E=length(edges)
    src=first.(edges)
    tgt=last.(edges)
    d=demand.(nodes)
end

model = JuMP.Model()
acs_graph[:, :x] = @variable(model, flows[e in Catlab.edges(acs_graph)] >= 0)
@constraint(
    model,
    [n in Catlab.vertices(acs_graph)],
    sum(acs_graph[inedges(acs_graph, n), :x]) -
    sum(acs_graph[outedges(acs_graph, n), :x]) == acs_graph[n, :d]
)

```

Benchmarking results are basically the same as expected. I think that acsets open up interesting possibilities for very expressive model building and fusing data + the LP/MIP model, so it was fun to write out this small example.

 ![benchmark](https://global.discourse-cdn.com/julialang/original/3X/c/b/cb83cfdb57a5e7b89280bb471bf3f5294a247385.png)

---

_[View the full topic](https://discourse.julialang.org/t/jump-takes-long-time-to-load-the-problem-model/118593)._
