1

I'm attempting to write a short mini-program in Python that plays around with force-based algorithms for graph drawing.

I'm trying to minimize the number of times lines intersect. Wikipedia suggests giving the lines an electrical charge so that they repel each other. I asked my physics teacher how I might simulate this, and she mentioned using calculus with Coulomb's Law, but I'm uncertain how to start.

Could somebody give me a hint on how I could do this? (Or alternatively, another way to tweak a force-based graph drawing algorithm to minimize the number of times the lines cross?) I'm just looking for a hint; no source code please.

In case anybody's interested, my source code and a youtube vid I made about it.

Michael0x2a
  • 58,192
  • 30
  • 175
  • 224

1 Answers1

1

You need to explicitly include a term in your cost function that minimizes the number of edge crossings. For example, for every pair of edges that cross, you incur a fixed penalty or, if the edges are weighted, you incur a penalty that is the product of the two weights.

Martin Harrigan
  • 1,044
  • 11
  • 28