Fork me on GitHub
#clojure
<
2022-11-12
>
onetom09:11:40

there was a talk about rewriting some court case management system in Clojure, starting with a small piece. they talked about juvenile detention and how the incentives of the court and the police are misaligned. does anyone know which talk was it? I'd like to recommend it to someone.

onetom19:11:55

that's not the one, but it was also very interesting, thx!

Martynas Maciulevičius13:11:55

Did anyone play around with https://github.com/aysylu/loom? I'm trying to put int tuples like this one [1 :attr 2] and get it to calculate a shortest path. I can easily do the case where I specify [1 2] as an edge but I want each edge to be named :thinking_face: Is there a way to name each edge?

Martynas Maciulevičius13:11:17

Figured it out by using an external map. Not sure if it's the best way :thinking_face:

(def edges [[1 :a1 2]
            [1 :a2 2]
            [2 :b 3]
            [3 :c 4]])

(def indexed-edges (->> edges
                        (map (fn [[k _ v :as link]]
                               {[k v] #{link}}))
                        (reduce (partial merge-with into) {})))

(def dg (apply loom.graph/digraph (keys indexed-edges)))

(->> (loom.alg/shortest-path dg 1 3)
     (#(map vector (butlast %) (rest %)))
     (map indexed-edges)
     (reduce into))
output:
#{[1 :a2 2] [2 :b 3] [1 :a1 2]}

jpmonettas14:11:34

Long time since I used loom but I think this namespaces https://cljdoc.org/d/aysylu/loom/1.0.2/api/loom.attr if for adding attributes to nodes, edges, etc

Martynas Maciulevičius14:11:09

Oh. I don't want to decorate my graph after creation as it still means that I'll have to do a second pass just to add these edge names. I thought I'll start with three-tuple and it could work like this. Also if I do a second-pass addition then I'll have to calculate what each edge points into. And I already do it in my example as I construct the map using merge-with. :thinking_face: I think that highlighting is the best use of loom.attr as you may not want to highlight all of the nodes at the same time: https://github.com/aysylu/loom/blob/master/src/loom/attr.cljc#L122 Edit: But that function is probably only from UI as it adds fill color which isn't what you'd use in a tree algorithm.