lcz

994 Reputation

11 Badges

6 years, 128 days
changsha, China

MaplePrimes Activity


These are questions asked by lcz

A Hamiltonian walk on a connected graph is a closed walk of minimal length which visits every vertex of a graph (and may visit vertices and edges multiple times). (See https://mathworld.wolfram.com/HamiltonianWalk.html)

 

Please note that there is a distinction between a Hamiltonian walk and a Hamiltonian cycle. Any graph can have a Hamiltonian walk, but not necessarily a Hamiltonian cycle.  The Hamiltonian number h(n) of a connected G is the length of a Hamiltonian walk. 

For example, let's consider the graph FriendshipGraph(2).

g:=GraphTheory[SpecialGraphs]:-FriendshipGraph(2);
DrawGraph(g)

Then its Hamiltonian number is 6.  A Hamiltonian walk is as shown in the following picture.

 

 

 

PS: After being reminded by others, I learned that a method in the following post seems to work, but I don't understand why it works for now. 

it's possible to formulate this as a Travelling Salesman Problem by augmenting the sparse graph into a complete graph by adding edges. These new edges represent shortest paths between any two vertices in the original graph and have weight equal to the path length.

 

It seems that the correctness of this transformation requires rigorous proof.

 

I followed the code on the website https://de.maplesoft.com/support/help/maple/view.aspx?path=updates/Maple18/GraphTheory to convert a graph to LaTeX code. However, after compiling with pdflatex, I found that some edges of the graph are jagged.

restart:    
with(GraphTheory):
with(SpecialGraphs):
S:=SoccerBallGraph():
Latex(S,FileTools:-JoinPath([currentdir(), "soccer.tex"]),300,300,true)

soccer.pdf

I suspect it's because of the converted LaTeX code.

PS: The PDF conversion issue from last time still remains unsolved in Maple 2023; see

https://www.mapleprimes.com/questions/236142-How-To-Remove-The-Mosaic-Of-Vertices.

An interval graph is an undirected graph formed from a set of intervals on the real line, with a vertex for each interval and an edge between vertices whose intervals intersect. Recognizing interval graphs  is in linear time. 

Seven intervals on the real line and the corresponding seven-vertex interval graph.

 

 

IsIntervalGraph(G) (was introduced in Maple 2022) tests whether the graph G could be expressed as an interval graph for some collection of intervals. If a graph is an interval graph, then the intervals corresponding to its vertices should be given. However,  IsIntervalGraphdoes not provide such an option, which makes it impossible for me to verify the correctness of the results or see more information.

with(GraphTheory):
G:=Graph({{1,2},{1,3},{1,4}, {4,2},{4,3}});
IsIntervalGraph(G)

true

Therefore, an option like the "certificate" option in SageMath needs to be provided.

g = Graph({1: [2, 3, 4], 4: [2, 3]})
g.show()
g.is_interval()
g.is_interval(certificate=True)

(True, {1: (0, 5), 2: (4, 6), 3: (1, 3), 4: (2, 7)})

 

 

I have looked at the source code of IsIntervalGraphand it seems to be checking whether the complement graph is comparability. I am not sure if this transformation can still find the corresponding intervals.

print(IsIntervalGraph)
proc(G::GRAPHLN)::truefalse;
    local G2;
    G2 := GraphTheory:-GraphComplement(G);
    return GraphTheory:-IsComparabilityGraph(G2);
end proc

print(IsComparabilityGraph)
proc (G::GRAPHLN, { transitiveorientation::truefalse := false, 

   usecached::truefalseFAIL := FAIL }, ` $`)::truefalse; local 

   iscomparability, L, A, result, V; A := op(4, G); result := 

   FindTransitiveOrientation(A, transitiveorientation); if 

   result = NULL then false elif transitiveorientation then V 

   := op(3, G); true, GraphTheory:-Graph(V, result) else true 

   end if end proc

 

By the way, can the  "FindTransitiveOrientation "  in the function IsComparabilityGraph be used by the user?

I compute some properties of some graphs and try to store their edge sets and their corresponding properties. I stored them using matrices, but now I want to export them to a file (csv format).

with(GraphTheory):
graphs := [seq(RandomGraphs:-RandomGraph(8, 9), 1 .. 10)]:
M0:=Edges~(graphs):
M1:=Girth~(graphs):
M2:=Diameter~(graphs):
B := Matrix(1..3,[M0,M1,M2]);
Export("E:/B.csv", B):

 

he exported file's data is messy, and it is difficult for me to observe the corresponding properties of the graphs.  I hope they can be sorted into three columns as shown below.

PS: I know that if the data has only one column, it can be done as discussed earlier

Export("E:/M.csv", M):

To make the data appear clearer, it is best to keep suitable spacing between columns.

multi_dimensional_data.mw

We can read all the graphs in a file at once, or we can use an iterative approach. But can I specify a certain number of lines to read? 

with(GraphTheory):
g:=ImportGraph("E:/5cc3free.txt", graph6, output=list)

The contents of 5cc3free.txt are as follows (all 5-vertex C_3 free connected graphs).  There are 6 lines.

D?{
D@s
DBw
DFw
DDW
DqK

The reason for wanting this kind of operation is that sometimes there are tens of thousands of graphs stored in a single file, and I want to read them in batches. For example, I want to extract the graph data from lines 1-2, 3-4, and 5-6 in batches. How can I accomplish this?

In the previous example, a small dataset was used for demonstration purposes. In the following example, which involves all 8-vertex connected graphs (see the attachment graph8c.txt), I want to extract the graphs from lines 200-300. 

I found that readline always starts reading from the first line of a file, so the efficiency may not be very high.

1 2 3 4 5 6 7 Last Page 3 of 25