Question

I need to represent in a graph (preferable using graphviz) a calculation of a formula, like this:

raw_unitary_value = <user_input>
quantity = <user_input>
discount = <user_input>

net_unitary_value = raw_unitary_value * (1 - discount/100)
total_value       = quantity * net_unitary_value 

I could implement thus:

raw_unity_value   -> net_unitary_value
discount          -> net_unitary_value
net_unitary_value -> total_value
quantity          -> total_value

Or

raw_unity_value        -> net_unitary_value_calc
discount               -> net_unitary_value_calc
net_unitary_value_calc    [label="%"]
net_unitary_value_calc -> net_unitary_value

net_unitary_value -> total_value_calc
quantity          -> total_value_calc
total_value_calc     [label="*"]
total_value_calc  -> total_value

But in both the approaches I can't feel comfortable that this is a good solution. This is only the first part of the formula, it has about 30 variables in total.

It is difficult to represent the details of the calculation, so in the second approach I added a new node called *_calc to represent the operation that has been made.

Does anybody have an idea of how to render this kind of explanation? Or, maybe, is this case not suitable to be represented in a graph?

Thanks

Was it helpful?

Solution

Traditionally in a (control) engineering sense, what you're asking for is a block diagram. Block diagrams are convenient way to capture relationships that depend on prior state (typically a summation or integration in a discrete or continuous sense). This method is pretty extensive in scope and I'm sure it encompasses what you want.

Although graphviz could do this, you're looking for a higher degree of layout control than what you typically get with the graphviz tools. There are engineering tools like simulink for solving this problem, but they tend to be excessive if you already have the code. Perhaps a better option is to generate LaTeX / TiKZ code, and generate PDFs from there. This ensures you get (academic) publication quality diagrams. There are great packages for doing this already.

block diagram

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top