Thanks for taking the time to take a look at it.
Regarding encapsulation violations: One of them was accidental. After I got the code largely to where I wanted it, I didn't like the delete $g->{nodes}{out_neg} statements, so I created _keep_only_names() to handle that. I put it into the first example, but forgot to put it into the second example. After thinking about it, I think that a better approach would be to tell the simplify() function which names it needs to care about, so I can use the same graph for multiple runs. If I ever get serious about putting more electronics components in there and other network types, I'll probably do something like that.
For the second one, as you mention, I should put the factory functions build_impedance() and build_pad() into the Gr package.
I don't generally write OO code in perl (aside from using packages from CPAN), as generally I use perl for my "let's learn about some problem domain before getting serious" language. I find good OO code really requires you to have a sufficient understanding of the problem domain before you start figuring out what the classes are or should be. I don't often get to use perl at the $job, so I generally use perl to explore the problem, then switch to an "approved" language, with classes and objects and whatnots ;^).
Your solution to removing the duplicate node() calls is amusing looking. I may have to play with it a little and see how I like it.
...roboticus
When your only tool is a hammer, all problems look like your thumb.
In reply to Re^2: Resistor network simplifier
by roboticus
in thread Resistor network simplifier
by roboticus
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |