2

I'm studying programming on my own and I would like to have an idea how to solve this problem.

I have been given the set of resistors with given resistances and a given value restot. I can pick a given number of those resistors. How can I make a circuit which resistance is as near as possible to restot? A programmer told me that that one can use genetic algorithms but I'm not limited to use such.

I guess I have to make a linear system of equations using Kirchoff's laws to make equations but as I don't have very much experience on electricity problems nor numerical algorithms to linear systems so I would like to have some guidance about how can I make those equations automatically to computers memory as the system changes all the time. And how can I make sure that the algorithm converges to a better solutions?

The problem is from a Finnish discussion forum.

Jaakko Seppälä
  • 744
  • 2
  • 7
  • 21

3 Answers3

3

Resistors can either exist in series or in parallel, and their resistances add up differently (add values for series, add reciprocals for parallel).

You can also have networks for resistors in series and parallel.

This sounds to me like a classic case of a recursive data structure, and you could probably represent it as a tree, in a similar way to a binary expression tree: http://en.wikipedia.org/wiki/Binary_expression_tree

Combine that some exploratory tree building (you should look into the way Prolog does this) and you can find the best combination of resistors that gets close to your total.

No genetic algorithms in this approach, although you could take a genetic approach to building and refining the tree.

Joe
  • 46,419
  • 33
  • 155
  • 245
0

To apply a genetic algorithm you would need to find a way to represent, mutate and combine the "DNA" of a resistor network.

One way would be to:

  1. Add some number of 0 ohm resistors to your resister set (representing wires).
  2. Number the resistors from 1 to N
  3. For some M, imagine a set of M junctions including the source (1) and sink (M).
  4. You could define which junctions the two endpoints of each resistor are connected to as the unique identifier of a network. This is just an N-tuple of integer pairs in the range 1..M. This tuple can be the "DNA".

Then:

  1. Generate a bunch of random networks from random tuples.
  2. Calculate each networks resistence
  3. Discard some amount of the population farthest from the target resistence.
  4. Combine random pairs of them to form new networks. (perhaps by randomly selecting each resistor endpoint from either parent A or parent B with 50% probability)
  5. Randomly change a few endpoints (mutation).
  6. Goto 2

Not sure if it would actually work exactly like this, but you get the general idea.

There is undoubtably a better non-genetic algorithm, but you specifically asked for a genetic one so there you go.

Andrew Tomazos
  • 66,139
  • 40
  • 186
  • 319
0

If you are not limited to genetic algorithm, then I think you can also solve this problem with help of linear programming. You can encode the problem as below and ask a solver to give the answer for you.

Required Resistance Of Circuit = x ohms

// We want to have total 33 resistors.
selected_in_series_1 + selected_in_series_2 +... + selected_in_series_211 + selected_in_parallel_1 + selected_in_parallel_2 + ... + selected_in_parallel_211 = 33

// Resistor in Series
(selected_in_series_1 * Resistor_1) + (selected_in_series_2 * Resistor_2) + ..(selected_in_series_211 * Resistor_211) = total_resistence_in series

// Similarly write formula for parallel
(selected_in_parallel_1 * 1/Resistor_1) + (selected_in_parallel_2 * 1/Resistor_2) + ..(selected_in_parallel_211 * 1/Resistor_211) = 1/total_resistence_in parallel

total_resistence_in series + total_resistence_in parallel = Required Resistance Of Circuit
Raj
  • 3,300
  • 8
  • 39
  • 67