1 Introduction

Membrane system is extremely parallel, so the computational complexity can be greatly reduced. Tissue P system, cell P system and neural P system are the three basic types of membrane system [1,2,3,4,5,6,7], the Spiking Neural P system is a sub-branch under the neural P system. SN P system has only one object, the object is the spikes, usually expressed by \(a \) [8]. In the SN P system, the exchange of information between neurons is achieved by transmitting spikes. So far, the SN P system has been applied in many ways. For example, a SNP can perform addition, subtraction, multiplication of natural numbers using binary. In recent years, the SN P system has also been combined with clustering, once again expanding its scope of application.

The Travelling Salesman Problem asks to find the minimum costly Hamiltonian cycles in a weighted undirected graph. Scholars put forward many algorithms according to the research to solve TSP. The most classic idea in the algorithm is point-by-point traversal, many algorithms are designed based on this idea. Some scholars also applied the membrane calculation to solve the TSP, and proposed the solutions based on the P system or the cP system, and so on [1, 9]. Other scholars have integrated the membrane structure and convenience algorithms to form integrated technologies such as ant colony algorithm and genetic algorithm [10,11,12].

However, Few scholars have studied the SN P system to solve the TSP. In this paper, we use the idea of point-by-point traversal and combine the characteristics of SN P system to propose a method to solve TSP with SN P system. The first part introduces the research background, the second part introduces the foundation, the third part elaborates the method steps, The fourth part expounds an example. The fifth part summarizes the whole paper and puts forward the prospect.

2 Foundation

Our work in this paper is based on the Spiking Neural P System to solve the Travelling Salesman Problem, so we firstly give knowledge of the SN P System, and then introduce related content of the TSP.

2.1 Spiking Neural P Systems

Membrane mainly investigate three kinds of membrane system, which are cell-like P system, tissue-like P system and spiking neural P system, and SN P is one of them. Then only one object in the SN P system is the spike, which is the difference from the other membrane systems [13,14,15,16]. There are four rules in the SN P system for the evolution of the system, firing rule, forgetting rule, neurons division rule, and neurons dissolution rule, respectively.

Firing rules are used to generate pulses and pass information. Pulses consume by forgetting rules. Splitting rules are used for the division of neurons. Dissolution rules are used to ablate pulses and neurons. In addition, the SN P system can convert the number of spikes into form of binary and apply firing and forgetting rules to perform addition and subtraction of natural numbers within neurons.

2.2 Travelling Salesman Problem

Whether in graph theory or in the field of computer science, the TSP is a long-standing, well-known NP-hard problem, the full name of which is Traveling Salesman Problem [17, 18]. The problem is generally reflected in the weighted graph. In essence, the TSP finds a Hamiltonian cycle that is the minimum cost in weighted digraphs. Hamiltonian cycle means starting from a vertex, passing through each vertex in the graph, and each vertex is traversed only once, finally returning to the path of the starting vertex. In a directed digraph, there will be multiple Hamiltonian cycles, so we need to find the Hamiltonian cycle with the minimum total cost (ie, the total weight). Each path has its own weight, the total weight of a path is the sum of the weights of all the subpaths that make up the path in a weighted graph. Since the discovery of the TSP, in many fields, various solutions have emerged. One of the most classic and most widely used methods is point-by-point iteration. This paper also adopted the idea of this algorithm, combined with the SN P system, re-proposed a new method of solving the TSP.

3 Description of Our SN P Systems TSP Algorithm

The algorithm uses a simple p principle, effectively a simple parallel deep exploration of digraph. So our general idea is to travel the node one by one, finally we can travel entire a weighted digraph and gain all Hamiltonian cycle. Then we could calculate total cost of every Hamiltonian cycle, total cost is expressed by total weight, and the minimum weight is selected from all Hamiltonian cycle.

The process of searching digraph is imagined as building a tree. We assume that initial neuron is regarded as the root vertex, the generating new neurons through spiking neurons division indicate children vertexes, branches are expressed by synapses between two neurons. Spiking neurons divide synchronously following expanding of the tree, finally leaves contain all information of total path, we should select the target path that has minimum cost. The weight of arc between two nodes is measured by an Euclidean distance in the digraph.

The algorithm that solves Travelling Salesman Problem with SN P systems mainly applies the firing rule and neuron division rule and neuron dissolution rule of Spiking Neural P Systems. Firstly, we provide a formal definition and four rules for the SN P system that we will use it in next context:

