Our program consists of two main parts, including the conversion of Nondeterministic Finite Automaton (NFA) to deterministic finite automaton (DFA) and also Reduction for minimizing the given input as much as possible.
The NFA to DFA algorithm contains three major functions. The first function(access lambda)،finds all possible transitions using epsilon transition. The second function(lambdaremove)، removes epsilon transitions by merging the related states. The last function(repeatedremove)makes a new transition table using the old values. That table is considered the final output of the program, which will be shown to the user after turning into a JSON format.
The reduction Algorithm has two separate sections. The first section is for removing inaccessible states using a function (RemoveInaccessibleStates), and the second is for finding equal states. This part contains three major functions. The first function, (createTransitionTable), is responsible for creating a transition table. The second function, (findEqualStates) is responsible for finding equal states from the transition table and removing equal, repeated states. The last function (standardTransitionTable) is responsible for building a new machine with survived states. The final output is converted to JSON format and ready to be sent to Front.
![Screenshot 2023-06-06 at 5 35 10 PM](https://private-user-images.githubusercontent.com/62938359/243722975-86fa9427-1290-41a4-bc4a-20487ac0ecaa.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk2NTYxNzIsIm5iZiI6MTczOTY1NTg3MiwicGF0aCI6Ii82MjkzODM1OS8yNDM3MjI5NzUtODZmYTk0MjctMTI5MC00MWE0LWJjNGEtMjA0ODdhYzBlY2FhLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTUlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjE1VDIxNDQzMlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTllOWEwMmQyYmUyMGFlYjUyODY0YjRkOGQ1Y2VjZjNjZWVhMWQ0NjQyOTA1MzAzMDZhOGQ4NTgwOWI1Y2MzMmImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.SI9dnJzuyf9f4pCI-pINWX3KI_z5LIipLyMykK3BytE)
![Screenshot 2023-06-06 at 5 35 30 PM](https://private-user-images.githubusercontent.com/62938359/243722965-056cf444-3d3c-461e-8610-46609125b723.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk2NTYxNzIsIm5iZiI6MTczOTY1NTg3MiwicGF0aCI6Ii82MjkzODM1OS8yNDM3MjI5NjUtMDU2Y2Y0NDQtM2QzYy00NjFlLTg2MTAtNDY2MDkxMjViNzIzLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTUlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjE1VDIxNDQzMlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTBiZGU0NmI2ODdiODUyNDU2ZTFlNGNjOWFmMjdjZWE1YzRkNDVlZWY3MmRjZTQzMGVmZmY1MTJjODQ2NDA2MjQmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.am109j8t8ZD4jL6SS6nZyPoUdtdxDnNtoAbvY09wRCE)
![Screenshot 2023-06-06 at 5 35 40 PM](https://private-user-images.githubusercontent.com/62938359/243722951-ea2a2530-adec-4478-b4d1-ab3bf1b1280d.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk2NTYxNzIsIm5iZiI6MTczOTY1NTg3MiwicGF0aCI6Ii82MjkzODM1OS8yNDM3MjI5NTEtZWEyYTI1MzAtYWRlYy00NDc4LWI0ZDEtYWIzYmYxYjEyODBkLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTUlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjE1VDIxNDQzMlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTgyMjI0NTA3ODRjZjBhOGZkNzhjNjNjOGMzZGRlODhiMTZiMTIzY2M1OGY1NjcwYmRiMmU3OWMxZmU3NzQyMTcmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.fDxXot9S46jr7oBNviKZbyOa_7ayir4r4f2IcwrxMnA)
![Screenshot 2023-06-06 at 5 37 11 PM](https://private-user-images.githubusercontent.com/62938359/243722938-c4bc607f-2e03-48b9-97a7-758994b0fd52.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk2NTYxNzIsIm5iZiI6MTczOTY1NTg3MiwicGF0aCI6Ii82MjkzODM1OS8yNDM3MjI5MzgtYzRiYzYwN2YtMmUwMy00OGI5LTk3YTctNzU4OTk0YjBmZDUyLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTUlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjE1VDIxNDQzMlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTQ2Mzc4ZjFlMjhmMWY3OWE2MTkxMzAyMTU2OGNhZDllNTU5Y2U2MTliNThjMTRmOGUyOWNkOGNkNDIwMjM4MjUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.u4NvJ8m-OkEUJoNgwAu2UZhiBrzw6scKWUB5dIA-Qms)
![Screenshot 2023-06-06 at 5 37 30 PM](https://private-user-images.githubusercontent.com/62938359/243722917-e2ebbb15-4b57-44b0-8d30-fbcf22d60f46.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk2NTYxNzIsIm5iZiI6MTczOTY1NTg3MiwicGF0aCI6Ii82MjkzODM1OS8yNDM3MjI5MTctZTJlYmJiMTUtNGI1Ny00NGIwLThkMzAtZmJjZjIyZDYwZjQ2LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTUlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjE1VDIxNDQzMlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTQyNWEyZWIwOTQ1MzVmOTIyMGI3NGFkMWEzYjVkMThmYjM1YzYxMTBhNDhkOTVhMmRhNWM1NmQ2ODA3YTZjZDAmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.q0l9iMM8YMKwHtmnaPhxhGc2CcGaFt_wfad9VOFZKPg)
![Screenshot 2023-06-06 at 5 37 45 PM](https://private-user-images.githubusercontent.com/62938359/243722904-4a1e8bf9-aeaf-4e09-9aac-a675313a7b3f.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk2NTYxNzIsIm5iZiI6MTczOTY1NTg3MiwicGF0aCI6Ii82MjkzODM1OS8yNDM3MjI5MDQtNGExZThiZjktYWVhZi00ZTA5LTlhYWMtYTY3NTMxM2E3YjNmLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTUlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjE1VDIxNDQzMlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWE5NWM3MWY5YTI3MGY3ZGIwOGZlNDU4YjExZmQ2ZjIzZTE1MGQ3MmY2ZWUzNTQyNTc4MjliZmUwOTk2ZmIxYTMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.JVNYRr5Y3A9KesEbRRpyri0UeLfHZa6R8xaXzPqkmRo)
![Screenshot 2023-06-06 at 5 37 59 PM](https://private-user-images.githubusercontent.com/62938359/243722874-e11e05a9-0be2-423c-8dc7-4620eafae8c4.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk2NTYxNzIsIm5iZiI6MTczOTY1NTg3MiwicGF0aCI6Ii82MjkzODM1OS8yNDM3MjI4NzQtZTExZTA1YTktMGJlMi00MjNjLThkYzctNDYyMGVhZmFlOGM0LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTUlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjE1VDIxNDQzMlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWU1MDk1MjllY2JmZWM1YjMzNDUzNzAyNWQ0MGM1ZTgyY2NjOTQ5MjRhZGRmMjc5NGY2NWUzMTJhODExZTM3ZTcmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.VVx-sK_ve_sQy5ShPtTb8klqJi3gKCsnyOQaLl255JY)
localhost:8000/nfa-to-dfa/{json_format}
The first index of our json is the states name, and in each states, we set their connection and state status. For example, in state "q0" we have just one connection with "q1" by "a" and other connections like "b", "λ", and "c" are null, but we shouldn't remove them from our input json and the last value "state" show the status of our state and only get "start", "final", "normal" value.
{
"q0":{
"a":[
"q1"
],
"b":[
],
"λ":[
],
"state":[
"start"
]
},
"q1":{
"a":[
],
"b":[
"q2"
],
"λ":[
],
"state":[
"normal"
]
},
"q2":{
"a":[
],
"b":[
],
"λ":[
"q2"
],
"state":[
"final"
]
}
}
In output we only have one extra states status and its "TRAP" like state "2" and other value are like input value.
{
"0":{
"state":[
"start"
],
"a":[
"1"
],
"b":[
"2"
]
},
"1":{
"state":[
"normal"
],
"a":[
"2"
],
"b":[
"3"
]
},
"2":{
"state":[
"TRAP"
],
"a":[
"2"
],
"b":[
"2"
]
},
"3":{
"state":[
"final"
],
"a":[
"2"
],
"b":[
"2"
]
}
}
If send empty JSON we will see these errors:
{"status": null}
If send the DFA machine we will see these errors because the DFA machine didn't need to change DFA and the input machine should be NFA:
{"is_dfa": True}
localhost:8000/reduction/{json_format}
All of the inputs and outputs in reduction are like NFA to DFA Api.
If send empty JSON we will see these errors:
{"status": null}
If send the NFA machine we will see this error because the reduction algorithm just gets DFA machine:
{"is_nfa": True}
-
Click and drag new Connections from the orange div in each State, Each State supports up to 20 Connections.
-
Click on a Connection to delete or rename it.
-
Double-click on the black movable button to see the Clear, NTD, Red, and Help button.
-
Right-click on the white page to see a menu of buttons.
-
Click on a 'Nfa 2 Dfa' button to convert from Nfa to Dfa and Show it.
-
Click on a 'Reduction' button to process a Reduction algorithm.
-
RightClick on a State to delete, rename, Start, or Finalize it.
-
Double-click on whitespace to add a new State.
To run this project follow below steps:
- Install
python3
,pip
in your system. - Clone this repository
https://github.com/mohamadkhalaj/statemachine-app.git
. - Run below commands:
pip install -r requirements.txt
python manage.py collectstatic
python manage.py runserver
- Open the following address
http://localhost:8000/
in your browser. - enjoy :)