Open arcondello opened 1 year ago
What would be the purpose of the graph besides visualization? I believe if it serves any logical purpose (by logical meaning we would use it elsewhere and try to interpret/infer something from it) then it should be a Iterable[Iterable[c0 dtype]] and we could then have a method that would access this Iterable of Iterables and construct the graph.
As for the name, if the literature doesn't have a standard meaning for it, why not name it as is, i.e. "Constraint Relationship Graph". I'd like to have a crack at this if possible, may I ask if there are any specific format you would prefer this, and in any specific file for a PR?
What would be the purpose of the graph besides visualization?
It can serve a logical purpose in some instances.
I believe if it serves any logical purpose (by logical meaning we would use it elsewhere and try to interpret/infer something from it) then it should be a Iterable[Iterable[c0 dtype]] and we could then have a method that would access this Iterable of Iterables and construct the graph.
I agree that a more general format is probably preferable. Upon further consideration I think {c0: [c1, ...], c1: [c0, ...], ...}
is probably the best return type. This would allow automatic construction of a NetworkX graph, e.g.
G = nx.Graph(cqm.constraint_dual_graph())
We could also allow a bit more future proofing by using a triple-nested-dict structure {c0: {c1: {}, ...}, ...}
which would allow the addition of edge data (for instance maybe the list of shared variables?) in the future. If we go with the former, I do think we should document that users should only expect that the "inner" iterable is an iterable, rather than a list specifically. So
class ConstraintedQuadraticModel:
...
def constraint_dual_graph(self) -> typing.Dict[typing.Hashable, typing.Iterable[typing.Hashable]]:
...
that way we can go from dict-of-lists to dict-of-dict-of-dict later if we like.
As for the name, if the literature doesn't have a standard meaning for it, why not name it as is, i.e. "Constraint Relationship Graph".
On further review, I think constraint dual graph is the literature name for it. So I like constraint_dual_graph()
as a name for the method.
I'd like to have a crack at this if possible, may I ask if there are any specific format you would prefer this, and in any specific file for a PR?
Contributions are very welcome! See above for opinions on the formatting. As for the file, I think as a method of the ConstrainedQuadraticModel
in this file.
Example for a QAP
Additional Considerations