Mercurial > sypikslang
changeset 100:b27b4dede626
added visualization for research tree
author | Rizmari Versfeld <rizziepit@gmail.com> |
---|---|
date | Wed, 09 May 2012 22:10:22 +0200 |
parents | e386ec5d179b |
children | e92035dce1f6 |
files | gamelib/visualize.py run_visualization.py |
diffstat | 2 files changed, 47 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gamelib/visualize.py Wed May 09 22:10:22 2012 +0200 @@ -0,0 +1,39 @@ +import networkx + +import matplotlib.pyplot as plt + +import pylab + +from gamelib import research +from gamelib import schematics +from gamelib.lab import Lab + + +def construct_research_tree(lab): + rt = networkx.DiGraph() + for research in lab.new_research: + rt.add_node(research, label=research.NAME, color='green') + for research in lab.new_research: + for prereq in research.PREREQUISITES: + rt.add_edge(prereq[0], research, weight=1.0/prereq[1], \ + label=prereq[1], color='green') + for schematic in lab.new_schematics: + rt.add_node(schematic, label=schematic.NAME, color='red') + for schematic in lab.new_schematics: + for prereq in schematic.PREREQUISITES: + rt.add_edge(prereq[0], schematic, weight=1.0/prereq[1], \ + label=prereq[1], color='red', size=schematic.COST/10) + return rt + + +def draw(rt): + agraph = networkx.to_agraph(rt) + agraph.graph_attr['label'] = 'Research Tree' + #agraph.layout(prog='dot') + agraph.write('research_tree.dot') + + +def main(): + lab = Lab({'science':{}}) + research_tree = construct_research_tree(lab) + draw(research_tree)