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.

Related posts
CodeIDELearn PythonPythonPython GUITkinter

How To Make More Than 20 ChatGPT Prompts Work With Python GUI Builders And OpenCV Library?

CodeIDEProjectsPythonWindows

Unlock the Power of Python for Deep Learning with Radial Basis Function Networks (RBFNs)

CodeIDELearn PythonPythonPython GUITkinter

How To Make More Than 20 ChatGPT Prompts Work With Python GUI Builders And NumPy Library?

CodeIDEProjectsPythonWindows

Unlock the Power of Python for Deep Learning with Generative Adversarial Networks (GANs) - The Engine behind DALL-E

Leave a Reply

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