From 27f784cced6127f0adf06e24668ad09aba795842 Mon Sep 17 00:00:00 2001 From: Ben Butler-Cole Date: Fri, 5 Aug 2022 16:44:58 +0100 Subject: [PATCH 1/2] Clarify use of stocks as variables --- docs/spec.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/docs/spec.md b/docs/spec.md index 83a9135..3a5449e 100644 --- a/docs/spec.md +++ b/docs/spec.md @@ -137,5 +137,8 @@ The above system shows that `Engineers` has an initial value of `Managers * 4`, a maximum value of `Managers * 8` and then shows that both `Engineers` and `Managers` grow at multiples of the value of the `Recruiters` stock. -This is also a good example of using the `Recruiters` stock as -a variable, as it doesn't' actually change over time. +This is also a good example of using the `Recruiters` stock as a +variable, as it doesn't actually change over time. (Although note that +this pattern can only be used for constants: if you specify a formula +that will only be used for the initial value, which is probably not +what you want.) From 3bfd9b7fd918c1c604b09c7d63de4221eee698cc Mon Sep 17 00:00:00 2001 From: Ben Butler-Cole Date: Fri, 5 Aug 2022 16:45:21 +0100 Subject: [PATCH 2/2] Exclude stocks without flows from graph If a stock isn't part of a flow then it's almost certainly being used as a variable. Including it in the graph just clutters things up. --- systems/viz.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/systems/viz.py b/systems/viz.py index f918680..7d84564 100644 --- a/systems/viz.py +++ b/systems/viz.py @@ -10,19 +10,25 @@ def as_dot(model, rankdir="LR"): - mapping = {s.name: str(i) for i, s in enumerate(model.stocks)} + mapping = {s.name: str(i) for i, s in enumerate(model.stocks)} dot = Digraph(comment=model.name) dot.attr(rankdir=rankdir) - - for stock in model.stocks: - dot.node(mapping[stock.name], stock.name) + + nodes_in_flow = set() for flow in model.flows: source_id = mapping[flow.source.name] destination_id = mapping[flow.destination.name] + nodes_in_flow.add(source_id) + nodes_in_flow.add(destination_id) dot.edge(source_id, destination_id) + for stock in model.stocks: + node_id = mapping[stock.name] + if node_id in nodes_in_flow: + dot.node(node_id, stock.name) + return dot