Closed btracey closed 5 years ago
Point being, this function could actually be called UniformGraph(nodes, func(types) )
, and we could provide type UniformDAG func(types)
as an easy one to plug in.
That plan SGTM
Okay, here's an updated implementation that almost compiles.
There are a lot of interfaces in graph that don't all quite overlap, and I'm not really sure how to navigate and compose them. I've already added a couple of things, but I can't use graph.Undirect
because DirectedMutator
doesn't implement graph.Graph
. I don't know what that should mean for changing interfaces or functions.
Graph APIs are difficult. When I wrote the UniformDAG function, I defined the necessary interface types at the site of the function definition.
Okay, I can do that if that's what you'd like. I was trying to follow the current package as much as possible.
Once it's working, we can clean it up.
ping
It compiles now. I'll try and add a test later tonight.
Hm, I'll fix this when I can. Sorry.
Is this still something that you want added? If you do, I can pick it up and bring it over to gonum/gonum.
Yea, it would be nice. I can also move it over if you'd prefer, though I know there have been a lot of changes to graph and I haven't been keeping up.
Are you happy with the state this is in (in terms of functionality)?
@btracey Are you still wanting to include this?
Yes, I believe I am happy with the state this is in. At one point I remember thinking I wanted it to be more general, but I'm pretty sure that was the second commit, and it any case it reads general enough. If you could port it over, I'll take a closer read through (and fix it up if it fails) and then we can get it submitted. Thanks, and sorry for the delay.
I've pushed these changes to the new repository in the graph/random-dag
branch, so I'm closing this PR.
This doesn't currently follow the conventions in the package (or even compile), but I wanted to get it up to show you.
This generates a DAG uniformly at random, but more generally one could also generate a DAG uniformly at random that also has all nodes of degree < 4 (or whatever). Instead of the
if g.HasEdgeFromTo(i,)
, you can more generally have an "acceptEdge" function. The requirements of such a function are in the paper, but loosely it has to have equal probability of going from graph A to B and graph B to A, and you have to be able to construct the graph from the line graph. In this way, it doesn't even necessarily have to generate DAGs.