Skip to content
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

[Feature-request] Topological sort with keying function that exposes internal state #143

Open
kaushikcfd opened this issue Jun 17, 2022 · 2 comments · May be fixed by #145
Open

[Feature-request] Topological sort with keying function that exposes internal state #143

kaushikcfd opened this issue Jun 17, 2022 · 2 comments · May be fixed by #145

Comments

@kaushikcfd
Copy link
Collaborator

kaushikcfd commented Jun 17, 2022

Consider the DAG below:

from pytools.graph import compute_topological_order

dag = {"A": {"C"},
       "B": {"E"},
       "C": {"D"},
       "D": set(),
       "E": set(),
       }

colors = {"A": "red",
          "B": "red",
          "C": "blue",
          "D": "red",
          "E": "blue"
          }

sorted_nodes = compute_topological_order(dag, key=lambda x: x)
print(sorted_nodes)                            # ['A', 'B', 'C', 'D', 'E']
print([colors[node] for node in sorted_nodes]) # ['red', 'red', 'blue', 'red', 'blue']

My application needs a valid topological sort that minimizes the jumps from 'red'<->'blue' nodes in the final schedule. And so for this problem, the topological sort order I'm after would be ['A', 'B', 'C', 'E', 'D']. I don't think that's possible with the current interface of compute_topological_order.

@inducer
Copy link
Owner

inducer commented Jun 17, 2022

Is some greedy thing enough, or do you need an actual minimum?

@kaushikcfd
Copy link
Collaborator Author

A greedy thing seems enough.

@kaushikcfd kaushikcfd linked a pull request Jun 18, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants