Turing Machine Virtual Simulation System Based on Unity

Through the Unity-based Turing machine virtual simulation system, 3D modeling and interactive simulation of complex algorithms of Turing machines are realized, which solves the problem of insufficient Turing machine simulation in the prior art, and provides portable Turing machine algorithm simulation and complexity display.

CN114818300BActive Publication Date: 2025-07-29NORTHEASTERN UNIV CHINA
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210402665.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-04-18
Publication Date
2025-07-29
Estimated Expiration
2042-04-18

AI Technical Summary

Technical Problem

In the prior art, the virtual simulation systems of Turing machines are mostly abstract simulations or simple algorithms, and lack 3D modeling and interactive simulation of complex algorithms, so they cannot deeply understand the computing process of Turing machines.

Method used

Based on Unity technology, a Turing machine virtual simulation system is built, including Turing machine modeling, read and write action and state transfer design, UI design, state transfer equation and WebGL optimization, to realize the virtual simulation of Turing machine, and to support the simulation of complex algorithms such as unary addition, binary search, split-pack greed and 0-1 backpack dynamic programming.

Benefits of technology

It provides 3D animation simulation of Turing machine algorithm, displays the algorithm process and complexity, supports a variety of classic algorithms and recursive function calls, adapts to different platforms, and realizes portable web-side access.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114818300B_ABST
    Figure CN114818300B_ABST
Patent Text Reader

Abstract

The present invention provides a Turing machine virtual simulation system based on Unity, which relates to the field of computer virtual simulation technology. This system models the Turing machine, designs the actions of the Turing machine for reading, writing, and state transition, uses the Turing machine to read and write characters and perform state transition to simulate five algorithms, and finally presents the process of the Turing machine simulating the algorithms in the form of 3D animations, and records the number of times the Turing machine reads and writes and the number of tape squares consumed to calculate the algorithm complexity. When using the Turing machine to simulate algorithms, different state transition equations are designed for different algorithms. At the same time, considering that the device performance and operating environment of different platforms are different, in order to improve the portability of use, the system is published in the form of WebGL based on WebGL technology. This system can not only utilize the execution process of simulating multiple classic algorithms, but also simulate the recursive function call process, realizing the function of Turing machine algorithm simulation.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of computer virtual simulation, and in particular to a Unity-based Turing machine virtual simulation system. Background Art

[0002] For every computer science student, the term "Turing machine" frequently appears in their study materials and by their instructors. It's practically a required knowledge point, playing a crucial role in students' understanding of computer principles, algorithmic processes, computational theory, and other course content. The Turing machine (also known as the Turing computer) is a highly abstract and theoretical model of electronic computing, first proposed by British mathematician Alan Mathison Turing in 1936. It laid the theoretical foundation for the advent of computers. The Turing machine is not a specific machine, but rather a conceptual model that allows the creation of a very simple yet extremely powerful computing device capable of calculating all conceivable computable functions.

[0003] The Turing machine, inspired by the typewriter, is an abstract machine conceived by Turing. It abstracts the process of mathematical calculations performed by humans using pen and paper, replacing humans with a virtual machine that performs mathematical calculations on an infinitely long tape. The tape is divided into small, equal-sized squares, each capable of storing a symbol. A machine head moves across the tape, maintaining a set of internal states and a fixed program. At each moment, the machine head reads information about a square from the tape, then uses its internal state to search a program table, outputs information to the tape squares according to the program, transforms its internal state, and then moves.

[0004] Turing's proposal of the Turing machine model wasn't intended to provide a computer design. It holds several important implications. First, it fully demonstrates a relatively general theory of random computational models, confirms the feasibility of a method for directly implementing a computer's internal functions, and proposes a fundamental computational architecture based on the computer's internal structure. The Turing machine computational model fully incorporates the concept of combining reading and writing with algorithms and programming languages in structural design, significantly breaking through previous design concepts for computing machines. The Turing machine model theory is a core principle in computing. Since the ultimate computational power of a computer is that of a universal Turing machine, many problems can be considered using the simple model of a Turing machine.

[0005] The algorithm that uses a Turing machine to simulate different strategies can not only help us understand the Turing machine more deeply, but also enable us to better study algorithms from the perspective of computational models. Compared with understanding algorithms from the perspective of programs, simulating algorithms from the perspective of computational models can help us understand the deeper ideas of algorithms and the underlying operations of computers when executing programs, rather than being limited to program statements. The Turing machine virtual simulation system can more vividly display the computing process of the Turing machine, helping students learn and understand the working principle of the Turing machine, and assisting teachers in better explaining the Turing machine during the teaching process. Compared with the universal Turing machine, the Turing machine that specifically simulates different strategy algorithms can better help students understand algorithms more deeply from the perspective of computational models in algorithm teaching.

[0006] For building a 3D model of the Turing machine, the Unity technology and development platform is a good choice. The Unity3D version is a large-scale online game software development tool independently designed, developed, and manufactured by the Chinese-Danish unity company. It mainly uses the particle physics-based engine of japhysx, supports multiple JavaScript, C#, and Boo scripts. It integrates excellent software functions such as being able to run on all application platforms, having an advanced ultra-high-delay laser lighting processing system, top-level color optics and texture processing technology, introducing numerous script automatic debugging features, and having a wide coverage of application fields. Therefore, it is not only widely used in the online game software industry but also widely used in urban construction, medicine, micro-imaging, and other professional fields.

[0007] Using Unity3D technology, we can obtain some information about the object, such as position information. In addition, we can also obtain relevant information about the parent object or child object. And by using the MoveTowards function, we can achieve the movement operations of the read / write head and the tape during the simulation process by specifying the starting position, ending position, and step size. At the same time, we can use the GetComponent method to achieve communication between scripts attached to various objects, including obtaining variables within scripts on other objects and calling functions of other scripts. In UI design, we can use the SceneManagement package and the UI package to achieve the function of scene switching when users select the algorithm to be simulated through the UI.

[0008] Software developed using Unity can be published in the form of WebGL, ultimately enabling it to be used without the need for downloading or installing plugins. WebGL (Web Graphics Library) is a technology for rendering interactive 3D graphics in web browsers. The most prominent feature of this technology is that it can be used directly without downloading and installing any third-party plugins. In 2011, the WebGL technology was standardized by the Khronos Group, a leader in the 3D graphics industry, and is now enabled by default in all mainstream browsers, but not all browsers are the same. In the past, WebGL was only provided by two browser vendors, Mozilla and Google, while other vendors were reluctant to offer the latest technology at that time. Subsequently, the situation has changed significantly, and finally Microsoft joined the 3D Web club. Nowadays, almost all Internet traffic passes through client software that supports WebGL, making this technology a powerful and extensive foundation for delivering interactive 3D content to over 400 million users. WebGL combines OpenGL ES 2.0 with JavaScript, enabling users to render 3D models on web pages through the Canvas element in HTML5. The WebGL form has the advantage of cross-platform, so it is very suitable for some lightweight applications to be published in the WebGL form without causing system lags due to performance reasons.

[0009] In the direction of Turing machine simulation, currently most have only achieved an abstract simulation of the Turing machine, only using the display of state transitions and the squares on the tape, and there are few Turing machines that use 3D modeling to achieve virtual simulation. From the perspective of implementation, both at home and abroad, what have been implemented are mostly universal Turing machines and Turing machines that simulate relatively simple algorithms, such as the Turing machine that simulates unary addition. In domestic undergraduate teaching, the Turing machine is mostly presented in the form of pictures, and in students' project designs, it is only required to simulate a universal Turing machine that only displays information such as the state tape in text.

[0010] In the research of some domestic scholars, there are Turing machines based on sendmail simulation and the design of universal Turing machines. These have only simulated universal Turing machines or simple algorithms such as unary addition and simple decision machines, and the results are either presented in text form or only designed without giving specific simulation results. Taking the Turing machine in the Stanford Encyclopedia of Philosophy as an example abroad, there are Turing machines that simulate abstract simple algorithms, and there are also those that make a real existing machine to simulate the Turing machine. These have only simulated relatively simple algorithms such as unary addition, prime number finding, and divisibility. Whether it is for scientific research simulation, such as David Gajser's simple simulation when verifying whether a single-tape Turing machine can run in linear time, or to provide a model for simulating the Turing machine, virtual simulation with 3D models and the simulation of some complex algorithms are relatively rare. Summary of the Invention

[0011] The technical problem to be solved by the present invention is to provide a Turing machine virtual simulation system based on Unity to realize the virtual simulation of the Turing machine in view of the deficiencies of the above-mentioned prior art.

[0012] To solve the above technical problem, the technical solution adopted by the present invention is: a Turing machine virtual simulation system based on Unity, which is characterized in that it includes a Turing machine modeling module, a design module for the reading / writing actions and state transitions of the Turing machine, a UI design module, a state transition equation design module, an algorithm complexity calculation module, and an optimization module based on WebGL; the Turing machine modeling module models the Turing machine based on Unity according to the task requirements to construct a Turing machine model; the design module for the reading / writing actions and state transitions of the Turing machine is used to implement the design of the reading / writing actions and state transitions of the Turing machine; the UI design module is used to design the UI interface of the Turing machine; the state transition equation design module is used to design the state transition equation for the Turing machine to achieve the task requirements, and then complete the task requirements through the Turing machine; the algorithm complexity calculation module is used to calculate the algorithm complexity for achieving the task requirements; the optimization module based on WebGL publishes the Turing machine virtual simulation system in the form of WebGL and deploys it on the server using node.js after publication, and finally realizes that the Turing machine virtual simulation system can be accessed through the web page.

[0013] The specific method for the Turing machine modeling module to model the Turing machine based on Unity according to the task requirements is as follows:

[0014] The set Turing machine task requirements are to implement five algorithms: unary addition, binary search Turing machine algorithm, binary search recursive algorithm, divisible knapsack greedy algorithm, and 0-1 knapsack dynamic programming algorithm.

[0015] Determine the read / write head of the Turing machine and the Turing machine framework model.

[0016] Use 3dsMax to model the tape, read / write head, and finite state automaton of the Turing machine; after modeling, export the FBX model and then import it into Unity to assign materials, and finally complete the modeling work through design.

[0017] In Unity, bind the tape, read / write head, and finite state automaton parts modeled by 3dsMax together to form an overall Turing machine model; and add a text component to display the automaton state and tape content.

