Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
KADMOS
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LR-FPP-MDO
KADMOS
Commits
df2dd811
Commit
df2dd811
authored
7 years ago
by
Anne-Liza
Browse files
Options
Downloads
Patches
Plain Diff
Bug fix and speed up get_possible_function_order()
Former-commit-id: f9a3406a4d1be155c3b7b872896594a521d79b97
parent
1a39cf52
No related branches found
Branches containing commit
Tags
v0.7.3
Tags containing commit
No related merge requests found
Pipeline
#192744
canceled
1 year ago
Stage: build
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
kadmos/graph/graph_data.py
+24
-11
24 additions, 11 deletions
kadmos/graph/graph_data.py
with
24 additions
and
11 deletions
kadmos/graph/graph_data.py
+
24
−
11
View file @
df2dd811
...
...
@@ -1906,23 +1906,36 @@ class FundamentalProblemGraph(DataGraph, KeChainMixin):
# Get function graph
function_graph
=
self
.
get_function_graph
()
# Find coupled functions
couplings
=
list
(
nx
.
simple_cycles
(
function_graph
))
coupled_functions
=
list
(
set
(
function_id
for
functions
in
couplings
for
function_id
in
functions
))
# Merge coupled functions into one super node
# Add a super node in which the coupled functions will be merged
function_graph
.
add_node
(
'
super_node
'
,
category
=
'
function
'
)
for
function_id
in
coupled_functions
:
function_graph
=
nx
.
contracted_nodes
(
function_graph
,
'
super_node
'
,
function_id
)
# Delete selfloop edges in supernode
function_graph
.
remove_edges_from
(
function_graph
.
selfloop_edges
())
coupled_functions
=
[]
# As long as not all coupled functions are merged into the super node:
while
not
nx
.
is_directed_acyclic_graph
(
function_graph
):
# Find a coupling
try
:
coupling
=
nx
.
find_cycle
(
function_graph
,
orientation
=
'
reverse
'
)
except
:
coupling
=
nx
.
find_cycle
(
function_graph
,
orientation
=
'
original
'
)
# Find the functions in the coupling
functions_in_coupling
=
list
(
set
(
function_id
for
functions
in
coupling
for
function_id
in
functions
))
print
coupling
# Merge the coupled functions in the super node
for
function_id
in
functions_in_coupling
:
if
function_id
!=
'
reverse
'
and
function_id
!=
'
super_node
'
:
coupled_functions
.
append
(
function_id
)
print
coupled_functions
function_graph
=
nx
.
contracted_nodes
(
function_graph
,
'
super_node
'
,
function_id
)
function_graph
.
remove_edges_from
(
function_graph
.
selfloop_edges
())
# Find function order
function_order
=
nx
.
topological_sort
(
function_graph
)
# Replace super node with coupled functions in function order
function_order
[
function_order
.
index
(
'
super_node
'
):
function_order
.
index
(
'
super_node
'
)
+
1
]
=
coupled_functions
function_order
[
function_order
.
index
(
'
super_node
'
):
function_order
.
index
(
'
super_node
'
)
+
1
]
=
coupled_functions
print
function_order
return
function_order
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment