CodeDelphiPythonPython GUIRAD Studio

Ultimate Way To Represent Networks In Your Delphi GUI App Using NetworkX Python Library

Do you want to represent networks of communication, data organization, computational devices, the flow of computation, etc in your GUI App? This post will get to understand how to use NetworkX Python Library using Python4Delphi in Delphi/C++ application with some basic NetworkX manipulations. NetworkX is a Python package for the creation, manipulation, and study of the structure, dynamics, and functions of complex networks.

The NetworkX package provides classes for graph objects, generators to create standard graphs, IO routines for reading in existing datasets, algorithms to analyze the resulting networks, and some basic drawing tools.

Python for Delphi (P4D) is a set of free components that wrap up the Python DLL into Delphi. They let you easily execute Python scripts, create new Python modules and new Python types. You can use Python4Delphi a number of different ways such as:

  • Create a Windows GUI around your existing Python app.
  • Add Python scripting to your Delphi Windows apps.
  • Add parallel processing to your Python apps through Delphi threads.
  • Enhance your speed-sensitive Python apps with functions from Delphi for more speed.

Prerequisites.

  • If not python and Python4Delphi is not installed on your machine, Check this how to run a simple python script in Delphi application using Python4Delphi sample app
  • Open windows open command prompt, and type pip install -U networkx to install NetworkX. For more info for Installing Python Modules check here
  • Alternatively, you can type pip install networkx[all] to include other optional packages.
  • First, run the Demo1 project for executing Python script in Python for Delphi. Then load the Texblob sample script in the Memo1 field and press the Execute Script button to see the result. On Clicking Execute Button the script strings are executed using the below code. Go to GitHub to download the Demo1 source.

Key NetworkX Concepts

A Graph consists of a finite set of vertices(or nodes) and a set of edges that connect a pair of nodes. Methods of the graph object are limited to basic manipulation and reporting. The following basic graph types are provided as Python classes:

  • Graph – This class implements an undirected graph. It ignores multiple edges between two nodes. It does allow self-loop edges between a node and itself.
  • DiGraph – Directed graphs, that is, graphs with directed edges. Provides operations common to directed graphs, (a subclass of Graph).
  • MultiGraph – A flexible graph class that allows multiple undirected edges between pairs of nodes. The additional flexibility leads to some degradation in performance, though usually not significant.
  • MultiDiGraph – A directed version of a MultiGraph.

NetworkX Python Library sample script details:

  • Creation of undirected graph and Digraph.
  • Adding Nodes one at a time, from any iterable container such as a list, adding nodes with node attributes. Also, add a node from another graph.
  • Adding Edges one at a time, from any iterable container such as a list.
  • Examining the elements of the group by listing a number of nodes and edges in a graph, node list, edge list, finding the neighbor node, degree of the graph, etc.
  • How to remove nodes, edges, and clear both from the graph.
  • Draw a cubical graph using matplotlib library.
networkx-3720766
NetworkX Demo

Note: Samples used for demonstration were picked from here with only the difference of printing the outputs. You can check the APIs and some more samples from the same place.

You have read the quick overview of NetworkX library, download this library from here, and easily generate graphs, manipulate graph operations, use numerical graph algorithms and draw the graphs in your applications. Check out Python4Delphi and easily build Python GUIs for Windows using Delphi.

close
Related posts
DelphiPythonPython GUIWindows

Learn To Build A Python GUI For Computer Vision Tasks With Powerful OpenCV Library In A Delphi Windows App

DelphiPythonPython GUIWindows

Learn To Work With HTTP Requests Using Python Requests Library In A Delphi Windows App

DelphiLearn PythonPythonPython GUIRAD Studio

Easily Integrate A Flexible Python REST Client To RAD Server In Python Windows GUI App Built In Delphi

DelphiIDELearn PythonPythonPython GUIRAD StudioWindows

Tutorial: Python For Delphi VCL vs Pyforms GUI

Leave a Reply

Your email address will not be published. Required fields are marked *

en_USEnglish