[0018] To facilitate the user to intuitively observe the working process of the Turing machine, the Turing machine is designed as a three-read / write head and three-tape model, including an input read / write head, a working read / write head, an output read / write head, an input tape, a working tape, an output tape, an automaton, and a state transition display screen.

[0019] The design module for the read / write operation and state transition of the Turing machine designs control scripts for the read / write head, scripts for updating the tape content, scripts for controlling the tape movement, state transition scripts, state display scripts, simulation function call scripts, and an array for accessing per unit time to implement the read / write operation and state transition of the Turing machine;

[0020] The control script for the read / write head is used to control the up and down movement of the read / write head to simulate the read / write operation; First, create an empty object in the Unity scene as the target position for the movement of the read / write head; Use the MoveTowards() function to specify the starting position, target position, and step size of the read / write head to change the position of the read / write head, enabling it to move back and forth between the target position and the starting position; When the read / write head moves to the target position, it sends a signal to the state transition script to start the state transition, and when the read / write head moves back to the initial position, it sends a signal to the control script for tape movement to start moving the tape;

[0021] The script for updating the tape content is used to manage the data on the tape and provides two interfaces, setBST() and getBST(); setBST() modifies the element at the target position on the tape by specifying the write position and the data to be written, and getBST() retrieves the tape data at the specified position by specifying the position; Each time it receives the signal for updating the tape content from the state transition script, it updates the tape data displayed in the current scene;

[0022] The control script for tape movement is used to control the movement of the tape; It calls the interface getI() provided by the state transition script to obtain the target position to which the current tape should move by specifying the tape name, starts moving the tape after receiving the signal for moving the tape, and sends a signal to the read / write head to drop down to simulate the next read / write operation after moving to the target position;

[0023] The state transition script is used to control the state transition of the Turing machine and switch the input, working, and output tapes as well as the read / write head; Each state transition process is as follows: First, modify the content on the current tape, then update the current tape position, then send a signal to allow the tape to update the content and raise the read / write head back to the initial position, and finally move the tape, select the tape for the next state, and update the state of the Turing machine; Inside this script, a variable nowTape is defined to determine whether the current tape and the read / write head are the input, working, or output tape and read / write head; At the same time, variables inputI, workI, and outputI are defined to mark the current read / write positions of the input, working, and output tapes;

[0024] The state display script uses the GetComponent method inherited from the GameObject class to call the interface getState() provided by the state transition script to obtain the state of the Turing machine and display it on the state display screen;

[0025] The simulation function call script moves the tape data out of the view for updating to achieve the simulation function call process; creates an empty object in the scene as the target position for the tape movement; uses the MoveTowards() function to achieve the reciprocating movement of the read / write head between the target position and the initial position; for recursive calls, only updates the data on the tape to the parameters input for the next level of recursion, and directly updates the corresponding sorted calls to the sorted results;

[0026] The unit time access array is implemented in three cases: under definite state transition, under indefinite state transition, and when switching tapes; for the implementation of the unit time access array under definite state transition, it only needs to directly move to the position located according to the array subscript when performing the tape left / right shift operation; for the two cases of indefinite state transition and tape switching, it is necessary to modify the positioning variables inputI, workI, and outputI before entering the next state, call the interface provided by the control tape movement script to control the tape movement, and then enter the next state.

[0027] The UI design module is specifically used to design the algorithm selection interface, the algorithm simulation interface, and implement the algorithm description and interaction functions;

[0028] The algorithm selection interface designs five buttons for selecting the algorithms to be simulated, and realizes the function of scene jumping by clicking the buttons by calling the SceneManager package in Unity;

[0029] The algorithm simulation interface is used to display the data of each tape, the time complexity, the space complexity, and the button to return to the algorithm selection page during algorithm simulation, displays the positions where the three tapes are being read and written through a small window, and provides buttons for starting / pausing, accelerating, and decelerating the algorithm simulation. The specific method is as follows:

[0030] Call the interface provided by the update tape content script to read the data on the tape and display it on the corresponding Text component in the interface;

[0031] The small window display uses three cameras respectively corresponding to the central positions of the three tapes, obtains the camera views using the render texture in the camera properties, and renders the camera views to the pictures in the interface to realize the display of the data of the positions where the tapes are being read and written using the small window;

[0032] In the binary search recursive algorithm, it is also necessary to implement the display of the recursive stack in the interface, that is, the data pushed into the recursive stack each time a call is made; when the execution state is call, low, high, and mid are pushed onto the stack in sequence, and when returning, they are popped from the stack following the principle of last in first out; in the small-scale 0-1 knapsack dynamic programming algorithm, the data in the two-dimensional array is also dynamically displayed in the interface through a two-dimensional table.

[0033] The specific method for implementing the algorithm description and interaction function is as follows: After selecting the algorithm to be simulated on the algorithm selection interface, the relevant description of the selected algorithm is given. When the user finishes reading and clicks the continue button to watch the algorithm simulation process; and on the algorithm description page, an input function is provided using the InputField component in the UI, allowing the user to input the initial input tape data on this page.

[0034] The specific method for the algorithm complexity calculation module to calculate the complexity of the five Turing machine simulation algorithms is as follows:

[0035] In the script for controlling the movement of the read / write head, a new variable num1 is added and initialized to 0. When the read / write head drops and moves to the target position, num1 is incremented by 1, and an interface for returning the value of num1 is provided to give the time complexity.

[0036] In the script for updating the tape content, a vis array is added to mark whether each position on the working tape is used; and an interface for passing out the number of working tape squares used is added to display the algorithm complexity in real time in the UI.

[0037] The state transition equation design module completes the task requirements of the Turing machine by designing an unary addition automaton, a binary search Turing machine algorithm automaton, a binary search recursive algorithm automaton, a divisible knapsack greedy algorithm automaton, and a 0-1 knapsack dynamic programming algorithm automaton.

[0038] The unary addition automaton simulates unary addition through four states: 0, 1, 10, and 11.

[0039] The binary search Turing machine algorithm automaton constructs 13 states to implement the simulation of the binary search Turing machine algorithm; the 13 states are: initLow, which reads the initial subscript low of the array A of the search interval to be searched from the input tape; writeLow, which writes low to the working tape; initHigh, which reads the ending subscript high of the array of the search interval from the input tape; writeHigh, which writes high to the working tape; compareLow, which compares high and low, and halts if low > high; calMid, which writes the middle value mid of low and high to the working tape; readMid, which reads the array element A[mid] at the mid position on the input tape; compareMid, which compares the array element A[mid] at the mid position with the target search element x. If A[mid] = x, the search is successful. If A[mid] > x, high is updated. If A[mid] < x, low is updated; updateLow, which updates the low on the working tape to mid + 1; compareHigh, which compares the updated low and high, and halts if low > high; updateHigh, which updates the high on the working tape to mid - 1; success, indicating successful search; stop, which halts.

[0040] Based on the states of the binary search Turing machine algorithm automaton, the binary search recursive algorithm automaton reduces the four states of initLow, initHigh, writeLow, and writeHigh, adds two states of call and return used for recursive calls, and constructs 11 states of the binary search recursive algorithm automaton; directly reads the parameters low and high from the input tape, and the calculated mid is still recorded on the working tape; and merges the state of updating low and high into the recursive call, and directly passes the parameters to the next recursive call according to the comparison result of A[mid] and x.

[0041] The split knapsack greedy algorithm automaton simulates the split knapsack greedy algorithm through 12 states, which are: readCapacity to read the knapsack capacity of the input tape; writeCapacity to write the knapsack capacity to the working tape; readWeight to read the weight of the object on the input tape; readValue to read the value of the object on the input tape; writeAverage to write the ratio of the object value to the weight to the working tape; writeNum to write the object number to the working tape; sort to sort each object by the value-weight ratio; readNum to read the object number on the working tape; readC to read the weight on the input tape corresponding to the object number; subBag to subtract the weight of the object already loaded from the knapsack capacity and update it on the working tape; writeAns to write the solution vector to the output tape; success to end the algorithm simulation;

[0042] The 0-1 knapsack dynamic programming algorithm simulates the 0-1 knapsack dynamic programming algorithm through 14 states; the 14 states are: readCapacity to read the capacity of the knapsack on the input tape; readNum to read the number of objects on the input tape; readWeight to read the weight of the object on the input tape; readValue to read the value of the object on the input tape; writeM(i,j) to write the optimal solution of the object loading information to the position (i,j) on the working tape; readM(i+1,j) to read the object loading information at the position (i+1,j) on the working tape; readW(i) to read the weight of the i-th object on the input tape; calM(i+1,j-weight) to read the optimal solution of the object information at the position (i+1,j-weight) on the working tape; ansM(i,j) to read the optimal solution of loading the current object on the working tape; cmpAnsM(i,j) to read and compare M(i+1,j) and M(i,j) on the working tape; writeAns(i-1) to write the solution vector to the output tape; writeAns(num) to write the solution vector to the num position on the output tape; cmp to compare the optimal solution of loading the current object with the optimal solution of not loading the current object; success to end the algorithm simulation;

[0043] Among them, i and j represent the position coordinates (i,j) in the two-dimensional array M storing object data, weight represents the object weight, num represents the object number, i ranges from 0 to the number of objects + 1, and j ranges from 0 to the number of objects - 1.

[0044] The specific method for the unary addition automaton to implement unary addition simulation is as follows:

[0045] Step 101: Construct four states of the unary addition automaton: 0, 1, 10, 11;

[0046] When the state of the unary addition automaton is 0, the working read / write head has not read the first addend yet; when the state is 0, if the working read / write head reads 0, the working tape moves to the right and the state remains unchanged until the read head reads 1, then the state of the unary addition automaton transfers to 1;

[0047] When the state of the unary addition automaton is 1, it means that the working read / write head of the Turing machine is reading the first number. When the working read / write head reads 0, it means that the first number has been read. At this time, rewrite the 0 read on the working tape as 1, and the unary addition automaton transfers to state 10;

[0048] When the state of the unary addition automaton is 10, it means that the working read / write head of the Turing machine is reading the second number. When it reads 0, it means that the second number has also been read. At this time, move the working tape to the left and transfer the state of the unary addition automaton to 11;

[0049] When the state of the unary addition automaton is 11, rewrite the last 1 on the working tape as 0, and the Turing machine halts automatically;

[0050] Step 106: For easier observation, the last state 11 of the unary addition automaton is rewritten; when the working read / write head reads 1, change the 1 on the working tape to 0, move the working tape to the right, and when it reads 0, the Turing machine halts.

