The Hamiltonian path (loop) and the Hamiltonian diagram (Hamilton diagram) pass through each node of the graph G once, and only one path (loop) is the Hamiltonian path (loop). The graph in which the Hamiltonian loop exists is the Hamiltonian graph.
Hamiltonian pathwayLet G = "V, E" be a picture (undirected or directed). The path through each vertex once and only once in G is called the Hamiltonian path.
2. Hamiltonian loopThe loop in G that passes through each vertex once and only once is called the Hamiltonian loop.
3. Hamiltonian diagramIf there is a Hamiltonian loop in G, it is called a Hamiltonian graph.
4. Definitions:(1) The map in which the Hamiltonian path (loop) exists must be a connected graph;
(2) The Hamiltonian path is the primary path and the Hamilton circuit is the primary circuit;
(3) If there is a Hamiltonian loop in G, then it must have a Hamiltonian path, and vice versa.
(4) Only the Hamiltonian path, the diagram without the Hamiltonian circuit does not intersect the Hamiltonian;
Second, the judgment theoremNote: There are currently no simple and necessary conditions for finding Hamiltonian graphs.
(1) Let the undirected graph G = "V, E" is a Hamiltonian graph, and V1 is any true subset of V. (Note: n-order xx graph refers to n vertices, don't be confused!)
p(G-V1)"=|V1|
Here, p(G-V1) is the number of connected branches of the obtained graph after deleting V1 in G, and |V1| is the number of vertices included in the V1 set. [Requirements for the existence of Hamiltonian graphs]
Corollary: The map with cut points must not be Hamiltonian
Let v be the cut point in the graph, then p(Gv)》=2, and the above theorem knows that G is not a Hamiltonian graph.
(2) Let G be an n(n)=3) order undirected simple graph, if for each pair of non-adjacent vertices u, v in G
d(u)+d(v)》=n-1
Then there is a Hamiltonian path in G. If
d(u)+d(v)》=n
Then there is a Hamiltonian loop in G, that is, G is a Hamiltonian graph. [Sufficient conditions for the existence of Hamiltonian, not necessary conditions]
Where d(u) and d(v) represent the degrees of the vertices u, v, respectively.
Inference: Let G be an n-n=n) order undirected simple graph. If the minimum degree of G is nn/2, then G is a Hamiltonian graph.
It is inferred from the inference that for the complete graph Kn, when n "=3, it is a Hamiltonian graph, and the complete bipartite graph Kr,s is a Hamiltonian graph when r==s"=2.
(3) In the n(n)=2) order directed graph D=“V, Eâ€, if the direction of all directed edges is omitted, and the resulting undirected graph contains the generated subgraph Kn, then there is a Hami in D. Road.
Corollary: n(n)=3) The order-directed complete graph is a Hamiltonian graph.
1. The commonly used method to judge is the Hamiltonian:(1) If it is possible to find a Hamiltonian loop in graph G by observation, then G is of course a Hamiltonian graph.
(2) If an undirected graph G satisfies the condition in (2) above, and a directed graph D satisfies the condition of the inference of (3) above, G and D are both Hamiltonian graphs.
2. Destroy the necessary conditions for the existence of the Hamiltonian graph and determine that it is not a Hamiltonian graph:Let the nth order graph G be a Hamiltonian graph, then G should satisfy the following conditions:
(1) G must be a connected graph;
(2) The number m of edges in G must be greater than or equal to the number of vertices n;
(3) If there is a 2 degree vertex v in G, ie d(v)=2, then the two edges ei, ej associated with v must be on any Hamiltonian loop in G;
(4) If there is an edge appearing in each Hamiltonian loop in G, it cannot form a primary loop (circle) whose number of sides is less than n;
Destruction of one of the above conditions is not a Hamiltonian.
The application of the Hamiltonian loop is randomly generated and solved by a Hamiltonian loop:// Graph.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include"Graph.h"
#include《iostream》
#include"fstream"
#include《stack》
#include"queue"
#include"limits"
Using namespace std;
Template "class T, class E"
Int sb(int start,Graph "T,E" &myGraph,ostream & fout)//simple backtracking algorithm to solve the minimum Hamiltonian loop problem of graph v is the start and end of the loop
{
E minDistance=std::numeric_limitsE::max();
Stack "int" myStack;
myStack.push(start);
Int numVertices=myGraph.NumberOfVertices();
Bool *visited=new bool[numVertices];
Memset(visited,false,numVertices);
Int v;
Int w=-1;
While(!myStack.empty()) //The stack is not empty
{
v=myStack.top();
Visited[v]=true;
If(w==-1)
{
w=myGraph.getFirstNeighbor(v);
}
Else
{
w=myGraph.getNextNeighbor(v,w);
}
For(;w!=-1&&visited[w]==true;w=myGraph.getNextNeighbor(v,w))
{
}
If(w==-1) //The next possible vertex is not found
{
myStack.pop(); //backtracking
w=v;
Visited[v]=false;
}
Else // find the next possible vertex
{
myStack.push(w); // put in the stack
If(myStack.size()==numVertices)// walk through all the vertices
{
If(myGraph.getWeight(start,w)==std::numeric_limits"E"::max()) //Determine whether the last vertex has returned to the starting edge
{
myStack.pop();
Visited[w]=false;
}
Else // successfully found the loop
{
/ / Output loop and record the length of the loop
Stack "int" temp;
While(!myStack.empty())
{
Int n=myStack.top();
Temp.push(n);
myStack.pop();
}
Fout ""Hamilton Circuit:";
E distance=0;
Int n=temp.top();
myStack.push(n);
Temp.pop();
Int last=n;
Fout "n" "--";
While(!temp.empty())
{
n=temp.top();
myStack.push(n);
Temp.pop();
Distance+=myGraph.getWeight(last,n);
Last=n;
Fout "n" "--";
}
Fout "start" "--" "endl;
Distance+=myGraph.getWeight(last,start);
Fout ""The total length is:" "distance" "endl;
/ / record the shortest length
If(minDistance"distance)
{
minDistance=distance;
}
//
myStack.pop();
Visited[w]=false;
}
}
Else
{
w=-1;
}
}
}
Fout ""The length of the shortest Hamiltonian loop is:" "minDistance" "endl;
Return 1;
}
//Branch bound method solves the shortest Hamiltonian loop problem
Template "class E"
Struct NODE
{
Int dep; / / indicates that the node is in the first few layers of the search tree
Int *vertices; //The vertices contained in the node force
E length; //the length of the path that has passed since the root to the current node
NODE(int depth)
{
Dep=depth;
Vertices=new int[dep];
};
Void cpy(int *&des)
{
For(int i=0;i"dep;i++)
{
Des[i]=vertices[i];
}
}
Bool find(int v)
{
For(int i=0;i"dep;i++)
{
If(vertices[i]==v)
Return true;
}
Return false;
}
};
Template "class T, class E"
Int bb(int start,Graph "T,E" & myGraph,ostream & fout)
{
Stack "NODE "E"" myStack; / / queue
E minDistance=std::numeric_limitsE::max();
Int s=myGraph.getFirstNeighbor(start);
For(s=myGraph.getNextNeighbor(start,s);s!=-1;s=myGraph.getNextNeighbor(start,s))
{
NODE "E" n (2);
N.vertices[0]=start;n.vertices[1]=s;
N.length=myGraph.getWeight(start,s);
myStack.push(n);
}
While(!myStack.empty()) //The queue is not empty
{
NODE "E" n=myStack.top();
myStack.pop();
Int v=n.vertices[n.dep-1];
If(n.dep+1==myGraph.NumberOfVertices())//The last layer is judged whether it is a Hamiltonian loop
{
Int w;
For( w=myGraph.getFirstNeighbor(v);w!=-1;w=myGraph.getNextNeighbor(v,w))
{
If( n.find(w)==false)
Break;
}
If(w!=-1)
{
If(myGraph.getWeight(w,start)"std::numeric_limits"E"::max())
{
/ / Form a loop
Fout ""The Hamiltonian circuit is:";
For(int i=0;i"n.dep;i++)
{
Fout "n.vertices[i]" """;
}
Fout "w" """ "start" "endl;
E tempDistance=n.length+myGraph.getWeight(v,w)+myGraph.getWeight(w,start);
Fout ""Total length:" "tempDistance" "endl;
If(minDistance"tempDistance)
{
minDistance=tempDistance;
}
}
}
}
For(int w=myGraph.getFirstNeighbor(v);w!=-1;w=myGraph.getNextNeighbor(v,w))
{
If(n.find(w)==false)
{
NODE "E" ne (n.dep+1);
Ne.length=n.length+myGraph.getWeight(v,w);
If(ne.length"minDistance)
{
N.cpy(ne.vertices);
Ne.vertices[ne.dep-1]=w;
myStack.push(ne);
}
}
}
}
Fout ""The shortest length is" "minDistance" "endl;
Return minDistance;
}
Int _tmain(int argc, _TCHAR* argv[])
{
Graph "char, int" myGraph (10);
//ifstream fin("input.txt");
//myGraph.Init(fin);
myGraph.RandInit();//random initialization map
Ofstream fout("outputsb.txt");
//sb(0, myGraph, fout);
Ofstream fout1("outputbb.txt");
Bb(0, myGraph, fout1);
System("pause");
Return 0;
}
Board To Board Connector,3.00Mm Board To Board Connector,1.00Mm Board To Board Connector,0.80Mm Board To Board Connector
Shenzhen CGE Electronic Co.,Ltd , https://www.cgeconnector.com