Liking cljdoc? Tell your friends :D

Migrating from Loom

This guide is for moving code from aysylu/loom or the net.clojars.savya/loom fork to cljgrapht.

When To Migrate

Migrate when you need JGraphT algorithms, JVM performance, or direct Java graph interop.

Do not migrate when you need ClojureScript or immutable graph values. loom graphs are immutable values. cljgrapht wraps mutable JGraphT graphs. Mutators return the graph for threading, but they change the same object in place.

Function Mapping

loom.graph / loom.algcljgrapht
loom.graph/graphcljgrapht.core/graph
loom.graph/digraphcljgrapht.core/digraph
loom.graph/weighted-graphcljgrapht.core/weighted-graph
loom.graph/weighted-digraphcljgrapht.core/weighted-digraph
loom.graph/nodescljgrapht.core/vertices
loom.graph/edgescljgrapht.core/edges
loom.graph/successorscljgrapht.core/successors
loom.graph/predecessorscljgrapht.core/predecessors
loom.graph/add-nodescljgrapht.core/add-vertex, repeated
loom.graph/add-edgescljgrapht.core/add-edge, repeated
loom.alg/bf-traversecljgrapht.algo/bfs
loom.alg/bf-pathcljgrapht.algo/shortest-path
loom.alg/dijkstra-pathcljgrapht.algo/shortest-path
loom.alg/dijkstra-path-distcljgrapht.algo/shortest-path or shortest-path-length
loom.alg/bellman-fordcljgrapht.algo/bellman-ford
loom.alg/astar-pathcljgrapht.algo/astar
loom.alg/astar-distcljgrapht.algo/astar, then :weight
loom.alg/topsortcljgrapht.algo/topological-sort
loom.alg/dag?cljgrapht.algo/dag?
loom.alg/connected-componentscljgrapht.algo/connected-components
loom.alg/connected?cljgrapht.algo/connected?
loom.alg/scccljgrapht.algo/strongly-connected-components
loom.alg/strongly-connected?cljgrapht.algo/strongly-connected?
loom.alg/bipartite?cljgrapht.algo/bipartite?
loom.alg/bipartite-setscljgrapht.algo/bipartite-sets
loom.alg/greedy-coloringcljgrapht.algo/greedy-coloring
loom.alg/max-flowcljgrapht.algo/max-flow
loom.alg/prim-mstcljgrapht.algo/minimum-spanning-tree
loom.alg/maximal-cliquescljgrapht.algo/maximal-cliques
loom.alg/clustering-coefficientcljgrapht.algo/clustering-coefficient
loom.alg/lonerscljgrapht.algo/isolated-vertices
loom.alg/densitycljgrapht.algo/density
loom.alg/distinct-edgescljgrapht.core/edges, then normalize if needed
loom.alg/isomorphism?cljgrapht.algo/isomorphic?
loom.alg/pre-traversecljgrapht.algo/dfs

Beyond Loom

These cljgrapht functions expose JGraphT capabilities without direct Loom counterparts.

cljgraphtNotes
cljgrapht.algo/bellman-ford-distancesSingle-source Bellman-Ford distances.
cljgrapht.algo/all-pairs-shortest-path-lengthFloyd-Warshall all-pairs shortest paths.
cljgrapht.algo/johnson-all-pairsJohnson all-pairs shortest paths.
cljgrapht.algo/k-shortest-pathsYen k shortest simple paths.
cljgrapht.algo/all-simple-pathsAll simple directed paths between two vertices.
cljgrapht.algo/cycle?Directed cycle detection.
cljgrapht.algo/vertices-on-cyclesVertices participating in directed cycles.
cljgrapht.algo/simple-cyclesDirected simple cycle enumeration.
cljgrapht.algo/maximum-matchingEdmonds maximum cardinality matching.
cljgrapht.algo/maximum-weight-matchingKolmogorov weighted matching.
cljgrapht.algo/bipartite-matchingHopcroft-Karp bipartite matching.
cljgrapht.algo/min-cutMinimum source/sink cut from push-relabel.
cljgrapht.algo/coloringSelectable coloring algorithms.
cljgrapht.algo/global-clustering-coefficientWhole-graph clustering score.
cljgrapht.algo/corenessCore number per vertex.
cljgrapht.algo/betweenness-centralityBetweenness centrality scores.
cljgrapht.algo/closeness-centralityCloseness centrality scores.
cljgrapht.algo/pagerankPageRank scores.
cljgrapht.gen/complete-graphJGraphT complete graph generator.
cljgrapht.gen/ring-graphJGraphT ring graph generator.
cljgrapht.gen/star-graphJGraphT star graph generator.
cljgrapht.gen/grid-graphJGraphT grid graph generator.
cljgrapht.gen/gnp-random-graphSeedable Erdos-Renyi generator.
cljgrapht.gen/barabasi-albert-graphSeedable Barabasi-Albert generator.
cljgrapht.gen/watts-strogatz-graphSeedable Watts-Strogatz generator.
cljgrapht.io/dotDOT export.
cljgrapht.io/read-dotDOT import with string vertex ids.
cljgrapht.io/graphmlGraphML export.

Not Covered

Loom areacljgrapht statusWorkaround
loom.alg/post-traverseNo direct wrapper.Use JGraphT interop directly or keep Loom for that traversal.
loom.attrNo separate attribute namespace.Put attributes in vertex values or maintain an external map.
loom.io/viewNo visualization wrapper.Export DOT with cljgrapht.io/dot and render with Graphviz.
ClojureScriptNot supported.Keep Loom for CLJS code.

Attribute Pattern

Loom attribute code often keeps identity and attributes separate:

(require '[loom.graph :as lg]
         '[loom.attr :as attr])

(-> (lg/graph [:a :b])
    (attr/add-attr :a :label "Alice"))

In cljgrapht, vertices can be arbitrary Clojure values. Put the attributes in the vertex value when that fits your model:

(require '[cljgrapht.core :as g])

(def alice {:id :a :label "Alice"})
(def bob {:id :b :label "Bob"})

(def gr (g/graph [[alice bob]]))

If vertex identity and attributes must change independently, keep vertices as stable ids and store attributes in a separate map.

Incremental Migration With cljgrapht.loom

cljgrapht.loom extends Loom protocols to raw JGraphT graphs. Load the namespace for side effects, then Loom algorithms can consume a cljgrapht graph:

(require '[cljgrapht.core :as g]
         '[cljgrapht.loom]
         '[loom.alg :as alg])

(def gr (g/weighted-digraph [[:a :b 1.0] [:a :c 10.0] [:b :c 1.0]]))

(alg/dijkstra-path gr :a :c)
;; => (:a :b :c)

This lets you migrate construction first, then replace Loom algorithms one call site at a time.

DFS Ordering

Loom pre-traverse visits neighbors in adjacency order. cljgrapht.algo/dfs uses JGraphT's stack-based iterator, so later neighbors can be visited first. If exact traversal order is observable in your tests, update the expected order while migrating.

Can you improve this documentation?Edit on GitHub

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close