[0051] The specific method for the binary search Turing machine algorithm automaton to implement the simulation of the binary search Turing machine algorithm is as follows:

[0052] Step 201: Construct 13 states of the binary search Turing machine algorithm automaton, which are respectively used for parameter initialization, calculating and comparing mid, updating parameters, and returning results;

[0053] Step 202: Read low and high on the input tape through the states initLow, writeLow, initHigh, and writeHigh and write them to the working tape;

[0054] Step 203: Perform iterative binary search through 7 states: compareLow, compareHigh, calMid, readMid, compareMid, updateLow, and updateHigh. First, compare the sizes of low and high through the states compareLow and compareHigh to determine whether to continue the iteration. If low > high, stop the iteration and transfer to the state stop; otherwise, transfer to the state calMid. After calculating the middle value mid through the state calMid and locating the position A[mid], the state of the binary search Turing machine algorithm automaton transfers to the readMid state to read A[mid], and then transfers to the state compareMid. Compare the read A[mid] with the input target search element x. Finally, update the parameters high or low according to the comparison result for the next round of iteration or terminate the iteration.

[0055] If A[mid] = x, terminate the iteration, and the state of the binary search Turing machine algorithm automaton transfers to success; if A[mid] > x, transfer to the state updateHigh to update the parameter high and continue the iteration; if A[mid] < x, transfer to the state updateLow to update the parameter low and continue the iteration.

[0056] Step 204: Simulate the return operation of the Turing machine through the states success and stop. When A[mid] = x, the state of the binary search Turing machine algorithm automaton transfers to the state success, and write the current mid to the output tape as the return value, indicating that the target search element is found and the search is successful. When low > high, transfer to the state stop, and write -1 to the output tape, indicating that the search fails and there is no target search element.

[0057] The specific method for the divisible knapsack greedy algorithm automaton to implement the simulation of the divisible knapsack greedy algorithm is as follows:

[0058] Step 301: Construct 12 states of the divisible knapsack greedy algorithm automaton.

[0059] Step 302: Initialize the knapsack capacity through the readCapacity and writeCapacity states, that is, read the knapsack capacity from the input tape and write it to the working tape.

[0060] Step 303: Use four states, readWeight, readValue, writeAverage, and writeNum, to form the first loop to continuously read the weight and value of the objects, calculate the value-to-weight ratio of the objects, and write the object number and value-to-weight ratio to the working tape.

[0061] Step 304: When reading the object weight #, it indicates that all objects have been read. At this time, the state of the split knapsack greedy algorithm automaton transfers to the state sort, and the objects are sorted according to the value-weight ratio;

[0062] Step 305: The sorted objects are loaded into the knapsack in order through the four states of readNum, readC, subBag, and writeAns; when the knapsack capacity is less than the total weight of all objects, a part of the object with the largest value-weight ratio at this time is loaded into the knapsack, and then it jumps to the state success, and the algorithm simulation ends;

[0063] Step 306: Process the two non-deterministic state transitions of readWeight and writeAns; for the split knapsack greedy algorithm automaton, there are also two non-deterministic state transitions, namely readWeight and writeAns; for the readWeight state, when the read / write head reads a number and #, it transfers to the readValue state of continuing to read the value and the sort state of sorting the objects respectively; for the state transition of the writeAns state, it mainly depends on whether the knapsack is full when executing the previous state subBag. If it is not full, write 1 at the corresponding position in the array of the object on the output tape and continue to iterate the process of loading the knapsack. If it is full, write the loading percentage at the corresponding position and transfer to the state success, and the algorithm simulation ends;

[0064] Step 307: Return a solution vector X = {X1, X2, X3,... Xn}, where Xn is the nth object loaded into the knapsack, and n is the number of objects loaded into the knapsack;

[0065] The specific method for the 0-1 knapsack dynamic programming algorithm automaton to implement the 0-1 knapsack dynamic programming algorithm simulation is as follows:

[0066] Step 401: Construct 14 states of the 0-1 knapsack dynamic programming algorithm automaton;

[0067] Step 402: Take the readCapacity state as the start state of the 0-1 knapsack dynamic programming algorithm automaton. At this time, read the knapsack capacity (capacity) and move the input tape 1 grid to the right, and then transfer to the state readNum;

[0068] Step 403: When the 0-1 knapsack dynamic programming algorithm automaton is in the state readNum, the input read / write head will read the object number num and move the input tape to the position of num * 2 to the right, and transfer to the state readWeight;

[0069] Step 404: When the 0-1 knapsack dynamic programming algorithm automaton is in the readWeight state, the input read / write head reads weight, the input paper tape moves 1 grid to the right, and it transfers to the readValue state; when in the readValue state, the input read / write head reads value, and the input paper tape moves 3 grids to the left;

[0070] Step 405: The state of the 0-1 knapsack dynamic programming algorithm automaton transfers to the state writeM(i,j) or the state readM(i+1,j); when i = num, it transfers to writeM(i,j), and at other times it transfers to readM(i+1,j); when i = num, when writing the value data of the object read and written by the working read / write head into the two-dimensional array, only need to pay attention to whether the current object can be loaded. If it can be loaded, fill in the value of the current object in the two-dimensional array, and if it cannot be loaded, fill in 0;

[0071] Step 406: When the 0-1 knapsack dynamic programming algorithm automaton is in the writeM(i,j) state, fill in the optimal solution with the maximum value of the object currently loaded into the knapsack at the corresponding position; there are three transfer routes for the state writeM(i,j);

[0072] When i = num, the working read / write head transfers to the position of M(num,j) on the working paper tape, the working paper tape moves 1 grid to the right and makes j+1 until j = capacity, and the state of the 0-1 knapsack dynamic programming algorithm automaton transfers to the readWeight state to read the information of the next object;

[0073] When j = capacity, the working paper tape moves left to the position of (i-1)*(capacity+1), and at the same time the state of the 0-1 knapsack dynamic programming algorithm automaton transfers to the readWeight state, and switches to the input paper tape and the input read / write head;

[0074] When i is not equal to num, the state of the 0-1 knapsack dynamic programming algorithm automaton transfers to the state read(i+1,j) until j = capacity; and when i = 1 and j = capacity, it transfers to the state readW(i) to start the recursive solution vector operation and switches to the output paper tape and the output read / write head;

[0075] Step 407: When the 0-1 knapsack dynamic programming algorithm automaton is in the state readM(i+1,j), when the knapsack can hold the current object, it should consider whether the benefit of loading the current object is greater or the benefit of not loading is greater. Therefore, when j >= weight, it transfers to the state calM(i+1,j-weight), reads the optimal solution with the maximum value of loading the current object, adds it to the value of the current object, and compares it with the optimal solution with the maximum value when not loading the current object to obtain the optimal solution and fill it in the position of the two-dimensional array subscript (i+1,j-weight).

[0076] Step 408: When the state of the 0-1 knapsack dynamic programming algorithm automaton transfers from the state readM(i+1,j) to the state calM(i+1,j-weight), the working paper tape moves right to the position i*(capacity+1)+mj-weight. When the current object cannot be loaded into the knapsack, that is, j < weight, the state transfers to write(i,j), which directly writes M(i+1,j), and the working paper tape moves right 1 grid.

[0077] Step 409: For the state calM(i+1,j-weight), the working paper tape moves right to the position i*(capacity+1), transfers to the state cmp. Through the state cmp for comparison, the optimal solution with the maximum value of the currently loaded object is obtained, the working paper tape moves left to the corresponding position of (i,j), and transfers to the state writeM(i,j).

[0078] Step 410: When the 0-1 knapsack dynamic programming algorithm automaton is in the readW(i) state, recursively calculate the serial number of the object loaded into the knapsack and write it into the solution vector.

[0079] In the readW(i) state, the weight of the i-th object is read, the working paper tape moves right 2 grids, transfers to the state ansM(i,j), and at the same time switches to the working paper tape and the working read-write head.

[0080] In the state ansM(i,j), the optimal solution with the maximum value of the currently loaded object is read, the working paper tape moves right capacity+1 grids, and transfers to the state cmpAnsM(i,j).

[0081] In the state cmpAnsM(i,j), M(i+1,j) and M(i,j) are read and compared. If they are the same, it means that the object is not loaded into the knapsack, and it transfers to the state readW(i). If they are different, it means that the object is loaded into the knapsack, the working paper tape moves left weight grids, transfers to the state writeAns(i-1), and switches to the output read-write head and the output paper tape.

[0082] Write whether the object is loaded (1 or 0) into the solution vector through the state writeAns(i - 1), transfer to the state readW(i), and at the same time switch to the input tape and the input read / write head; when i = num, directly transfer from the state ansM(i, j) to the writeAns(num) state, and determine whether the object is loaded into the backpack according to whether M(i, j) is 0 and fill in the solution vector, and finally transfer to the state success, and the algorithm simulation is completed;

[0083] Step 411: Return a solution vector of Y = {Y1, Y2, Y3,..., Ym}, where Ym is the solution output on the output tape and m is the number of solutions.

[0084] The beneficial effects of adopting the above technical solutions are as follows: The Turing machine virtual simulation system based on Unity provided by the present invention realizes the simulation of the algorithm by using the Turing machine to read and write characters and state transfer, and finally presents the process of the Turing machine simulation algorithm in the form of a 3D animation and shows the time and space consumed by the algorithm. To implement the Turing machine simulation algorithm, model the Turing machine, design the actions of the Turing machine for reading, writing and state transfer, and record the number of times the Turing machine reads and writes and the number of tape squares consumed to calculate the algorithm complexity. When using the Turing machine to simulate the algorithm, different state transfer equations are designed for different algorithms. At the same time, considering that the device performance and operating environment of different platforms are different, in order to improve the portability of use, the system is published in the form of WebGL based on the WebGL technology.

[0085] The Turing machine virtual simulation system of the present invention realizes the function of Turing machine algorithm simulation. The algorithm simulation can not only utilize the execution processes of simulating various classical algorithms, but also simulate the recursive function call process. In order to be as portable as possible and adapt to different devices on various platforms, the system is published in the form of WebGL. Under the condition of ensuring the integrity of the system function, the system is finally deployed to the web page to provide a portable, reliable, installation-free and fast Turing machine virtual simulation system. Description of the Drawings

[0086] Figure 1 It is a structural block diagram of the Turing machine virtual simulation system based on Unity provided by the embodiment of the present invention;

[0087] Figure 2 It is a flowchart of using the Turing machine virtual simulation system to perform unary addition simulation calculation provided by the embodiment of the present invention;

