-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: assign weights in graph #351
base: main
Are you sure you want to change the base?
Conversation
61a0875
to
fadb142
Compare
fadb142
to
becf772
Compare
7e3fe41
to
d8294c0
Compare
229e617
to
9508c94
Compare
16d2daf
to
900e50e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May not be for this PR. But it will be good idea to add unit test in some of the major method as there may be cases not covered in the TestWeightedGraphBuilder test
Why not use gonum's weighted graph? 🤔 |
pkg/go/graph/weighted_graph.go
Outdated
|
||
//nolint: cyclop | ||
func NewWeightedAuthorizationModelGraph(model *openfgav1.AuthorizationModel) (*WeightedAuthorizationModelGraph, error) { | ||
g, err := NewAuthorizationModelGraph(model) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use the existing builder?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The existing builder's job is to figure out the edges, their directions, etc. This builder's job is to assign weights. Since both are fairly complex jobs i'd like to keep them separate. Makes testing easier and less code per file
@elbuo8 several reasons:
|
Non-Blocking The relationship between the weighted graph builder and the weighted graph is a bit odd. Currently the weighted graph has a dependency of its builder, which seems backwards. Instead of coupling it all together with the current approach: weightedGraph, err := NewWeightedAuthorizationModelGraph(model) I would suggest decoupling them explicitly: weightedGraphBuilder := NewWeightedAuthorizationModelGraphBuilder()
weightedGraph, err := weightedGraphBuilder.Build(model) I know this is introducing an additional step/line of code, however I really don't see the point of having the builder, otherwise. |
pkg/go/graph/weighted_graph_edge.go
Outdated
// isNested signals that this edge is a self-loop. The associated node will also have this flag set to true. | ||
isNested bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put in other words, is this an edge that connects a vertex to itself?
graph TD;
A-->A;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep! not sure what to call it
Description
This is the scaffolding code required to compute weights for each node and edge. It's not meant to support every kind of model - more followup PRs will come. (For example, models with cycles are not handled).
Please review each model in the
weighted_graph_builder_test.go
and visualize the output in https://dreampuf.github.io/GraphvizOnline/. This will help you review the correctness of the weight assignment algorithm.Example