Rule:

r\(_1\): \(\left[ E \right] _i\rightarrow \left[ \quad \right] _j||\left[ \quad \right] _k\); \(\mathrm{i}\in \left\{ 1,2,3,\cdots ,n \right\} \), \(\mathrm{j}\in \left\{ 1,2,3,\cdots ,n \right\} \), \(\mathrm{k}\in \big \{ 1,2,\) \(3,\cdots ,n \big \}\).

r\(_2\): a \(\rightarrow \) a.

r\(_3\): E\a \(\rightarrow \) a;d,\(\left\{ a\right\} \) \( \notin \) E.

r\(_4\): \( \left[ E \right] \) \(_i\) \(\rightarrow \) \(\delta \), i\(\in \) \(\left\{ 1,2,3,\cdots ,n \right\} \).

Define:

\(\left( 1\right) \) O=\(\left\{ a \right\} \).

\(\left( 2\right) \) \(\sigma \) \(_{Input}\)=(1,R\(_{Input}\) ),R\(_{Input}\)={ r\(_1\),r\(_2\),r\(_4\),i=1 }.

(3) \(\sigma \) \(_2\)=(2,R\(_2\)),R\(_2\)={ r\(_1\),r\(_3\),r\(_4\),i=2 }.

(4) \(\sigma \) \(_n\)=(n,R\(_n\)),R\(_n\)={ r\(_1\),r\(_3\),r\(_4\),i=n }.

(5) syn={(Input,2)}\(\cup \) {(Input,4)}\(\cup \) \(\cdots \) \(\cup \) {(i,j)}, i\(\in \) \(\left\{ 1,2,3,\cdots ,n \right\} \), j\(\in \) \(\big \{ 1,2,\) \(3,\cdots ,n \big \}\).

The process of this algorithm requires to be described as follows:

Input: we arbitrarily select a node as the initial vertex \(\sigma _{Input}\) of travelling directed graph, the number of spike indicates the sequence number of node. Every neuron has corresponding spiking that the number of spike is our pre-concerted. We make this neuron act as \(\sigma _{Input}\), and it includes the weight between two vertexes. Input initial information of travelling by applying the rule r\(_2\) in \(\sigma _{Input}\).

Path construction: travel all vertexes in digraph, all legal paths in parallel could be generated as follows:

  1. (1)

    Make the initial vertex to be starting vertex of path P.

  2. (2)

    If there are edges from the remainder of vertexes to starting vertex, initial neuron divides to new neurons through applying division rule r\(_1\). If there are two vertexes that they connect with starting vertex, and then the initial neuron is divided to two new neurons. The label of new neuron is the sequence number of corresponding vertex, and the spike in new neuron is generated by spikes of initial neuron, the distribution of spikes in new neurons corresponds to rule r\(_1\). The weight of arc between father neuron and child neuron has be recursively preserved in new neuron after division.

  3. (3)

    Travel remainder of vertexes by applying rule r\(_3\) after finishing the traversal of first level vertex, if a vertex connects with several vertexes, the vertex could apply rule r\(_1\) to divide as mentioned above in step (1). But there is a difference, after dividing, if the newly generated vertex has explored, it applies rule r\(_4\) to dissolute itself.

  4. (4)

    Repeat step (3) until all vertexes are visited.

Path detection: Many paths does not made up Hamiltonian cycle, so we should delete illegal paths. If there is an edge between last vertex and the initial vertex, add the information to the finally neuron. Otherwise we apply rule r\(_4\), all spikes of neuron are consumed, the neuron is dissolved, then delete the path.

Path selection: the message of order and cost of path is extracted from final neurons, then recode the cost of all paths in the form of binary. We enter the binary in a pre-specified singly-linked neurons string, the number of spikes represents the cost of path. Applying rule r\(_3\) triggers the neuron, causing the binary to enter the next neuron and subtraction, leaving a smaller binary into the subsequent neurons for comparison. Until the last neuron is fired, the minimum cost is generated. Meanwhile, the last neuron will export the minimum cost to the system. This process is end and TSP is solved.

Fig. 1.
figure 1

The graph G

4 Worked Example