[0088] Figure 3 It is a flowchart of using the Turing machine virtual simulation system to perform binary search Turing machine algorithm simulation calculation provided by the embodiment of the present invention;

[0089] Figure 4Flowchart of simulating and calculating the binary search recursive algorithm using the Turing machine virtual simulation system provided by the embodiments of the present invention;

[0090] Figure 5 Flowchart of simulating and calculating the divisible knapsack greedy algorithm using the Turing machine virtual simulation system provided by the embodiments of the present invention;

[0091] Figure 6 Flowchart of simulating and calculating the 0-1 knapsack dynamic programming algorithm using the Turing machine virtual simulation system provided by the embodiments of the present invention;

[0092] Figure 7 Effect diagram of unary addition simulation provided by the embodiments of the present invention;

[0093] Figure 8 Effect diagram of simulating the binary search Turing machine algorithm provided by the embodiments of the present invention;

[0094] Figure 9 Effect diagram of simulating the binary search recursive algorithm provided by the embodiments of the present invention;

[0095] Figure 10 Effect diagram of simulating the divisible knapsack greedy algorithm provided by the embodiments of the present invention;

[0096] Figure 11 Effect diagram of the 0-1 knapsack dynamic programming algorithm provided by the embodiments of the present invention. Specific embodiments

[0097] The following combines the accompanying drawings and embodiments to further describe in detail the specific embodiments of the present invention. The following embodiments are used to illustrate the present invention, but are not used to limit the scope of the present invention.

[0098] In this embodiment, a Turing machine virtual simulation system based on Unity, as Figure 1As shown in the figure, it includes a Turing machine modeling module, a design module for the reading / writing actions and state transitions of the Turing machine, a UI design module, a state transition equation design module, an algorithm complexity calculation module, and an optimization module based on WebGL; the Turing machine modeling module models the Turing machine based on Unity according to the task requirements to construct a Turing machine model; the design module for the reading / writing actions and state transitions of the Turing machine is used to implement the design of the reading / writing actions and state transitions of the Turing machine; the UI design module is used to design the UI interface of the Turing machine; the state transition equation design module is used to design the state transition equation for the Turing machine to achieve the task requirements, and then complete the task requirements through the Turing machine; the algorithm complexity calculation module is used to calculate the algorithm complexity for achieving the task requirements; the optimization module based on WebGL publishes the Turing machine virtual simulation system in the form of WebGL and deploys it on the server using node.js after publication, and finally enables the Turing machine virtual simulation system to be accessed through the web page end.

[0099] The Turing machine modeling module models the Turing machine based on Unity. The specific method is as follows:

[0100] Set the task requirements of the Turing machine and model the Turing machine according to the task requirements; the set task requirements of the Turing machine are to implement five algorithms: the unary addition, binary search Turing machine algorithm, binary search recursive algorithm, divisible knapsack greedy algorithm, and 0-1 knapsack dynamic programming algorithm.

[0101] Determine the read / write head of the Turing machine and the Turing machine framework model.

[0102] Use 3dsMax to model the tape, read / write head, and finite state automaton of the Turing machine; after modeling, export the FBX model and then import it into Unity to assign materials, and finally complete the modeling work through design.

[0103] In Unity, bind the tape, read / write head, and finite state automaton parts modeled by 3dsMax together to form an overall Turing machine model; and add a text component to display the automaton state and tape content.

[0104] At the same time, in order to facilitate users to intuitively observe the working process of the Turing machine, the Turing machine is designed as a three-read / write head and three-tape model, including an input read / write head, a working read / write head, an output read / write head, an input tape, a working tape, an output tape, an automaton, and a state transition display screen.

[0105] The design module for the reading / writing actions and state transitions of the Turing machine is used to implement the design of the reading / writing actions and state transitions of the Turing machine. Specifically, it includes:

[0106] Design a script to control the read / write head; this script is used to control the up and down movement of the read / write head to simulate the read / write operation. First, create an empty object in the Unity scene as the target position for the read / write head to move. Use the MoveTowards() function to specify the starting position, target position, and step size of the read / write head, so as to change the position of the read / write head and make it move back and forth between the target position and the starting position. When the read / write head moves to the target position, it will send a signal to the state transition script to start the state transition. When the read / write head moves back to the initial position, it will send a signal to the script that controls the movement of the paper tape to start moving the paper tape.

[0107] Design a script to update the content of the paper tape; this script is used to manage the data on the paper tape and provides two interfaces, setBST() and getBST(), to the outside. setBST() modifies the element at the target position on the paper tape by specifying the write position and the write data, and getBST() obtains the data on the paper tape at the specified position by specifying the position. Each time it receives the signal to update the content of the paper tape from the state transition script, it updates the data of the paper tape displayed in the current scene.

[0108] Design a script to control the movement of the paper tape; this script is used to control the movement of the paper tape. Call the interface getI() provided by the state transition script to obtain the target position to which the current paper tape should move by specifying the name of the paper tape. After receiving the signal to move the paper tape, it starts to move the paper tape. After moving to the target position, it sends a signal to the read / write head to make it drop to simulate the next read / write operation.

[0109] Design a state transition script; this script is used to control the state transition and switch between the input, working, and output paper tapes and the read / write head. Each state transition process is as follows: First, modify the content on the current paper tape (read data or write data), then update the current position of the paper tape (i.e., the i obtained by getI(), which is used to determine the next read / write square position). After that, send a signal to allow the paper tape to update its content and make the read / write head rise back to the initial position. Finally, move the paper tape, select the paper tape to be used for the next state (i.e., select the input, working, or output paper tape to be used next) and update the state of the Turing machine. Inside this script, a variable nowTape is defined to determine whether the current paper tape and the read / write head are the input, working, or output paper tape and the read / write head. At the same time, variables inputI, workI, and outputI are defined to mark the current read / write positions of the input, working, and output paper tapes.

[0110] Design a state display script; use the GetComponent method inherited from the GameObject class to call the interface getState() provided by the state transition script to obtain the state of the Turing machine at all times without any input and display it on the state display screen.

[0111] Design a simulation function call script; adopt the method of moving the tape data out of the view for updating to simulate the function call process; create an empty object in the scene as the target position for the tape to move; use the MoveTowards() function to achieve the reciprocating movement of the read / write head between the target position and the initial position; for recursive calls, only update the data on the tape to the parameters input for the next layer of recursion, and directly update the corresponding sorted calls to the sorted results;

[0112] Design the unit time access array; the requirements for the unit time access array are divided into three cases: implementation under a determined state transition, implementation under an undetermined state transition, and implementation under tape switching; for the implementation of the unit time access array under a determined state transition, it is only necessary to directly move to the position located according to the array subscript when performing the left / right shift operations of the tape; for the two cases of undetermined state transition and tape switching, it is necessary to modify the positioning variables inputI, workI, and outputI before entering the next state, call the interface provided by the control tape movement script to control the tape movement, and then enter the next state.

[0113] The UI design module is used to design the UI interface of the Turing machine, specifically including:

[0114] Design the algorithm selection interface; the algorithm selection interface designs five buttons for selecting the algorithms to be simulated, and realizes the function of scene jumping by clicking the buttons by calling the SceneManager package in Unity;

[0115] Design the algorithm simulation interface; used to display the data of each tape, time complexity, space complexity, and the button to return to the algorithm selection page during algorithm simulation, and display the positions where the three tapes are being read and written through a small window. The specific method is as follows:

[0116] 1. Call the interface provided by the update tape content script to read the data on the tape and display it on the corresponding Text component in the interface; the display of time complexity and space complexity also adopts a similar implementation method. The return button is implemented in the same way as the button in step 1.

[0117] 2. For the small window display, three cameras are set corresponding to the central positions of the three tapes respectively. Use the render texture in the camera properties to obtain the camera view, and render the camera view to the picture in the interface to realize the display of the data at the positions where the tapes are being read and written through the small window, solving the problem of unclear direct observation of the tape data.

[0118] Thirdly, in the binary search recursive algorithm, it is also necessary to implement the display of the recursive stack in the interface, that is, the data pushed into the recursive stack each time a call is made; when the execution state is call, low, high, and mid are pushed onto the stack in sequence, and when returning, they are popped off the stack following the principle of last in first out; in the small-scale 0-1 knapsack dynamic programming algorithm, a two-dimensional table is also dynamically displayed in the interface.

[0119] Implement the algorithm description and interaction functions; after selecting the algorithm simulation page, provide the relevant description of the selected algorithm. When the user finishes reading and clicks the continue button, watch the algorithm simulation process; and on the algorithm description page, an input function is provided using the InputField component in the UI, allowing the user to input the initial input tape data on this page by themselves, and certain guidance is given; on the algorithm simulation page, start / pause, accelerate, and decelerate buttons are provided.

[0120] The state transition equation design module is used to implement the state transition equations of five algorithms, including the following steps:

[0121] Step 1: Design a unary addition automaton;

[0122] Step 1.1: Construct four states of the unary addition automaton: 0, 1, 10, 11;

[0123] In step 1.2, when the state of the unary addition automaton is 0, the working read / write head has not read the first addend, that is, a in a + b; when the state is 0, if the working read / write head reads 0, the working tape moves to the right and the state remains unchanged until the working read / write head reads 1, and then the state of the unary addition automaton transfers to 1.

[0124] In step 1.3, when the state of the unary addition automaton is 1, it means that the working read / write head of the Turing machine is reading the first number. When the working read / write head reads 0, it means that the first number has been read. At this time, rewrite the 0 read on the working tape as 1, and the unary addition automaton transfers to state 10.

[0125] In step 1.4, when the state of the unary addition automaton is 10, it means that the working read / write head of the Turing machine is reading the second number. When reading 0, it means that the second number has also been read. At this time, move the tape to the left and transfer the state of the unary addition automaton to 11.

[0126] In step 1.5, when the state of the unary addition automaton is 11, rewrite the last 1 on the working tape as 0, and the Turing machine automatically halts;

[0127] In step 1.6, for easier observation, the last state 11 of the unary addition automaton is rewritten; when the working read / write head reads 1, change the 1 on the tape to 0, move the tape to the right, and when reading 0, the Turing machine halts.

[0128] Step 2: Design a binary search Turing machine algorithm automaton;

[0129] Step 2.1: Construct 13 states of the binary search Turing machine algorithm automaton, which are respectively used for parameter initialization, calculating and comparing mid, updating parameters, and returning results;

