# Converting a schematic into a graph

I've been working for some time trying to figure out how it might be possible to translate a schematic into something like a node graph, where each node is a component.

I've taken some liberties in creating it due to my limited understanding, but it seems to be working now for basic resistor circuits, for example:

# define the components
V1 = Battery(5)
R1 = Resistor(100)
R2 = Resistor(200)
R3 = Resistor(300)

# connect the components and graph
c = Circuit()
c.connect(V1, R1).connect([R2,R3]).ground_all()
c.graph()


Now I have a directed graph that solves for the currents at the edges (Everycircuit on the left):

This only handles the most basic cases (nothing time-related, multiple input/output, etc.). A couple questions about this:

• Other than showing current, what additional things would a normal 'current-solver' show or do?
• What seem to be the main ambiguities from the representation of the circuit on the right?
• Not sure about the wisdom of making components nodes and currents edges. Your 100 ohm resistor appears to have three connections. It's obvious what's happening in this toy case, but what happens with an increase in complexity? Nets, the wires, are the numbered nodes in circuit solvers, the current-carrying edges are the links between components and nodes. Does your formulation allow anything to be done that the conventional one doesn't? – Neil_UK Feb 9 at 6:50
• @Neil_UK -- thanks, could you please clarify what you mean by "Nets" ? Does your formulation allow anything to be done that the conventional one doesn't? <-- of course not, it's really just for me to understand basic circuits a bit better -- as you can see from my other questions, I'm very new to this. – David542 Feb 9 at 6:58
• Nets are the wires, aka conductors or voltage points. Have you ever looked at a SPICE netlist? In a circuit simulator, where all components are ideal, the components are defined as being strung between nets. Have a look at this and this. It sounds like you're re-inventing the wheel, with no idea of what a cart looks like. A netlist lists each component, and the numbers of the nodes that it's connected to. Get a circuit simulator, I usually recommend LTSpice, it's free and the de facto hobbyist standard. – Neil_UK Feb 9 at 7:08
• Also see pages 10 and 11 (to start) from here. – jonk Feb 9 at 7:46
• @David542 Also note their use in Figure 2.2, where the devices are nodes. You may enjoy this paper. – jonk Feb 9 at 7:57

When you design a circuit in a given CAD tool, your design is reduced to a list of nets called a... Netlist. A netlist includes all the components and the nodes in your design. A node is a conductor to which your components connect. This makes sense when you think about the most basic representation of components and conductors. The Former being an input and an output, and the later being a point (node).

You've got your data model flipped around. Your graph should represent common connections as nodes and your components as edges.

This approach provides a more accessible data model when solving lumped element models. Checkout Mr. Kirchhoff

• The OP (from prior discussions) is struggling to develop his own graph-theoretic ideas about representing schematics. I don't think the OP will discover anything new. But it's a worthy exercise of one's own imagination to try. Having an existing answer won't help the OP. Finding errors in the OP's ideas would help. Frankly, I think this is the wrong place to be asking, as everyone here knows already the "right way" to do it. The OP wants to find something that "sings in his own mind," though. And apparently, the EESE melody doesn't sings well for the OP. Or, the OP wants a new melody. – jonk Feb 9 at 7:50
• If you yourself are interested, see Figure 2.2 here. There, a circuit is indeed represented with devices at the nodes. Chapter 2 of this thesis discusses a variety of graph representations as a basis for the rest. It's worth reading for those interested in alternative approaches to analysis. – jonk Feb 9 at 8:00
• @Yoshimitsu -- thanks, yes I think I have switched around the concept of nodes and edges for the above diagram, but I've updated that. – David542 Feb 10 at 3:31

As explained in an answer to your previous question you are being inconsistent with your nodes. You have shown three terminals on R1 in your network diagram. R1 can only have two. You need an extra node.

Figure 1. Missing node.