We use the spiking neurons to represent the vertexes in the graph. The TSP is described by bidirectional graph G as shown in Fig. 1. We will use the method described in Sect. 3 to find the least cost Hamiltonian path through neurons division in the SN P system. First, assume that the vertex randomly selected from the digraph is V\(_1\), so V\(_1\) is marked as \(\sigma \) \(_{Input}\). We make the sequence number of the vertex as the subscript of the neuron, and use the initial number of spikes contained in the neuron to represent the sequence number of the vertex. Then we can get the form of the SN P system as follows:

figure a

In the initial SN P system, \(\sigma \) \(_{Input}\) is fired first. From the digraph G, V\(_1\) is connected with V\(_2\), V\(_4\) and V\(_5\), so applying rule r\(_1\), \(\sigma _{Input}\) could divide oneself and split into three neurons accordingly as shown in Fig. 2. The labels of new neurons are 2, 4 and 5, respectively. The newly generated neurons contain the serial number of the father neuron and the weight between the two neurons and their own rules.

We consider the traversal of the initial vertex as the first layer of traversal, the three neurons split by the initial vertex are the second layer of traversal, and we take the split of V\(_2\) as an example to introduce the following traversal. Before dividing, we again emphasize the rules contained in V\(_2\). It can be seen from the label, V\(_2\) contains 2 initial spikes, the firing rule is a\(^2\) \(\rightarrow \) a, By the syn of definition can clearly know V\(_2\) is connected with V\(_1\), V\(_3\) and V\(_5\), so the division rules is [a\(^2\)]\(_2\) \(\rightarrow \)[a]\(_1\) || [a\(^3\)]\(_3\) || [a\(^5\)]\(_5\), while V\(_2\) contains the dissolution rule a\(^2\) \(\rightarrow \) \(\delta \). After firing V\(_2\), V\(_2\) applies the division rule and still splits into three neurons labeled 1, 3, and 5. Due to V\(_1\) has traversed, V\(_2\) already contains information of V\(_1\), so the newly generated V\(_1\) could dissolve itself by applying the dissolution rules, leaving only neurons V\(_3\) and V\(_5\) produced by the V\(_2\) division as shown in Fig. 3. The remaining vertexes are traversed as the V\(_2\) traversal method until all vertexes traversed.

Fig. 2.
figure 2

The division of initial neuron

Fig. 3.
figure 3

The finally state of \(\sigma \) \(_2\) division

After all vertexes have traversed, we need to determine whether the last vertex is connected to the initial vertex V\(_1\), and if so, input the relevant information into the neuron. Otherwise, the corresponding neurons will dissolve using the dissolution rules to dissolve oneself. Eventually only the Hamiltonian cycle remains in the system, and the paths that do not constitute an Hamiltonian cycle have been deleted as the neurons dissolve. We employ the tree to represent the traversal of graph G, as shown in Fig. 4:

Fig. 4.
figure 4

The tree diagram of travelling

The traversal tree in the Fig. 4 above shows only the complete process of two Hamiltonian cycles, and the rest of the paths are similar. Finally we get seven Hamiltonian cycles. By calculating the weight of the seven paths, respectively, 21, 18, 19, 21, 19, 18, 21. The weights are extracted from the neurons. The weights are represented by the number of vertexes. We enter the binary in a pre-specified singly-linked neurons string, and different numbers of neurons contain different path weights. Finally, we can get the minimum weight that is 18, and there are two corresponding path, which is {V\(_1\) \(\rightarrow \) V\(_2\) \(\rightarrow \) V\(_3\) \(\rightarrow \) V\(_5\) \(\rightarrow \) V\(_4\) \(\rightarrow \) V\(_1\)} and {V\(_1\) \(\rightarrow \) V\(_4\) \(\rightarrow \) V\(_5\) \(\rightarrow \) V\(_3\) \(\rightarrow \) V\(_2\) \(\rightarrow \) V\(_1\)}.

5 Conclusion

Membrane computing is a new computational model inspired by biological cells, the SN P system is a branch of the membrane system. This paper proposes to solve the travelling salesman problem by applying SN P system algorithm in O(n) time, proposes a new idea for solving TSP and broaden the application range of SN P system. This idea uses the maximum parallelism of the SN P system, uses fewer neurons, and applies fewer rules throughout the process, making TSP easier to solve. We use the dividing property of neurons in the SN P system to find all the Hamiltonian circuits, and apply the dissolving property of neurons to delete the paths that do not form cycles. Finally, we compare the weights with the binary form of the spikes and finally find the minimum cost Hamilton cycle. In order to further improve the efficiency of the algorithm, the process of simplifying weight comparison is the direction of future efforts.