[0130] The 13 states of the binary search Turing machine algorithm automaton are respectively: initLow, reading the initial subscript low of the array A in the search interval from the input tape; writeLow, writing low to the working tape; initHigh, reading the ending subscript high of the array in the search interval from the input tape; writeHigh, writing high to the working tape; compareLow, comparing high and low, if low > high, then halt; calMid, writing the middle value mid of low and high to the working tape; readMid, reading the array element A[mid] at the mid position on the input tape; compareMid, comparing the array element A[mid] at the mid position with the target search element x, if A[mid] = x, then the search is successful, if A[mid] > x, then update high, if A[mid] < x, then update low; updateLow, updating the low on the working tape to mid + 1; compareHigh, comparing the updated low and high, if low > high, then halt; updateHigh, updating the high on the working tape to mid - 1; success, the search is successful; stop, halt;

[0131] Step 2.2: Read low and high on the input tape and write them to the working tape through the states initLow, writeLow, initHigh, and writeHigh; this stage is mainly used to write the initial parameters low and high on the input tape to the working tape for use in binary search;

[0132] Step 2.3: Perform iterative binary search through 7 states: compareLow, compareHigh, calMid, readMid, compareMid, updateLow, and updateHigh. First, compare the sizes of low and high through the states compareLow and compareHigh to determine whether to continue the iteration. If low > high, stop the iteration and transfer to the state stop; otherwise, transfer to the state calMid. After calculating the middle value mid and locating the position A[mid] through the state calMid, the state transition of the binary search Turing machine algorithm automaton transfers to the readMid state, reads A[mid], and the state transfers to the compareMid state. Compare the read A[mid] with the input target search element x. Finally, update the parameters high or low according to the comparison result for the next round of iteration or terminate the iteration.

[0133] If A[mid] = x, terminate the iteration, and the state of the binary search Turing machine algorithm automaton changes to success. If A[mid] > x, transfer the state to updateHigh to update the parameter high and continue the iteration. If A[mid] < x, transfer the state to updateLow to update the parameter low and continue the iteration.

[0134] In Step 2.3, there are non-deterministic state transitions in the binary search Turing machine algorithm automaton. For example, when comparing the size relationship between A[mid] and x, there are three transfer branches. When they are equal, the state of the binary search Turing machine algorithm automaton transfers to the success state, indicating a successful search. When A[mid] < x, the target search element is on the right side of mid, so the state transfers to updateLow to update the parameter low. When A[mid] > x, the target search element is on the left side of mid, so the state transfers to updateHigh to update high. When the binary search Turing machine algorithm automaton is in the compareHigh and compareLow states, if low > high, it transfers to the state stop; otherwise, it transfers to the state calMid.

[0135] Step 2.4: Simulate the return operation of the Turing machine through the success and stop states. When A[mid] = x, the state of the binary search Turing machine algorithm automaton transfers to the success state, and the current mid is written on the output tape as the return value, indicating that the target search element has been found and the search is successful. When low > high, it transfers to the state stop, and -1 is written on the output tape, indicating that the search fails and there is no target search element.

[0136] Step 3: Design a binary search recursive algorithm automaton.

[0137] Modify the binary search Turing machine algorithm automaton designed for step 2, reduce the four states of initLow, initHigh, writeLow, and writeHigh for initializing low, high, compareLow and updating parameters, add two states of call and return used in recursive calls, and construct 11 states of the binary search recursive algorithm automaton; directly read the parameters low and high from the input tape, and the calculated mid is still recorded on the working tape; and merge the state of updating low and high into the recursive call, and directly pass the parameters to the next recursive call according to the comparison result of A[mid] and x without the need to update high and low;

[0138] Step 4: Design a divisible knapsack greedy algorithm automaton;

[0139] Step 4.1: Construct 12 states of the divisible knapsack greedy algorithm automaton: readCapacity, writeCapacity, readWeight, readValue, writeAverage, writeNum, sort, readNum, readC, subBag, writeAns, success;

[0140] Among them, readCapacity reads the knapsack capacity from the input tape; writeCapacity writes the knapsack capacity to the working tape; readWeight reads the weight of the object from the input tape; readValue reads the value of the object from the input tape; writeAverage writes the ratio of the object value to the weight to the working tape; writeNum writes the object number to the working tape; sort sorts each object by the value-weight ratio; readNum reads the object number on the working tape; readC reads the weight on the input tape corresponding to the object number; subBag subtracts the weight of the object already loaded from the knapsack capacity and updates it on the working tape; writeAns writes the solution vector to the output tape; success ends the algorithm simulation;

[0141] Step 4.2: Initialize the knapsack capacity through the readCapacity and writeCapacity states, that is, read the knapsack capacity from the input tape and write it to the working tape;

[0142] Step 4.3: A first loop is formed by four states, namely readWeight, readValue, writeAverage, and writeNum, to continuously read the weight and value of the object, calculate the value-to-weight ratio of the object, and write the object number and the value-to-weight ratio into the working tape;

[0143] When the weight of the object read into # is read, it indicates that all objects have been read. At this time, the state of the divisible knapsack greedy algorithm automaton transfers to the state sort, and the objects are sorted according to the value-to-weight ratio;

[0144] Step 4.5: Four states, namely readNum, readC, subBag, and writeAns, are used to load the sorted objects into the knapsack in order; when the capacity of the knapsack is less than the total weight of all objects, a part of the object with the largest value-to-weight ratio at this time is loaded into the knapsack, and then it jumps to the state success, and the algorithm simulation ends;

[0145] Step 4.6: Process the two non-deterministic state transitions of readWeight and writeAns; for the divisible knapsack greedy algorithm automaton, there are also two non-deterministic state transitions, namely readWeight and writeAns; for the readWeight state, when the read / write head reads a number and #, it transfers to the readValue state that continues to read the value and the sort state that sorts each object; for the state transition of the writeAns state, it mainly depends on whether the knapsack is full when the previous state subBag that executes it is executed. If it is not full, write 1 at the corresponding position in the array where the object is located on the output tape and continue to iterate the process of loading the knapsack. If it is full, write the loading percentage at the corresponding position and transfer to the state success, and the algorithm simulation ends;

[0146] Step 4.7: Return a solution vector X = {X1, X2, X3,... Xn}, where Xn is the nth object loaded into the knapsack, and n is the number of objects loaded into the knapsack;

[0147] Step 5: Design a 0-1 knapsack dynamic programming algorithm automaton;

[0148] Step 5.1: Construct 14 states, namely readCapacity, readNum, readWeight, readValue, writeM(i, j), readM(i + 1, j), readW(i), calM(i + 1, j - weight), ansM(i, j), cmpAnsM(i, j), writeAns(i - 1), writeAns(num), cmp, success;

[0149] Among them, i and j represent the position coordinates (i, j) in the two-dimensional array M storing object data, weight represents the object weight, num represents the object serial number, i ranges from 0 to the number of objects + 1, and j ranges from 0 to the number of objects - 1;

[0150] readCapacity reads the capacity of the knapsack on the input tape; readNum reads the number of objects on the input tape; readWeight reads the weight of the objects on the input tape; readValue reads the value of the objects on the input tape; writeM(i, j) writes the optimal solution of the object loading information to the position (i, j) on the working tape; readM(i + 1, j) reads the object loading information at the position (i + 1, j) on the working tape; readW(i) reads the weight of the i-th object on the input tape; calM(i + 1, j - weight) reads the optimal solution of the object information at the position (i + 1, j - weight) on the working tape; ansM(i, j) reads the optimal solution of loading the current object on the working tape; cmpAnsM(i, j) reads M(i + 1, j) and M(i, j) on the working tape for comparison; writeAns(i - 1) writes the solution vector to the output tape; writeAns(num) writes the solution vector to the num position on the output tape; cmp compares the optimal solution of loading the current object with the optimal solution of not loading the current object; success indicates the end of the algorithm simulation;

[0151] Step 5.2: The readCapacity state serves as the starting state for the operation of the 0-1 knapsack dynamic programming algorithm automaton. At this time, the knapsack capacity (capacity) is read in, and the input tape is shifted one grid to the right, and then it transfers to the readNum state;

[0152] Step 5.3: When the 0-1 knapsack dynamic programming algorithm automaton is in the readNum state, the input read / write head reads the object serial number num and shifts the input tape to the position num * 2 (each object's information is stored in two grids, the first grid for weight and the second grid for value, and the 0th and 1st grids of the tape store capacity and num, so the weight of the last object should be stored at num * 2), and transfers to the readWeight state;

[0153] Step 5.4: When the 0-1 knapsack dynamic programming algorithm automaton is in the readWeight state, the input read / write head reads weight, and the input tape is shifted one grid to the right, and then it transfers to the readValue state; when in the readValue state, the input read / write head reads value, and the input tape is shifted three grids to the left (to the weight storage position of the previous object for future use);

[0154] Step 5.5: The automaton of the 0-1 knapsack dynamic programming algorithm transfers to state writeM(i, j) or state readM(i + 1, j); when i = num, it transfers to writeM(i, j), and at other times it transfers to readM(i + 1, j); here, from the recurrence formula, it can be seen that when i = num, when writing the value data of the object read by the working read / write head into the two-dimensional array, only need to focus on whether the current object can be loaded. If it can be loaded, fill in the value of the current object in the two-dimensional array, and if it cannot be loaded, fill in 0;

[0155] Step 5.6: When the automaton of the 0-1 knapsack dynamic programming algorithm is in state writeM(i, j), fill in the optimal solution with the maximum value of the object currently loaded into the knapsack at the corresponding position; there are three transfer routes for state writeM(i, j);

[0156] Step 5.6.1: When i = num, the working read / write head transfers to the position of M(num, j) on the working tape, the working tape moves 1 grid to the right and makes j + 1 until j = capacity, and the automaton of the 0-1 knapsack dynamic programming algorithm transfers to state readWeight to read the information of the next object;

[0157] Step 5.6.2: When j = capacity, the working tape moves left to (i - 1)*(capacity + 1) (when i is not equal to num, in any case, M(i + 1, j) should be read. Since the next filling position is (i - 1, 0) at this time, it should transfer to the position (i, 0), and through calculation, it is known that the tape position corresponding to this position is (i - 1)*(capacity + 1)), at the same time, the automaton of the 0-1 knapsack dynamic programming algorithm transfers to state readWeight, and switches to the input tape and the input read / write head;

[0158] Step 5.6.3: When i is not equal to num, the automaton of the 0-1 knapsack dynamic programming algorithm transfers to state read(i + 1, j) until j = capacity; when i = 1 and j = capacity, it transfers to state readW(i) to start the recurrence solution vector operation and switches to the output tape and the output read / write head;

[0159] Step 5.7: When the 0-1 knapsack dynamic programming algorithm automaton is in the state readM(i+1,j), when the knapsack can hold the current item, it should consider whether the benefit of loading the current item is greater or the benefit of not loading is greater; therefore, when j >= weight (weight of the current item), it transfers to the state calM(i+1,j-weight), reads the optimal solution with the maximum value of loading the current item, adds it to the value of the current item, and compares it with the optimal solution with the maximum value when not loading the current item to obtain the optimal solution and fill it in the position of the two-dimensional array subscript (i+1,j-weight).

[0160] Step 5.8: When the state of the 0-1 knapsack dynamic programming algorithm automaton transfers from the state readM(i+1,j) to the state calM(i+1,j-weight), the working paper tape moves right to the position i*(capacity+1)+mj-weight; when the current item cannot fit into the knapsack, that is, j < weight, the state transfers to write(i,j), that is, directly write M(i+1,j), and the working paper tape moves right 1 grid.

[0161] Step 5.9: For the state calM(i+1,j-weight), the working paper tape moves right to the position i*(capacity+1), transfers to the state cmp; through the state cmp for comparison, and then obtains the optimal solution with the maximum value of the value of the currently loaded item. The working paper tape moves left to the corresponding position of (i,j), and transfers to the state writeM(i,j).

[0162] Step 5.10: When the 0-1 knapsack dynamic programming algorithm automaton is in the readW(i) state, recursively calculate the item numbers loaded into the knapsack and write them into the solution vector.

[0163] Step 5.10.1: Through the readW(i) state, read the weight of the i-th item, the working paper tape moves right 2 grids, transfers to the state ansM(i,j), and at the same time switches to the working paper tape and the working read / write head.

[0164] Step 5.10.2: Through the state ansM(i,j), read the optimal solution with the maximum value of the value of the currently loaded item, the working paper tape moves right capacity+1 grids, and transfers to the state cmpAnsM(i,j).

[0165] Step 5.10.3: Through the state cmpAnsM(i,j), compare the read M(i+1,j) with M(i,j). If they are the same, it means that the item is not loaded into the knapsack, and it transfers to the state readW(i). If they are different, it means that the item is loaded into the knapsack, the working paper tape moves left weight grids, transfers to the state writeAns(i-1), and switches to the output read / write head and the output paper tape.

[0166] Step 5.10.4: Write 1 or 0 indicating whether an object is loaded into the solution vector through the state writeAns(i - 1), transfer to the state readW(i), and at the same time switch to the input paper tape and the input read / write head; when i = num, directly transfer from the state ansM(i, j) to the writeAns(num) state, determine whether the object is loaded into the backpack according to whether M(i, j) is 0 and fill in the solution vector, and finally transfer to the state success, and the algorithm simulation is completed;

[0167] Step 5.11: Return a solution vector Y = {Y1, Y2, Y3, …, Ym}, where Ym is the solution output on the output paper tape and m is the number of solutions;

[0168] The algorithm complexity calculation module is used to calculate the complexity of five algorithms. The specific method is as follows:

[0169] In the script for controlling the movement of the read / write head, add a new variable num1 and initialize it to 0. When the read / write head moves down to the target position, increment num1 by 1, and provide an interface to return the value of num1 to give the time complexity;

[0170] Add a vis array in the script for updating the content of the paper tape to mark whether each position on the working paper tape is used; and add an interface to transmit the number of squares on the working paper tape used, and display the algorithm complexity in real time in the UI.

[0171] The optimization module based on WebGL optimizes the Turing machine virtual simulation system based on WebGL, deploys the Turing machine simulation system to a remote server, enabling users to access the Turing machine virtual simulation system through the Internet. The specific method is as follows:

[0172] In Unity, set the field of view width of the Camera object to 0.5;

[0173] In the project settings of Unity, set the compression item to disabled; (After disabling this item, the generated file after publishing changes from a compressed package form to a file form. Although it will cause the loading speed to slow down, the file can be successfully read and run, solving the problem of getting stuck at 70% during loading.)

[0174] Modify the container and canvas in the style.css file in the script project file formed after publishing, and change the width and height parameters of the attributes of the container and canvas to 100% to adapt to various devices and browsers;

[0175] After running the tests locally without errors, compress the script project file and transfer it to the remote server. After transfer, decompress it and use node.js to deploy it, then the Turing machine virtual simulation system can be used through the Internet.

[0176] In this embodiment, the Turing machine simulation system is deployed to the remote server based on WebGL. Users can access the Turing machine virtual simulation system through the Internet to implement the simulation of unary addition, binary search Turing machine algorithm, binary search recursive algorithm, splittable knapsack greedy algorithm module, and 0-1 knapsack dynamic programming algorithm. As Figures 2-6 shown, specifically:

[0177] The first part, the specific implementation steps of the unary addition simulation are as follows:

[0178] Step 1: Enter the website address in the browser to enter the algorithm selection page;

[0179] Step 2: Click the "Unary Addition" button to select the unary addition algorithm.

[0180] Step 3: Click the "Continue" button on the algorithm description page.

[0181] Step 4: Click the "Start / Pause" button to start or pause the simulation demonstration process of the unary addition. The effect diagram of this process on the web page is as Figure 7 shown.

[0182] Step 5: Click the "Accelerate" or "Decelerate" button to accelerate or decelerate the playback of the demonstration process.

[0183] Step 6: After the demonstration process of the unary addition algorithm is over, the time and space complexity are displayed on this page.

[0184] Step 7: Click the "Return to Main Interface" button to return to the algorithm selection page.

[0185] The second part, the specific implementation steps of the binary search Turing machine algorithm simulation are as follows:

[0186] Step 1: Enter the website address in the browser to enter the algorithm selection page.

[0187] Step 2: Click the "Binary Search Turing Machine Algorithm" button to select the binary search Turing machine algorithm.

[0188] Step 3: On the algorithm description page, customize and enter the initial data or use the default example, and click the "Continue" button.

[0189] Step 4: Click the "Start / Pause" button to start or pause the simulation demonstration process of the binary search Turing machine algorithm. The effect diagram of this process on the web page is as Figure 8 shown.

[0190] Step 5: Click the "Accelerate" or "Decelerate" button to speed up or slow down the playback of the demonstration process.

[0191] Step 6: After the demonstration process of simulating the binary search Turing machine algorithm ends, the time and space complexity are displayed on this page.

[0192] Step 7: Click the "Return to Main Interface" button to return to the algorithm selection page.

[0193] Part Three, the specific implementation steps of simulating the binary search recursive algorithm are as follows:

[0194] Step 1: Enter the website in the browser to enter the algorithm selection page.

[0195] Step 2: Click the "Binary Search Recursive Algorithm" button to select the binary search recursive algorithm.

[0196] Step 3: On the algorithm description page, customize and enter the initial data or use the default example, and click the "Continue" button.

[0197] Step 4: Click the "Start / Pause" button to start or pause the simulation demonstration process of the binary search recursive algorithm. The effect diagram of this process on the web page is as Figure 9 shown.

[0198] Step 5: Click the "Accelerate" or "Decelerate" button to speed up or slow down the playback of the demonstration process.

[0199] Step 6: After the demonstration process of simulating the binary search recursive algorithm ends, the time and space complexity are displayed on this page.

[0200] Step 7: Click the "Return to Main Interface" button to return to the algorithm selection page.

[0201] Part Four, the specific implementation steps of simulating the fractional knapsack greedy algorithm are as follows:

[0202] Step 1: Enter the website in the browser to enter the algorithm selection page.

[0203] Step 2: Click the "Fractional Knapsack Greedy Algorithm" button to select the fractional knapsack greedy algorithm.

[0204] Step 3: On the algorithm description page, customize and enter the initial data or use the default example, and click the "Continue" button.

[0205] Step 4: Click the "Start / Pause" button to start or pause the simulation demonstration process of the fractional knapsack greedy algorithm. The effect diagram of this process on the web page is as Figure 10 shown.

[0206] Step 5: Click the "Accelerate" or "Decelerate" button to accelerate or decelerate the playback of the demonstration process.

[0207] Step 6: After the demonstration of the process of simulating the split knapsack greedy algorithm ends, display the time and space complexity on this page.

[0208] Step 7: Click the "Return to Main Interface" button to return to the algorithm selection page.

[0209] Part Five, the specific implementation steps of the simulation of the 0-1 knapsack dynamic programming algorithm are as follows:

[0210] Step 1: Enter the website in the browser to enter the algorithm selection page.

[0211] Step 2: Click the "0-1 Knapsack Dynamic Programming Algorithm" button to select the 0-1 knapsack dynamic programming algorithm.

[0212] Step 3: On the algorithm description page, custom-enter the initial data or use the default example, and click the "Continue" button.

[0213] Step 4: Click the "Start / Pause" button to start or pause the simulation demonstration process of the 0-1 knapsack dynamic programming algorithm. The effect diagram of this process on the web page is as Figure 11 shown.

[0214] Step 5: Click the "Accelerate" or "Decelerate" button to accelerate or decelerate the playback of the demonstration process.

[0215] Step 6: After the demonstration of the process of simulating the 0-1 knapsack dynamic programming algorithm ends, display the time and space complexity on this page.

[0216] Step 7: Click the "Return to Main Interface" button to return to the algorithm selection page.

[0217] In this embodiment, the Turing machine virtual simulation system is implemented on the browser web page using the Unity development technology. Specifically, the Turing machines simulating different strategy algorithms are demonstrated in the form of 3D animations, which can better help students understand the algorithms more deeply from the perspective of computational models in algorithm teaching.

[0218] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that they can still modify the technical solutions recorded in the foregoing embodiments, or perform equivalent replacements on some or all of the technical features; and these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope defined by the claims of the present invention.

Claims

1. A Turing machine virtual simulation system based on Unity, characterized in that: It includes a Turing machine modeling module, a Turing machine reading and writing action and state transfer design module, a UI design module, a state transfer equation design module, an algorithm complexity calculation module and a WebGL-based optimization module; the Turing machine modeling module models the Turing machine based on Unity according to task requirements and constructs a Turing machine model; the Turing machine reading and writing action and state transfer design module is used to implement the design of Turing machine reading and writing action and state transfer; the UI design module is used to design the UI interface of the Turing machine; the state transfer equation design module is used to design the state transfer equation of the Turing machine to achieve the task requirements, and then complete the task requirements through the Turing machine; The algorithm complexity calculation module is used to calculate the algorithm complexity required to achieve the task; the WebGL-based optimization module publishes the Turing machine virtual simulation system in WebGL format and deploys it on the server using node.js after publishing, ultimately enabling access to the Turing machine virtual simulation system through the web page; The specific method of the Turing machine modeling module to model the Turing machine based on Unity according to task requirements is: The set Turing machine task requirements are to implement five algorithms: unary addition, binary search Turing machine algorithm, binary search recursive algorithm, splittable knapsack greedy algorithm and 0-1 knapsack dynamic programming algorithm; Determine the Turing machine's read / write head and Turing machine framework model; Use 3dsMax to model the Turing machine's paper tape, read / write head, and finite state automaton; After modeling, export the FBX model and then import it into Unity to assign materials, and finally design it to complete the modeling work; In Unity, bind the paper tape, read / write head, and finite state automaton modeled in 3dsMax together to form the overall Turing machine model; and add a text component to display the automaton state and the paper tape content; In order to make it easier for users to intuitively observe the working process of the Turing machine, the Turing machine is designed as a three-reader-write head and three-paper tape model, including an input read-write head, a working read-write head, an output read-write head, an input paper tape, a working paper tape, an output paper tape, an automaton, and a state transition display screen.

2. The Turing machine virtual simulation system based on Unity according to claim 1, characterized in that: The design module for Turing machine reading and writing actions and state transfer designs a control read and write head script, a paper tape content update script, a paper tape movement control script, a state transfer script, a state display script, a simulation function call script, and a unit time access array for realizing Turing machine reading and writing actions and state transfer; The control script for the read / write head is used to control the up and down movement of the read / write head to simulate read / write operations. First, an empty object is created in the Unity scene as the target position for the read / write head to move. The start position, target position, and step size of the read / write head are given by the MoveTowards() function to change the position of the read / write head so that the read / write head moves back and forth between the target position and the start position. When the read / write head moves to the target position, a signal is sent to the state transfer script to start state transfer. When the read / write head moves back to the initial position, a signal is sent to the tape movement control script to start moving the tape. The script for updating the tape content is used to manage the data on the tape and provides two interfaces, setBST() and getBST(), externally. setBST() modifies the element at the target position on the tape by specifying the write position and the data to be written. getBST() retrieves the tape data at the specified position by specifying the position. Each time the update tape content signal of the state transition script is obtained, the tape data displayed in the current scene is updated. The script for controlling the tape movement is used to control the movement of the tape. It calls the interface getI() provided by the state transition script to obtain the target position to which the current tape should move by specifying the tape name. After receiving the signal to move the tape, it starts to move the tape. After moving to the target position, it sends a signal to the read / write head to make it drop to simulate the next read / write operation. The state transition script is used to control the state transition of the Turing machine and switch the input, working, and output tapes as well as the read / write head. Each state transition process is as follows: First, modify the content on the current tape, then update the current tape position. After that, send a signal to allow the tape to update its content and raise the read / write head back to the initial position. Finally, move the tape, select the tape for the next state, and update the state of the Turing machine. A variable nowTape is defined inside this script to determine whether the current tape and read / write head are the input, working, or output tape and read / write head. At the same time, variables inputI, workI, and outputI are defined to mark the current read / write positions of the input, working, and output tapes. The state display script uses the GetComponent method inherited from the GameObject class to call the interface getState() provided by the state transition script to obtain the state of the Turing machine and display it on the state display screen. The simulation function call script moves the tape data outside the view for updating to achieve the simulation function call process. Create an empty object in the scene as the target position for the tape movement. Use the MoveTowards() function to achieve the reciprocating movement of the read / write head between the target position and the initial position. For recursive calls, only update the data on the tape to the parameters input for the next level of recursion. For calls corresponding to sorting, directly update to the sorted result. The unit time access array is implemented in three cases: under deterministic state transition, under non-deterministic state transition, and when switching tapes. For the implementation of the unit time access array under deterministic state transition, it only needs to directly move to the position located according to the array subscript when performing the left / right shift operations of the tape. For the two cases of non-deterministic state transition and switching tapes, it is necessary to modify the positioning variables inputI, workI, and outputI before entering the next state, and call the interface provided by the script for controlling the tape movement to control the tape movement, and then enter the next state.

3. The Turing machine virtual simulation system based on Unity according to claim 2, characterized in that: The UI design module is specifically used to design the algorithm selection interface, the algorithm simulation interface, and implement the algorithm description and interaction functions. The algorithm selection interface designs five buttons for selecting the algorithms to be simulated, and realizes the function of scene jump by clicking the buttons by calling the SceneManager package in Unity; The algorithm simulation interface is used to display the data of each tape, time complexity, space complexity and the button to return to the algorithm selection page during algorithm simulation. It displays the positions where the three tapes are being read and written through a small window, and provides buttons for starting / pausing, accelerating and decelerating the algorithm simulation. The specific method is as follows: Call the interface provided by the script for updating the tape content to read the data on the tape and display it on the corresponding Text component in the interface; The small window display uses three cameras respectively corresponding to the central positions of the three tapes, obtains the perspectives of the cameras using the render texture in the camera properties, and renders the perspectives of the cameras to the pictures in the interface to realize the display of the data of the positions where the tapes are being read and written using the small window; In the binary search recursive algorithm, it is also necessary to implement the display of the recursive stack in the interface, that is, the data pushed into the recursive stack each time it is called; when the execution state is call, low, high and mid are pushed into the stack in sequence, and when returning, they are popped out of the stack following the principle of last in first out; in the small-scale 0-1 knapsack dynamic programming algorithm, the data in the two-dimensional array is also dynamically displayed in the interface through a two-dimensional table; The specific method for implementing the algorithm description and interaction function is as follows: after selecting the algorithm to be simulated on the algorithm selection interface, relevant descriptions of the selected algorithm are given. When the user finishes reading and clicks the continue button to watch the algorithm simulation process; and on the algorithm description page, an input function is provided using the InputField component in the UI, allowing the user to input the initial input tape data on this page by themselves.

4. The Unity-based Turing machine virtual simulation system according to claim 3, characterized in that: The specific method for the algorithm complexity calculation module to calculate the complexity of the five algorithms simulated by the Turing machine is as follows: In the script for controlling the movement of the read / write head, a new variable num1 is added and initialized to 0. When the read / write head drops and moves to the target position, num1 is incremented by 1, and an interface for returning the value of num1 is provided to give the time complexity; A vis array is added to the script for updating the tape content to mark whether each position on the working tape is used; and an interface for passing out the number of squares on the working tape used is added to display the algorithm complexity in real time in the UI.

5. The Turing machine virtual simulation system based on Unity according to claim 4, characterized in that: The state transition equation design module completes the task requirements of the Turing machine by designing an unary addition automaton, a binary search Turing machine algorithm automaton, a binary search recursive algorithm automaton, a divisible knapsack greedy algorithm automaton and a 0-1 knapsack dynamic programming algorithm automaton; The unary addition automaton realizes the simulation of unary addition through four states: 0, 1, 10, and 11; The binary search Turing machine algorithm automaton constructs 13 states to implement the simulation of the binary search Turing machine algorithm; the 13 states are: initLow, which reads the initial subscript low of the array A of the search interval to be searched from the input tape; writeLow, which writes low to the working tape; initHigh, which reads the ending subscript high of the array of the search interval to be searched from the input tape; writeHigh, which writes high to the working tape; compareLow, which compares high and low, and halts if low > high; calMid, which writes the middle value mid of low and high to the working tape; readMid, which reads the array element A[mid] at the mid position on the input tape; compareMid, which compares the array element A[mid] at the mid position with the target search element x. If A[mid] = x, the search is successful. If A[mid] > x, high is updated. If A[mid] < x, low is updated; updateLow, which updates low on the working tape to mid + 1; compareHigh, which compares the updated low and high, and halts if low > high; updateHigh, which updates high on the working tape to mid - 1; success, which indicates successful search; stop, which halts; Based on the states of the binary search Turing machine algorithm automaton, the binary search recursive algorithm automaton reduces the four states of initLow, initHigh, writeLow, and writeHigh, adds two states of call and return used for recursive calls, and constructs 11 states of the binary search recursive algorithm automaton; directly reads the parameters low and high from the input tape, and the calculated mid is still recorded on the working tape; and merges the state of updating low and high into the recursive call, and directly passes the parameters to the next recursive call according to the comparison result of A[mid] and x; The detachable knapsack greedy algorithm automaton realizes the simulation of the detachable knapsack greedy algorithm through 12 states, which are: readCapacity reads the knapsack capacity of the input paper tape; writeCapacity writes the knapsack capacity to the working paper tape; readWeight reads the weight of the object on the input paper tape; readValue reads the value of the object on the input paper tape; writeAverage writes the ratio of the object value to the weight to the working paper tape; writeNum writes the object serial number to the working paper tape; sort sorts the objects according to the value-to-weight ratio; readNum reads the object serial number on the working paper tape; readC reads the weight on the input paper tape corresponding to the object serial number; subBag subtracts the weight of the loaded object from the knapsack capacity and updates it on the working paper tape; writeAns writes the solution vector to the output paper tape; success algorithm simulation ends; The 0-1 backpack dynamic programming algorithm realizes the simulation of the 0-1 backpack dynamic programming algorithm through 14 states; the 14 states are: readCapacity reads the capacity of the backpack on the input paper tape; readNum reads the number of objects on the input paper tape; readWeight reads the weight of the objects on the input paper tape; readValue reads the value of the objects on the input paper tape; writeM(i,j) writes the optimal solution of the loaded object information to the position (i,j) of the working paper tape; readM(i+1,j) reads the loaded object information at the position (i+1,j) of the working paper tape; readW(i) reads the first object on the input paper tape. The weight of object i; calM(i+1,j-weight) reads the optimal solution of the object information at position (i+1,j-weight) on the work paper tape; ansM(i,j) reads the optimal solution of the work paper tape with the current object loaded; cmpAnsM(i,j) reads M(i+1,j) and M(i,j) on the work paper tape and compares them; writeAns(i-1) writes the solution vector to the output paper tape; writeAns(num) writes the solution vector to position num on the output paper tape; cmp compares the optimal solution with the current object loaded with the optimal solution without the current object loaded; the success algorithm simulation ends; Where i and j represent the position coordinates (i, j) in the two-dimensional array M storing the object data, weight represents the weight of the object, num represents the object number, i ranges from 0 to the number of objects + 1, and j ranges from 0 to the number of objects - 1.

6. The Unity-based Turing machine virtual simulation system according to claim 4, characterized in that: The specific method of unary addition automaton to realize unary addition simulation is: Step 101: Construct a unary additive automaton with four states: 0, 1, 10, and 11; Step 102: When the state of the unary addition automaton is 0, the working read / write head has not yet read the first addend; When the state is 0, if the working read / write head reads 0, the working tape moves to the right and the state remains unchanged until the read head reads 1, at which point the unary addition automaton's state transitions to 1; Step 103: When the state of the unary addition automaton is 1, it means the working read / write head of the Turing machine is reading the first number. When the working read / write head reads 0, it means the first number has been read. At this time, rewrite the 0 read on the working tape as 1, and the unary addition automaton transitions to state 10; Step 104: When the state of the unary addition automaton is 10, it means the working read / write head of the Turing machine is reading the second number. When it reads 0, it means the second number has also been read. At this time, move the working tape to the left and transfer the state of the unary addition automaton to 11; Step 105: When the state of the unary addition automaton is 11, rewrite the last 1 on the working tape as 0, and the Turing machine automatically halts; Step 106: Rewrite the last state 11 of the unary addition automaton; when the working read / write head reads 1, change the 1 on the working tape to 0, move the working tape to the right, and when it reads 0, the Turing machine halts.

7. The Unity-based Turing machine virtual simulation system according to claim 4, characterized in that: The specific method for the binary search Turing machine algorithm automaton to implement the binary search Turing machine algorithm simulation is as follows: Step 201: Construct 13 states of the binary search Turing machine algorithm automaton, which are respectively used for parameter initialization, calculating and comparing mid, updating parameters, and returning results; Step 202: Read low and high on the input tape through states initLow, writeLow, initHigh, and writeHigh and write them to the working tape; Step 203: Perform iterative binary search through 7 states: compareLow, compareHigh, calMid, readMid, compareMid, updateLow, and updateHigh. First, compare the sizes of low and high through states compareLow and compareHigh to determine whether to continue the iteration. If low > high, stop the iteration and transfer to state stop; otherwise, transfer to state calMid. After calculating the intermediate value mid and locating to the position of A[mid] through state calMid, the state of the binary search Turing machine algorithm automaton transfers to the readMid state to read A[mid], and then transfers to state compareMid. Compare the read A[mid] with the input target search element x, and finally update the parameter high or low according to the comparison result for the next round of iteration or terminate the iteration; If A[mid] = x, terminate the iteration, and the state of the binary search Turing machine algorithm automaton changes to success; if A[mid] > x, transfer to state updateHigh to update the parameter high and continue the iteration; if A[mid] < x, transfer to state updateLow to update the parameter low and continue the iteration; Step 204: Simulate the return operation of the Turing machine through the success and stop states; when A[mid] = x, the state transition of the binary search Turing machine algorithm automaton moves to the success state, and the mid at this time is written to the output tape as the return value, indicating that the target search element has been found and the search is successful. When low > high, it moves to the stop state, and -1 is written to the output tape, indicating that the search fails and there is no target search element.

8. The Unity-based Turing machine virtual simulation system according to claim 4, wherein: The specific method for the divisible knapsack greedy algorithm automaton to implement the simulation of the divisible knapsack greedy algorithm is as follows: Step 301: Construct 12 states of the divisible knapsack greedy algorithm automaton; Step 302: Initialize the knapsack capacity through the readCapacity and writeCapacity states, that is, read the knapsack capacity from the input tape and write it to the working tape; Step 303: Use the four states of readWeight, readValue, writeAverage, and writeNum to form the first loop to continuously read the weight and value of the objects, calculate the value-to-weight ratio of the objects, and write the object number and value-to-weight ratio to the working tape; Step 304: When the read weight reads #, it indicates that all objects have been read. At this time, the state of the divisible knapsack greedy algorithm automaton transfers to the sort state, and the objects are sorted according to the value-to-weight ratio; Step 305: Use the four states of readNum, readC, subBag, and writeAns to load the sorted objects into the knapsack in order; when the knapsack capacity is less than the total weight of the objects, load a part of the object with the largest value-to-weight ratio into the knapsack at this time, and then jump to the success state, and the algorithm simulation ends; Step 306: Process the state transitions of the two uncertain states of readWeight and writeAns; for the divisible knapsack greedy algorithm automaton, there are also two uncertain state transitions, namely readWeight and writeAns; for the readWeight state, when the read / write head reads a number and #, it transfers to the readValue state to continue reading the value and the sort state to sort the objects respectively; for the state transition of the writeAns state, it mainly depends on whether the previous state subBag fills the knapsack. If it is not filled, write 1 to the corresponding position in the object array on the output tape and continue to iterate the process of loading the knapsack. If it is filled, write the loading percentage to the corresponding position and transfer to the success state, and the algorithm simulation ends; Step 307: Return a solution vector X = {X1, X2, X3,... Xn}, where Xn is the nth object loaded into the knapsack, and n is the number of objects loaded into the knapsack.

9. The Unity-based Turing machine virtual simulation system according to claim 4, wherein: The specific method for the 0-1 knapsack dynamic programming algorithm automaton to realize the 0-1 knapsack dynamic programming algorithm simulation is: Step 401: construct 14 states of the 0-1 knapsack dynamic programming algorithm automaton; Step 402: The readCapacity state is used as the starting state of the 0-1 knapsack dynamic programming algorithm automaton. At this time, the knapsack capacity is read in and the input tape is shifted right by 1 space, and then the state is transferred to readNum. Step 403: When the 0-1 backpack dynamic programming algorithm automaton is in state readNum, the input read / write head reads the object serial number num and moves the input paper tape right to the position num*2, and then transfers to state readWeight; Step 404: When the 0-1 knapsack dynamic programming algorithm automaton is in the readWeight state, the input read / write head reads weight, the input tape moves right by one square, and the machine transitions to the readValue state. When in the readValue state, the input read / write head reads value, and the input tape moves left by three squares. Step 405: The 0-1 knapsack dynamic programming algorithm automaton state is transferred to the state writeM(i, j) or the state readM(i+1, j); when i=num, it is transferred to writeM(i, j), and at other times it is transferred to readM(i+1, j); When i=num, when writing the value data of the object read and written by the working read / write head into the two-dimensional array, it is only necessary to pay attention to whether the current object can be loaded. If it can be loaded, fill the two-dimensional array with the current object value, and if it cannot be loaded, fill it with 0; Step 406: When the 0-1 backpack dynamic programming algorithm automaton is in state writeM(i,j), the optimal solution with the maximum value of the object currently loaded into the backpack is filled into the corresponding position; there are three transfer routes for state writeM(i,j); When i=num, the working read / write head moves to the position M(num,j) on the working paper tape, and the working paper tape moves right by 1 grid and makes j+1, until j=capacity. The 0-1 knapsack dynamic programming algorithm automaton state moves to the state readWeight to read the next object information. When j = capacity, the work tape moves left to (i-1)*(capacity+1), and the 0-1 knapsack dynamic programming algorithm automaton state transfers to the readWeight state, and switches to the input tape and input read / write head; When i is not equal to num, the 0-1 knapsack dynamic programming algorithm automaton state transfers to state read(i+1,j) until j=capacity; and when i=1 and j=capacity, it transfers to state readW(i) to start recursive solution of vector operations and switch to output paper tape and output read / write head; Step 407: When the 0-1 knapsack dynamic programming algorithm automaton is in the state readM(i+1,j), when the knapsack can hold the current object, it should consider whether the benefit of loading the current object is greater or the benefit of not loading is greater. Therefore, when j >= weight, it transfers to the state calM(i+1,j-weight), reads the optimal solution with the maximum value of loading the current object, adds it to the value of the current object, and compares it with the optimal solution with the maximum value when not loading the current object to obtain the optimal solution and fill it in the position of the two-dimensional array subscript (i+1,j-weight). Step 408: When the state of the 0-1 knapsack dynamic programming algorithm automaton transfers from the state readM(i+1,j) to the state calM(i+1,j-weight), the working paper tape moves right to the position i*(capacity+1)+mj-weight. When the current object cannot be put into the knapsack, that is, j < weight, the state transfers to write(i,j), that is, directly write M(i+1,j), and the working paper tape moves right 1 grid. Step 409: For the state calM(i+1,j-weight), the working paper tape moves right to the position i*(capacity+1), transfers to the state cmp. Through the state cmp for comparison, and then obtains the optimal solution with the maximum value of the current loaded object. The working paper tape moves left to the corresponding position of (i,j), and transfers to the state writeM(i,j). Step 410: When the 0-1 knapsack dynamic programming algorithm automaton is in the readW(i) state, recursively calculate the serial number of the object loaded into the knapsack and write it into the solution vector. Through the readW(i) state, read the weight of the i-th object, the working paper tape moves right 2 grids, transfers to the state ansM(i,j), and at the same time switches to the working paper tape and the working read-write head. Through the state ansM(i,j), read the optimal solution with the maximum value of the current loaded object, the working paper tape moves right capacity+1 grids, and transfers to the state cmpAnsM(i,j). Through the state cmpAnsM(i,j), read M(i+1,j) and compare it with M(i,j). If they are the same, it means that the object is not loaded into the knapsack, and transfers to the state readW(i). If they are different, it means that the object is loaded into the knapsack, the working paper tape moves left weight grids, transfers to the state writeAns(i-1), and switches to the output read-write head and the output paper tape. Through the state writeAns(i-1), write 1 or 0 indicating whether the object is loaded into the solution vector, and transfer to the state readW(i), and at the same time switch to the input paper tape and the input read-write head. When i = num, directly transfer from the state ansM(i,j) to the state writeAns(num), and judge whether the object is loaded into the knapsack according to whether M(i,j) is 0 and fill in the solution vector, and finally transfer to the state success, and the algorithm simulation is completed. Step 411: Return a solution vector of Y = {Y1, Y2, Y3, …, Ym}, where Ym is the solution output on the output tape and m is the number of solutions.

Citation Information

Patent Citations

  • Turing model-based augment reality assembly environment system modeling method

    CN102073758A

  • Nondeterministic Turing Machine Computer Architecture for Efficient Processing Using Spatial Relationships

    US20180129949A1