Skip to content

uknfire/tsmpy

Repository files navigation

tsmpy

tsmpy is a Python implementation of an orthogonal layout algorithm based on the Topology-Shape-Metrics (TSM) approach. The algorithm is inspired by A Generic Framework for the Topology-Shape-Metrics Based Layout.

Installation

pip install -r requirements.txt

Quick start

import networkx as nx
from matplotlib import pyplot as plt
from tsmpy import TSM

# Load a planar graph from the test data
G = nx.Graph(nx.read_gml("test/inputs/case2.gml"))

# Optional: provide an initial embedding
pos = {node: eval(node) for node in G}

# Solve the minimum cost flow problem using linear programming
tsm = TSM(G, pos)
# tsm = TSM(G, pos, uselp=False)  # use networkx.min_cost_flow instead

# Display and save the layout
tsm.display()
plt.savefig("test/outputs/case2.lp.svg")
plt.close()

Examples

case1 case2
case1 case2
bend case grid case
bend grid

Running tests

# show help
python test.py -h

# run all tests
python test.py

# run all tests in TestGML
python test.py TestGML

Playground

Try editing the original case2 graph with yed.

Requirements for input graph

  • Planar
  • Connected
  • Maximum node degree is 4
  • No self-loops

Features

  • Linear programming based minimum-cost flow formulation to reduce the number of bends

TODO

  • Cleaner code
  • More comments
  • Fix overlay
  • Support node degree > 4
  • Support cut-edges

About

An orthogonal layout algorithm, using TSM approach

Topics

Resources

License

Stars

Watchers

Forks

Languages