Skip to content
Snippets Groups Projects
Commit c77dc4b8 authored by Andreas Makus's avatar Andreas Makus
Browse files

finished class method that adds KB graphs to MDOproblem-instance; added helper...

finished class method that adds KB graphs to MDOproblem-instance; added helper functions that create edge-tuples and add node attributes; created new class MDPgraph that serves as super-class for other graph classes (MCG, FPG, PSG); added graph-contraction method to super class; added Graph-subclass MCG; added method that generates graph object for the MCG
parent c7a0276a
No related branches found
No related tags found
No related merge requests found
......@@ -3,8 +3,6 @@
"version":1.0,
"creator":"Ali Elham",
"description": "provide description here."},
"execution_info":{ "run time (s)":20,
"fidelity level":"L1",
"precision":0.05}
"execution_info":{ "runTime":20, "fidelity":"L1", "precision":0.05}
}
......@@ -3,8 +3,6 @@
"version":1.0,
"creator":"Mengmeng Zhang",
"description": "In this case Q3D only performs the inviscid VLM analysis in order to provide the loads per wing strip in an aeroDataSetForLoads associated with the flightLoadCase. These loads can then be used for further analysis with other tools. A tool that fits well to this analysis is TUD's wing weight estimation tool EMWET."},
"execution_info":{ "run time (s)":20,
"fidelity level":"L1",
"precision":0.05}
"execution_info":{ "runTime":20, "fidelity":"L1", "precision":0.05}
}
import networkx as nx
from pyKADMOS.MDOproblem import MdoProblemInit
class Graph(object):
"""
Super class for graph subclasses (MCG, FPG, PSG), contains common functions.
"""
def __init__(self, knowledgeBase):
self.knowledgeBase = knowledgeBase
assert isinstance(knowledgeBase, MdoProblemInit), 'The required argument to instantiate a graph must be of type "MDOknowledgeBase".'
def get_contracted_graph(self, graph, contractionLevel):
"""
Function to contract the nodes of a graph to a given xpath level.
:param graph: graph to be contracted
:param contractionLevel: int from 0 (highest level) to X (lowest level existing in XML schema)
:return: graph with contracted nodes
"""
# check input
assert (contractionLevel >= 0) & isinstance(contractionLevel, (int, long)), "Contraction level should be non-negative integer."
# create clean copy of graph
contracted_graph = nx.DiGraph(graph)
# iterate over each graph node and contract nodes where required.
for node, data in contracted_graph.nodes_iter(data=True):
if data['level'] > contractionLevel:
# Find higher level sibling at required level; split node at separator
split_xpath = node.split('/')[1:] # remove first entry (this is empty since string starts with '/'
# Create xpath of required node
required_node = '/' + '/'.join(split_xpath[0:contractionLevel + 1])
# Add node if not in contracted graph
if required_node not in contracted_graph:
contracted_graph.add_node(required_node,
shape = 'd',
category = 'variable group',
label = split_xpath[contractionLevel],
level = contractionLevel)
# Contract node with its higher level sibling
contracted_graph = nx.contracted_nodes(contracted_graph, required_node, node, self_loops=True)
#TODO: include rules to manage a higher contraction level
return contracted_graph
class MCG(Graph):
def __init__(self, knowledgeBase):
super(self.__class__, self).__init__(knowledgeBase)
def get_graph(self, contractionLevel = None):
"""
Function to create Maximal Connectivity Graph (Pate, 2014) by composing a list of graphs.
:return: maximal connectivity graph (MCG)
"""
functionGraphs = self.knowledgeBase.functionGraphs
# if contracted level procided, reduce function Graphs to that level
if contractionLevel is not None:
conGraphs = [] # initialize contracted graph list
for graph in functionGraphs:
conGraph = self.get_contracted_graph(graph, contractionLevel)
conGraphs.append(conGraph)
functionGraphs = conGraphs # replace function graphs with contracted function graphs
MCG = nx.DiGraph() # initilaze MCG
for g in functionGraphs: # TODO: this will be contracted graphs
MCG = nx.compose(MCG, g)
return MCG
This diff is collapsed.
import pprint
import networkx as nx
from pyKADMOS.MDOproblem import MDOproblem
exProb = MDOproblem('KB_CPACS')
graph3 = exProb._get_function_graph('EMWET')
from pyKADMOS.MDOproblem import MdoProblemInit
from pyKADMOS.MDOgraph import Graph, MCG
from pyKADMOS.MDOvisualization import plot_graph
kb = MdoProblemInit('KB_CPACS')
mcg = MCG(kb)
mcGraph = mcg.get_graph(3)
plot_graph(mcGraph, 1, show_now=True)
print "ALL GOOD!!!"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment