# \[WIP\] SimpleLazyGraphs.jl - add vertices and edges as needed

**URL:** <https://discourse.julialang.org/t/wip-simplelazygraphs-jl-add-vertices-and-edges-as-needed/84326>\
**Category:** Package Announcements\
**Tags:** question, package, graphs\
**Created:** [July 16, 2022, 6:17pm UTC](https://discourse.julialang.org/t/wip-simplelazygraphs-jl-add-vertices-and-edges-as-needed/84326 "2022-07-16T18:17:57Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![acxz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/acxz/32/16759_2.png) [@acxz](https://discourse.julialang.org/u/acxz)\
**Post date:** [July 16, 2022, 6:17pm UTC](https://discourse.julialang.org/t/wip-simplelazygraphs-jl-add-vertices-and-edges-as-needed/84326/1 "2022-07-16T18:17:57Z")

</div>

Hello all, I’d like to introduce a small module I’ve been trying to implement called SimpleLazyGraphs.jl: [GitHub - acxz/SimpleLazyGraphs.jl: Graph data structures to add vertices and edges as needed for Graphs.jl.](https://github.com/acxz/SimpleLazyGraphs.jl)

Effectively, this module is inspired by the following issue: [a\_star dynamic neighbor creation · Issue #115 · JuliaGraphs/Graphs.jl · GitHub](https://github.com/JuliaGraphs/Graphs.jl/issues/115#event-6214662573)

I’d love to gain feedback on the code that I have already written and suggestions on how to make it more Julian as this is my first time “subtyping” existing types and I’ve been learning quite a few things along the way.

I also have many questions that I’m hoping folks can help me out on.

First, I’ll describe what I’d like this package to be. Basically, I want to piggyback off of the type SimpleGraphs and use the entire functionality of it, besides two methods (`inneighbors` & `outneighbors`) I’d like “overridden” (forgive me for my OOP lingo) or should I say dispatched on my new type SimpleLazyGraph instead of the existing SimpleGraph.

As you can see in the [code](https://github.com/acxz/SimpleLazyGraphs.jl/blob/5686edd032d6600987ed0907c2f9bfbac2fddfa9/src/simplelazygraph.jl#L73-L97) I’ve done that. However, as an added caveat, I’d like to also use the original functionality of SimpleGraph’s `in/outneighbors` method. As you can also see in the code, I had attempted to use `@invoke`, however, it did not work for me and I had to essentially copy and paste the implementation of SimpleGraph’s `in/outneighbors` methods as well as other methods that I needed to just test the functionality like `add_vertex!` and `add_edge!`. Ideally, my SimpleLazyGraph should be able to use the SimpleGraph’s version of these methods.

The second point is about the proper design of the type SimpleLazyGraph. The way I’d like to change `in/outneighbors` is by adding a user defined function. How can/should I do this? As of right now, the user passes in these functions when defining a SimpleLazyGraph and I say those functions inside the SimpleLazyGraph type so that my dispatched `in/outneighbors` functions can use them. It is important that the method signature (in terms of arguments) stays the same so that I can utilize the functionality of the Graphs.jl library, in particular the A\* algorithm for my specific use case.

So while, the functionality of lazily adding to a graph works in my `test/runtests.jl`, my SimpleLazyGraphs.jl package doesn’t have the mechanism to run the Graphs a\_star algorithm yet. I’d like to do this with as much code reuse as possible.

Thank you for reading this and I would appreciate any help to better understand how to do this task.

---

<div class="post-metadata">

**Author:** ![acxz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/acxz/32/16759_2.png) [@acxz](https://discourse.julialang.org/u/acxz)\
**Post date:** [July 16, 2022, 6:22pm UTC](https://discourse.julialang.org/t/wip-simplelazygraphs-jl-add-vertices-and-edges-as-needed/84326/2 "2022-07-16T18:22:25Z")

</div>

ninja edit: If you also have any suggestions on the name, or how to create lazy graphs in a more performant manner please mention that as well. Although, since I’m a bit new to creating julia packages I’d like to understand proper Julia architecture.

---

<div class="post-metadata">

**Author:** ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)\
**Post date:** [July 16, 2022, 6:26pm UTC](https://discourse.julialang.org/t/wip-simplelazygraphs-jl-add-vertices-and-edges-as-needed/84326/3 "2022-07-16T18:26:14Z")

</div>

Looks good! Do I have to use GraphPlot.jl? ( I don’t think Graphs.jl requires GraphPlot.jl…)

---

<div class="post-metadata">

**Author:** ![acxz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/acxz/32/16759_2.png) [@acxz](https://discourse.julialang.org/u/acxz)\
**Post date:** [July 16, 2022, 6:30pm UTC](https://discourse.julialang.org/t/wip-simplelazygraphs-jl-add-vertices-and-edges-as-needed/84326/4 "2022-07-16T18:30:59Z")

</div>

Thanks! Do you believe the value prop offered by this package is useful?

I’d like to use GraphPlot on my SimpleLazyGraphs, but again similar to a\_star I’d need to copy paste quite a lot of SimpleGraphs methods (as i understand currently, if anyone can show me how to get around this that would be great).

I’ll remove GraphPlot from the deps for now. Is it possible to have testing deps? If so, I’d like to move GraphPlot there.

---

<div class="post-metadata">

**Author:** ![acxz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/acxz/32/16759_2.png) [@acxz](https://discourse.julialang.org/u/acxz)\
**Post date:** [July 16, 2022, 6:37pm UTC](https://discourse.julialang.org/t/wip-simplelazygraphs-jl-add-vertices-and-edges-as-needed/84326/5 "2022-07-16T18:37:19Z")

</div>

> I’ll remove GraphPlot from the deps for now. Is it possible to have testing deps? If so, I’d like to move GraphPlot there.

Done, using the older Julia 1.1/2 style testdep for now. [5. Creating Packages · Pkg.jl](https://pkgdocs.julialang.org/v1/creating-packages/#Test-specific-dependencies-in-Julia-1.0-and-1.1)

---

<div class="post-metadata">

**Author:** ![acxz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/acxz/32/16759_2.png) [@acxz](https://discourse.julialang.org/u/acxz)\
**Post date:** [July 16, 2022, 7:02pm UTC](https://discourse.julialang.org/t/wip-simplelazygraphs-jl-add-vertices-and-edges-as-needed/84326/6 "2022-07-16T19:02:40Z")

</div>

I think understanding this thread: [Composition and inheritance: the Julian way](https://discourse.julialang.org/t/composition-and-inheritance-the-julian-way/11231) may give me the answers I need.  
Maybe Graphs.jl would also need some PRs to make some of their methods dispatch on AbstractSimpleGraph instead of the concrete SimpleGraph?

---

<div class="post-metadata">

**Author:** ![acxz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/acxz/32/16759_2.png) [@acxz](https://discourse.julialang.org/u/acxz)\
**Post date:** [July 18, 2022, 2:37pm UTC](https://discourse.julialang.org/t/wip-simplelazygraphs-jl-add-vertices-and-edges-as-needed/84326/7 "2022-07-18T14:37:48Z")

</div>

For the first point, I believe I am now properly using composition.

However, I am still unsure what is the best way of going about user defined function fields. Maybe type parameterization on the function?

Edit: Yep this did the trick! See the commit: [https://github.com/acxz/SimpleLazyGraphs.jl/commit/3da26600441d8474431b3c7370e0e58d8afa0ba5](https://github.com/acxz/SimpleLazyGraphs.jl/commit/3da26600441d8474431b3c7370e0e58d8afa0ba5)
