noshot 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- noshot/__init__.py +1 -0
- noshot/data/AIDS CN NLP/AIDS/1. Implement Basic Search Strategies/(A) Breadth First Search.ipynb +112 -0
- noshot/data/AIDS CN NLP/AIDS/1. Implement Basic Search Strategies/(B) Depth First Search.ipynb +111 -0
- noshot/data/AIDS CN NLP/AIDS/1. Implement Basic Search Strategies/(C) Uniform Cost Search.ipynb +134 -0
- noshot/data/AIDS CN NLP/AIDS/1. Implement Basic Search Strategies/(D) Depth Limites Search.ipynb +115 -0
- noshot/data/AIDS CN NLP/AIDS/1. Implement Basic Search Strategies/(E) Iterative Deepening DFS.ipynb +123 -0
- noshot/data/AIDS CN NLP/AIDS/10. ANOVA/2_ANOVA.csv +769 -0
- noshot/data/AIDS CN NLP/AIDS/10. ANOVA/One Way ANOVA (Repeated Measure).ipynb +126 -0
- noshot/data/AIDS CN NLP/AIDS/10. ANOVA/One Way ANOVA.ipynb +134 -0
- noshot/data/AIDS CN NLP/AIDS/10. ANOVA/Sample 1 Way ANOVA Test.ipynb +119 -0
- noshot/data/AIDS CN NLP/AIDS/10. ANOVA/Two Way ANOVA.ipynb +138 -0
- noshot/data/AIDS CN NLP/AIDS/10. ANOVA/reaction_time.csv +5 -0
- noshot/data/AIDS CN NLP/AIDS/10. ANOVA/sample_data.csv +16 -0
- noshot/data/AIDS CN NLP/AIDS/10. ANOVA/sleep_deprivation.csv +4 -0
- noshot/data/AIDS CN NLP/AIDS/11. Linear Regression/3_Linear.csv +4802 -0
- noshot/data/AIDS CN NLP/AIDS/11. Linear Regression/Linear Regression LAB.ipynb +113 -0
- noshot/data/AIDS CN NLP/AIDS/11. Linear Regression/Linear Regression New- sklearn.ipynb +118 -0
- noshot/data/AIDS CN NLP/AIDS/11. Linear Regression/Linear Regression.ipynb +148 -0
- noshot/data/AIDS CN NLP/AIDS/11. Linear Regression/house_rate.csv +22 -0
- noshot/data/AIDS CN NLP/AIDS/12. Logistic Regression/Logistic Regression New- sklearn.ipynb +128 -0
- noshot/data/AIDS CN NLP/AIDS/12. Logistic Regression/Logistic Regression.ipynb +145 -0
- noshot/data/AIDS CN NLP/AIDS/12. Logistic Regression/default.csv +1001 -0
- noshot/data/AIDS CN NLP/AIDS/12. Logistic Regression/hours_scores_records.csv +101 -0
- noshot/data/AIDS CN NLP/AIDS/2. Implement A Star And MA Star/(A) Astar.ipynb +256 -0
- noshot/data/AIDS CN NLP/AIDS/2. Implement A Star And MA Star/(B) IDAstar.ipynb +157 -0
- noshot/data/AIDS CN NLP/AIDS/2. Implement A Star And MA Star/(C) SMAstar.ipynb +178 -0
- noshot/data/AIDS CN NLP/AIDS/3. Genetic Algorithm/Genetic.ipynb +95 -0
- noshot/data/AIDS CN NLP/AIDS/4. Simulated Annealing/Simulated Annealing.ipynb +74 -0
- noshot/data/AIDS CN NLP/AIDS/4. Simulated Annealing/Sudoku Simulated Annealing.ipynb +103 -0
- noshot/data/AIDS CN NLP/AIDS/5. Alpha Beta Pruning/AlphaBetaPruning.ipynb +182 -0
- noshot/data/AIDS CN NLP/AIDS/6. Consraint Satisfaction Problems (CSP)/(A) CSP House Allocation.ipynb +120 -0
- noshot/data/AIDS CN NLP/AIDS/6. Consraint Satisfaction Problems (CSP)/(B) CSP Map Coloring.ipynb +125 -0
- noshot/data/AIDS CN NLP/AIDS/7. Random Sampling/Random Sampling.ipynb +73 -0
- noshot/data/AIDS CN NLP/AIDS/7. Random Sampling/height_weight_bmi.csv +8389 -0
- noshot/data/AIDS CN NLP/AIDS/8. Z Test/Z Test Hash Function.ipynb +141 -0
- noshot/data/AIDS CN NLP/AIDS/8. Z Test/Z Test.ipynb +151 -0
- noshot/data/AIDS CN NLP/AIDS/8. Z Test/height_weight_bmi.csv +8389 -0
- noshot/data/AIDS CN NLP/AIDS/9. T Test/1_heart.csv +304 -0
- noshot/data/AIDS CN NLP/AIDS/9. T Test/Independent T Test.ipynb +119 -0
- noshot/data/AIDS CN NLP/AIDS/9. T Test/Paired T Test.ipynb +118 -0
- noshot/data/AIDS CN NLP/AIDS/9. T Test/T Test Hash Function.ipynb +142 -0
- noshot/data/AIDS CN NLP/AIDS/9. T Test/T Test.ipynb +158 -0
- noshot/data/AIDS CN NLP/AIDS/9. T Test/height_weight_bmi.csv +8389 -0
- noshot/data/AIDS CN NLP/AIDS/9. T Test/iq_test.csv +0 -0
- noshot/data/AIDS CN NLP/AIDS/Others (AllinOne)/All In One.ipynb +4581 -0
- noshot/data/AIDS CN NLP/CN/1. Chat Application/chat.java +81 -0
- noshot/data/AIDS CN NLP/CN/1. Chat Application/output.png +0 -0
- noshot/data/AIDS CN NLP/CN/1. Chat Application/procedure.png +0 -0
- noshot/data/AIDS CN NLP/CN/10. Ethernet LAN IEEE 802.3/LAN.tcl +65 -0
- noshot/data/AIDS CN NLP/CN/10. Ethernet LAN IEEE 802.3/analysis.awk +44 -0
- noshot/data/AIDS CN NLP/CN/10. Ethernet LAN IEEE 802.3/output.png +0 -0
- noshot/data/AIDS CN NLP/CN/10. Ethernet LAN IEEE 802.3/procedure.png +0 -0
- noshot/data/AIDS CN NLP/CN/11. Wireless LAN IEEE 802.11/complexdcf.tcl +229 -0
- noshot/data/AIDS CN NLP/CN/11. Wireless LAN IEEE 802.11/output.png +0 -0
- noshot/data/AIDS CN NLP/CN/11. Wireless LAN IEEE 802.11/procedure.png +0 -0
- noshot/data/AIDS CN NLP/CN/2. File Transfer/file_to_send.txt +2 -0
- noshot/data/AIDS CN NLP/CN/2. File Transfer/filetransfer.java +119 -0
- noshot/data/AIDS CN NLP/CN/2. File Transfer/output.png +0 -0
- noshot/data/AIDS CN NLP/CN/2. File Transfer/procedure.png +0 -0
- noshot/data/AIDS CN NLP/CN/3. RMI (Remote Method Invocation)/output.png +0 -0
- noshot/data/AIDS CN NLP/CN/3. RMI (Remote Method Invocation)/procedure.png +0 -0
- noshot/data/AIDS CN NLP/CN/3. RMI (Remote Method Invocation)/rmi.java +56 -0
- noshot/data/AIDS CN NLP/CN/4. Wired Network/output.png +0 -0
- noshot/data/AIDS CN NLP/CN/4. Wired Network/procedure.png +0 -0
- noshot/data/AIDS CN NLP/CN/4. Wired Network/wired.awk +25 -0
- noshot/data/AIDS CN NLP/CN/4. Wired Network/wired.tcl +81 -0
- noshot/data/AIDS CN NLP/CN/5. Wireless Network/output.png +0 -0
- noshot/data/AIDS CN NLP/CN/5. Wireless Network/procedure.png +0 -0
- noshot/data/AIDS CN NLP/CN/5. Wireless Network/wireless.awk +27 -0
- noshot/data/AIDS CN NLP/CN/5. Wireless Network/wireless.tcl +153 -0
- noshot/data/AIDS CN NLP/CN/6. TCP Flow And Congestion Control/TCP Congestion Control/Sack And Vegas/analysis.awk +27 -0
- noshot/data/AIDS CN NLP/CN/6. TCP Flow And Congestion Control/TCP Congestion Control/Sack And Vegas/output.png +0 -0
- noshot/data/AIDS CN NLP/CN/6. TCP Flow And Congestion Control/TCP Congestion Control/Sack And Vegas/sack.tcl +86 -0
- noshot/data/AIDS CN NLP/CN/6. TCP Flow And Congestion Control/TCP Congestion Control/Sack And Vegas/vegas.tcl +86 -0
- noshot/data/AIDS CN NLP/CN/6. TCP Flow And Congestion Control/TCP Congestion Control/Tahoe And Reno/analysis.awk +28 -0
- noshot/data/AIDS CN NLP/CN/6. TCP Flow And Congestion Control/TCP Congestion Control/Tahoe And Reno/output.png +0 -0
- noshot/data/AIDS CN NLP/CN/6. TCP Flow And Congestion Control/TCP Congestion Control/Tahoe And Reno/reno.tcl +78 -0
- noshot/data/AIDS CN NLP/CN/6. TCP Flow And Congestion Control/TCP Congestion Control/Tahoe And Reno/tahoe.tcl +79 -0
- noshot/data/AIDS CN NLP/CN/6. TCP Flow And Congestion Control/TCP Flow Control/analysis.awk +27 -0
- noshot/data/AIDS CN NLP/CN/6. TCP Flow And Congestion Control/TCP Flow Control/flow.tcl +163 -0
- noshot/data/AIDS CN NLP/CN/6. TCP Flow And Congestion Control/TCP Flow Control/output.png +0 -0
- noshot/data/AIDS CN NLP/CN/6. TCP Flow And Congestion Control/procedure.png +0 -0
- noshot/data/AIDS CN NLP/CN/7. Link State And Distance Vector Routing/DV.tcl +111 -0
- noshot/data/AIDS CN NLP/CN/7. Link State And Distance Vector Routing/LS.tcl +106 -0
- noshot/data/AIDS CN NLP/CN/7. Link State And Distance Vector Routing/analysis.awk +36 -0
- noshot/data/AIDS CN NLP/CN/7. Link State And Distance Vector Routing/output.png +0 -0
- noshot/data/AIDS CN NLP/CN/7. Link State And Distance Vector Routing/procedure.png +0 -0
- noshot/data/AIDS CN NLP/CN/8. Multicast And Broadcast Routing/analysis.awk +20 -0
- noshot/data/AIDS CN NLP/CN/8. Multicast And Broadcast Routing/broadcast.tcl +76 -0
- noshot/data/AIDS CN NLP/CN/8. Multicast And Broadcast Routing/multicast.tcl +103 -0
- noshot/data/AIDS CN NLP/CN/8. Multicast And Broadcast Routing/output.png +0 -0
- noshot/data/AIDS CN NLP/CN/8. Multicast And Broadcast Routing/procedure.png +0 -0
- noshot/data/AIDS CN NLP/CN/9. DHCP/DHCP.java +125 -0
- noshot/data/AIDS CN NLP/CN/9. DHCP/output.png +0 -0
- noshot/data/AIDS CN NLP/CN/9. DHCP/procedure.png +0 -0
- noshot/data/AIDS CN NLP/NLP/NLP 1/1-Prereqs.py +18 -0
- noshot/data/AIDS CN NLP/NLP/NLP 1/2-Chi2test.py +83 -0
- noshot/data/AIDS CN NLP/NLP/NLP 1/2-T-test.py +79 -0
- noshot/data/AIDS CN NLP/NLP/NLP 1/3-WSD-nb.py +53 -0
- noshot/data/AIDS CN NLP/NLP/NLP 1/4-Hindle-Rooth.py +53 -0
- noshot/data/AIDS CN NLP/NLP/NLP 1/5-HMM-Trellis.py +82 -0
- noshot/data/AIDS CN NLP/NLP/NLP 1/6-HMM-Viterbi.py +16 -0
- noshot/data/AIDS CN NLP/NLP/NLP 1/7-PCFG-parsetree.py +15 -0
- noshot/data/AIDS CN NLP/NLP/NLP 1/Chi2test.ipynb +285 -0
- noshot/data/AIDS CN NLP/NLP/NLP 1/Hindle-Rooth.ipynb +179 -0
- noshot/data/AIDS CN NLP/NLP/NLP 1/Lab 10 - Text generator using LSTM.ipynb +1461 -0
- noshot/data/AIDS CN NLP/NLP/NLP 1/Lab 11 NMT.ipynb +2307 -0
- noshot/data/AIDS CN NLP/NLP/NLP 1/PCFG.ipynb +134 -0
- noshot/data/AIDS CN NLP/NLP/NLP 1/Prereqs.ipynb +131 -0
- noshot/data/AIDS CN NLP/NLP/NLP 1/T test.ipynb +252 -0
- noshot/data/AIDS CN NLP/NLP/NLP 1/TFIDF BOW.ipynb +171 -0
- noshot/data/AIDS CN NLP/NLP/NLP 1/Trellis.ipynb +244 -0
- noshot/data/AIDS CN NLP/NLP/NLP 1/WSD.ipynb +645 -0
- noshot/data/AIDS CN NLP/NLP/NLP 1/Word2Vec.ipynb +93 -0
- noshot/data/AIDS CN NLP/NLP/NLP 2/Lab01(tokenizer)/tokenizer.ipynb +370 -0
- noshot/data/AIDS CN NLP/NLP/NLP 2/Lab01(tokenizer)/training_tokenizer.txt +6 -0
- noshot/data/AIDS CN NLP/NLP/NLP 2/Lab02(stemming)/exp0.ipynb +274 -0
- noshot/data/AIDS CN NLP/NLP/NLP 2/Lab02(stemming)/lab2.ipynb +905 -0
- noshot/data/AIDS CN NLP/NLP/NLP 2/Lab02(stemming)/test.txt +1 -0
- noshot/data/AIDS CN NLP/NLP/NLP 2/Lab02(stemming)/tokenizing.ipynb +272 -0
- noshot/data/AIDS CN NLP/NLP/NLP 2/Lab03(parse-tree)/collocation.ipynb +332 -0
- noshot/data/AIDS CN NLP/NLP/NLP 2/Lab03(parse-tree)/lab3.ipynb +549 -0
- noshot/data/AIDS CN NLP/NLP/NLP 2/Lab03(parse-tree)/nlp.txt +1 -0
- noshot/data/AIDS CN NLP/NLP/NLP 2/Lab04(collocation)/Lab4-NLP-Exp-2.ipynb +817 -0
- noshot/data/AIDS CN NLP/NLP/NLP 2/Lab04(collocation)/collocation.ipynb +332 -0
- noshot/data/AIDS CN NLP/NLP/NLP 2/Lab05(WSD)/NLP-Lab-5-Exp3.ipynb +231 -0
- noshot/data/AIDS CN NLP/NLP/NLP 2/Lab05(WSD)/word-sense-disambiguation.ipynb +507 -0
- noshot/data/AIDS CN NLP/NLP/NLP 2/Lab06(additional-exercise)/lab6.ipynb +134 -0
- noshot/data/AIDS CN NLP/NLP/NLP 2/Lab07(HMM,Viterbi)/NLP Exp 4.ipynb +255 -0
- noshot/data/AIDS CN NLP/NLP/NLP 2/Lab07(HMM,Viterbi)/NLP_Exp_5.ipynb +159 -0
- noshot/data/AIDS CN NLP/NLP/NLP 2/Lab08(PCFG)/PCFG.ipynb +282 -0
- noshot/data/AIDS CN NLP/NLP/NLP 2/Lab09-Hindle-rooth&MLP/Lab 9 - MLP classifier.ipynb +670 -0
- noshot/data/AIDS CN NLP/NLP/NLP 2/Lab09-Hindle-rooth&MLP/MLP-alternative-code.ipynb +613 -0
- noshot/data/AIDS CN NLP/NLP/NLP 2/Lab09-Hindle-rooth&MLP/hindle-rooth-algorithm.ipynb +74 -0
- noshot/data/AIDS CN NLP/NLP/NLP 2/Lab10(LSTM)/Lab_10_Text_generator_using_LSTM.ipynb +480 -0
- noshot/data/AIDS CN NLP/NLP/NLP 2/Lab11(Viterbi-PCFG,Machine-translation)/Machine-translation.ipynb +445 -0
- noshot/data/AIDS CN NLP/NLP/NLP 2/Lab11(Viterbi-PCFG,Machine-translation)/Viterbi-PCFG.ipynb +105 -0
- noshot/data/AIDS CN NLP/NLP/NLP 2/Lab11(Viterbi-PCFG,Machine-translation)/corpora_tools.py +87 -0
- noshot/data/AIDS CN NLP/NLP/NLP 2/Lab11(Viterbi-PCFG,Machine-translation)/data_utils.py +11 -0
- noshot/data/AIDS CN NLP/NLP/NLP 2/Lab11(Viterbi-PCFG,Machine-translation)/train_translator.py +83 -0
- noshot/data/AIDS CN NLP/NLP/NLP 2/Lab12(Information-Extraction)/Information_Extraction.ipynb +201 -0
- noshot/data/AIDS CN NLP/NLP/NLP 3/Backtrack-without-Verbitri.ipynb +185 -0
- noshot/data/AIDS CN NLP/NLP/NLP 3/Backward-Procedure.ipynb +597 -0
- noshot/data/AIDS CN NLP/NLP/NLP 3/Bag_of.ipynb +1422 -0
- noshot/data/AIDS CN NLP/NLP/NLP 3/CYK-algorithm.ipynb +1067 -0
- noshot/data/AIDS CN NLP/NLP/NLP 3/Forward-Procedure.ipynb +477 -0
- noshot/data/AIDS CN NLP/NLP/NLP 3/LSTM.ipynb +1290 -0
- noshot/data/AIDS CN NLP/NLP/NLP 3/Lab 10 - Text generator using LSTM.ipynb +1461 -0
- noshot/data/AIDS CN NLP/NLP/NLP 3/Lab 11 NMT.ipynb +2307 -0
- noshot/data/AIDS CN NLP/NLP/NLP 3/NLP-LAB-4.ipynb +216 -0
- noshot/data/AIDS CN NLP/NLP/NLP 3/NLP-LAB-5.ipynb +216 -0
- noshot/data/AIDS CN NLP/NLP/NLP 3/abc.txt +6 -0
- noshot/data/AIDS CN NLP/NLP/NLP 3/ex-1-nltk.ipynb +711 -0
- noshot/data/AIDS CN NLP/NLP/NLP 3/ex-2-nlp.ipynb +267 -0
- noshot/data/AIDS CN NLP/NLP/NLP 3/exp8&9.ipynb +305 -0
- noshot/data/AIDS CN NLP/NLP/NLP 3/hind.ipynb +287 -0
- noshot/data/AIDS CN NLP/NLP/NLP 3/lab66.ipynb +752 -0
- noshot/data/AIDS CN NLP/NLP/NLP 3/leb_3.ipynb +612 -0
- noshot/data/AIDS CN NLP/NLP/NLP 3/naive_bayes_classifier.pkl +0 -0
- noshot/data/AIDS CN NLP/NLP/NLP 3/nlp_leb_1.ipynb +3008 -0
- noshot/data/AIDS CN NLP/NLP/NLP 3/nlp_leb_2.ipynb +3095 -0
- noshot/data/AIDS CN NLP/NLP/NLP 3/nlplab-9.ipynb +295 -0
- noshot/data/AIDS CN NLP/NLP/NLP 3/nltk-ex-4.ipynb +506 -0
- noshot/data/AIDS CN NLP/NLP/NLP 3/text1.txt +48 -0
- noshot/data/AIDS CN NLP/NLP/NLP 3/text2.txt +8 -0
- noshot/data/AIDS CN NLP/NLP/NLP 3/text3.txt +48 -0
- noshot/data/AIDS CN NLP/NLP/NLP 3/translation-rnn.ipynb +812 -0
- noshot/data/AIDS CN NLP/NLP/NLP 3/word2vector.ipynb +173 -0
- noshot/data/AIDS CN NLP/NLP/NLP 4/Backward Procedure Algorithm.ipynb +179 -0
- noshot/data/AIDS CN NLP/NLP/NLP 4/Chi Square Collocation.ipynb +208 -0
- noshot/data/AIDS CN NLP/NLP/NLP 4/Collocation (T test).ipynb +188 -0
- noshot/data/AIDS CN NLP/NLP/NLP 4/Experiment 1.ipynb +437 -0
- noshot/data/AIDS CN NLP/NLP/NLP 4/Forward Procedure Algorithm.ipynb +132 -0
- noshot/data/AIDS CN NLP/NLP/NLP 4/Hindle Rooth.ipynb +414 -0
- noshot/data/AIDS CN NLP/NLP/NLP 4/MachineTranslation.ipynb +368 -0
- noshot/data/AIDS CN NLP/NLP/NLP 4/Multi Layer Perceptron using MLPClassifier.ipynb +86 -0
- noshot/data/AIDS CN NLP/NLP/NLP 4/Multi Layer Perceptron using Tensorflow.ipynb +112 -0
- noshot/data/AIDS CN NLP/NLP/NLP 4/PCFG Inside Probability.ipynb +451 -0
- noshot/data/AIDS CN NLP/NLP/NLP 4/Text Generation using LSTM.ipynb +297 -0
- noshot/data/AIDS CN NLP/NLP/NLP 4/Viterbi.ipynb +310 -0
- noshot/data/AIDS CN NLP/NLP/NLP 4/Word Sense Disambiguation.ipynb +335 -0
- noshot/data/AIDS CN NLP/NLP/NLP 5/10.Text Generation using LSTM.ipynb +316 -0
- noshot/data/AIDS CN NLP/NLP/NLP 5/11.Machine Translation.ipynb +868 -0
- noshot/data/AIDS CN NLP/NLP/NLP 5/2.T and Chi2 Test.ipynb +204 -0
- noshot/data/AIDS CN NLP/NLP/NLP 5/3.Word Sense Diambiguation.ipynb +234 -0
- noshot/data/AIDS CN NLP/NLP/NLP 5/4.Hinddle and Rooth.ipynb +128 -0
- noshot/data/AIDS CN NLP/NLP/NLP 5/5.Forward and Backward.ipynb +149 -0
- noshot/data/AIDS CN NLP/NLP/NLP 5/6.Viterbi.ipynb +111 -0
- noshot/data/AIDS CN NLP/NLP/NLP 5/7.PCFG Parse Tree.ipynb +134 -0
- noshot/data/AIDS CN NLP/NLP/NLP 5/7.PCFG using cyk.ipynb +101 -0
- noshot/data/AIDS CN NLP/NLP/NLP 5/8.Bag of words and TF-IDF.ipynb +310 -0
- noshot/data/AIDS CN NLP/NLP/NLP 5/9.Word2Vector.ipynb +78 -0
- noshot/data/AIDS CN NLP/NLP/NLP 5/NLP ALL In One.ipynb +2619 -0
- noshot/data/AIDS CN NLP/NLP/NLP 5/sample1.txt +15 -0
- noshot/data/AIDS CN NLP/NLP/NLP 5/sample2.txt +4 -0
- noshot/data/AIDS CN NLP/NLP/NLP 5/word2vec_model.bin +0 -0
- noshot/data/AIDS CN NLP/NLP/NLP 6/1. Tokenize, Tagging, NER, Parse Tree.ipynb +312 -0
- noshot/data/AIDS CN NLP/NLP/NLP 6/2. T Test and Chi2 Test.ipynb +185 -0
- noshot/data/AIDS CN NLP/NLP/NLP 6/3. Naive Bayes WSD.ipynb +199 -0
- noshot/data/AIDS CN NLP/NLP/NLP 6/4. Hinddle and Rooth.ipynb +151 -0
- noshot/data/AIDS CN NLP/NLP/NLP 6/5 and 6 FWD, BWD, Viterbi.ipynb +164 -0
- noshot/data/AIDS CN NLP/NLP/NLP 6/7. PCFG using CYK.ipynb +383 -0
- noshot/data/AIDS CN NLP/NLP/NLP 6/8. BOW and TF-IDF.ipynb +252 -0
- noshot/data/AIDS CN NLP/Ubuntu CN Lab.iso +0 -0
- noshot/main.py +47 -0
- noshot-0.1.0.dist-info/LICENSE.txt +21 -0
- noshot-0.1.0.dist-info/METADATA +65 -0
- noshot-0.1.0.dist-info/RECORD +210 -0
- noshot-0.1.0.dist-info/WHEEL +5 -0
- noshot-0.1.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,95 @@
|
|
1
|
+
{
|
2
|
+
"cells": [
|
3
|
+
{
|
4
|
+
"cell_type": "code",
|
5
|
+
"execution_count": null,
|
6
|
+
"id": "b5d46296-1714-4d28-b99b-02403662e645",
|
7
|
+
"metadata": {},
|
8
|
+
"outputs": [],
|
9
|
+
"source": [
|
10
|
+
"from random import randint as rint\n",
|
11
|
+
"n = 8\n",
|
12
|
+
"def show(b):\n",
|
13
|
+
" board = [['_'] * n for _ in range(n)]\n",
|
14
|
+
" for i in range(n):\n",
|
15
|
+
" board[int(b[i])-1][i] = 'Q'\n",
|
16
|
+
" print(f\" {' '.join(['_']*n)}\")\n",
|
17
|
+
" for i in board:\n",
|
18
|
+
" print(f\"|{'|'.join(i)}|\")\n",
|
19
|
+
"def mutate(b1, b2):\n",
|
20
|
+
" b1, b2 = list(b1), list(b2)\n",
|
21
|
+
" x, y = rint(0,n-1), rint(0,n-1)\n",
|
22
|
+
" b1[x], b2[x] = b2[x], b1[x]\n",
|
23
|
+
" b1[y] = str(int(y) + 1)\n",
|
24
|
+
" return (''.join(b1),''.join(b2))\n",
|
25
|
+
"def crossover(b1, b2):\n",
|
26
|
+
" b1, b2 = list(b1), list(b2)\n",
|
27
|
+
" x = rint(1,n-1)\n",
|
28
|
+
" b1[0:x], b2[0:x] = b2[0:x], b1[0:x]\n",
|
29
|
+
" return (''.join(b1), ''.join(b2))\n",
|
30
|
+
"def fitness(b):\n",
|
31
|
+
" b = list(b)\n",
|
32
|
+
" attacks = 0\n",
|
33
|
+
" for i in range(n):\n",
|
34
|
+
" for j in range(i+1, n):\n",
|
35
|
+
" if b[i] == b[j] or abs(int(b[i]) - int(b[j])) == j - i:\n",
|
36
|
+
" attacks += 1\n",
|
37
|
+
" return attacks\n",
|
38
|
+
"def genetic(gen, pop):\n",
|
39
|
+
" global n \n",
|
40
|
+
" n = len(pop[0])\n",
|
41
|
+
" pq = pop\n",
|
42
|
+
" for i in range(1,gen+1):\n",
|
43
|
+
" pq.sort(key = lambda x : fitness(x))\n",
|
44
|
+
" b1 = pq.pop(0)\n",
|
45
|
+
" b2 = pq.pop(0)\n",
|
46
|
+
" pq.clear()\n",
|
47
|
+
" if fitness(b1) == 0:\n",
|
48
|
+
" print(\"Goal State:\",b1,\"Generation:\",i)\n",
|
49
|
+
" show(b1)\n",
|
50
|
+
" return\n",
|
51
|
+
" x1, x2 = crossover(b1, b2)\n",
|
52
|
+
" x3, x4 = crossover(b2, b1)\n",
|
53
|
+
" pq = [x1, x2, x3, x4, *mutate(x1, x2), *mutate(x2, x1), b1, b2]\n",
|
54
|
+
" print(\"Most Evolved State:\",pq[0],\"Generation:\",i,\"Attacks:\",fitness(pq[0]))\n",
|
55
|
+
" show(pq[0])\n",
|
56
|
+
"\n",
|
57
|
+
"def main():\n",
|
58
|
+
" #no of queens is inferred in genetic()\n",
|
59
|
+
" print(\"Genetic Algorithm Example 1(5 Queen): \")\n",
|
60
|
+
" genetic(1000, [\"32152\",\"24345\"])\n",
|
61
|
+
" print()\n",
|
62
|
+
" print(\"Genetic Algorithm Example 2(8 Queen): \")\n",
|
63
|
+
" genetic(1000, [\"57142860\",\"56782463\"])\n",
|
64
|
+
"\n",
|
65
|
+
" #Sample output\n",
|
66
|
+
" #Genetic Algorithm Example 1(5 Queen): \n",
|
67
|
+
" #Most Evolved State: 14352 Generation: 1000 Attacks: 2\n",
|
68
|
+
" #Genetic Algorithm Example 2(8 Queen): \n",
|
69
|
+
" #Goal State: 57142863 Generation: 1\n",
|
70
|
+
"main()"
|
71
|
+
]
|
72
|
+
}
|
73
|
+
],
|
74
|
+
"metadata": {
|
75
|
+
"kernelspec": {
|
76
|
+
"display_name": "Python 3 (ipykernel)",
|
77
|
+
"language": "python",
|
78
|
+
"name": "python3"
|
79
|
+
},
|
80
|
+
"language_info": {
|
81
|
+
"codemirror_mode": {
|
82
|
+
"name": "ipython",
|
83
|
+
"version": 3
|
84
|
+
},
|
85
|
+
"file_extension": ".py",
|
86
|
+
"mimetype": "text/x-python",
|
87
|
+
"name": "python",
|
88
|
+
"nbconvert_exporter": "python",
|
89
|
+
"pygments_lexer": "ipython3",
|
90
|
+
"version": "3.12.4"
|
91
|
+
}
|
92
|
+
},
|
93
|
+
"nbformat": 4,
|
94
|
+
"nbformat_minor": 5
|
95
|
+
}
|
@@ -0,0 +1,74 @@
|
|
1
|
+
{
|
2
|
+
"cells": [
|
3
|
+
{
|
4
|
+
"cell_type": "code",
|
5
|
+
"execution_count": null,
|
6
|
+
"id": "1fbe1abb-5a71-4dce-99dc-efbab49656dd",
|
7
|
+
"metadata": {},
|
8
|
+
"outputs": [],
|
9
|
+
"source": [
|
10
|
+
"import math\n",
|
11
|
+
"import random\n",
|
12
|
+
"def simulated_annealing(initsol, inittemp, alpha, iters):\n",
|
13
|
+
" currsol = initsol\n",
|
14
|
+
" cost = fcost(currsol)\n",
|
15
|
+
" sol = currsol\n",
|
16
|
+
" mincost = cost\n",
|
17
|
+
" temp = inittemp\n",
|
18
|
+
" for iteration in range(iters):\n",
|
19
|
+
" neighbor = successors(currsol)\n",
|
20
|
+
" ncost = fcost(neighbor)\n",
|
21
|
+
" costdiff = ncost - cost\n",
|
22
|
+
" if costdiff < 0 or random.random() < math.exp(-costdiff/temp):\n",
|
23
|
+
" currsol = neighbor\n",
|
24
|
+
" cost = ncost\n",
|
25
|
+
" if cost < mincost:\n",
|
26
|
+
" sol = currsol\n",
|
27
|
+
" mincost = cost\n",
|
28
|
+
" temp *= alpha\n",
|
29
|
+
" return sol, mincost\n",
|
30
|
+
"def fcost(sol):\n",
|
31
|
+
" return sum([i**2 for i in sol])\n",
|
32
|
+
"def successors(sol, step = 1.0):\n",
|
33
|
+
" succ = [x + random.uniform(-step,step) for x in sol]\n",
|
34
|
+
" return succ\n",
|
35
|
+
"\n",
|
36
|
+
"def main():\n",
|
37
|
+
" initsol = [300.0, 400.0]\n",
|
38
|
+
" inittemp = 1000.0\n",
|
39
|
+
" alpha = 0.95\n",
|
40
|
+
" iters = 500\n",
|
41
|
+
" \n",
|
42
|
+
" bestsol, cost = simulated_annealing(initsol, inittemp, alpha, iters)\n",
|
43
|
+
" print(\"Best Solution:\",bestsol)\n",
|
44
|
+
" print(\"Best Cost:\",cost)\n",
|
45
|
+
"\n",
|
46
|
+
" #Sample input/output (can change due to the use of random)\n",
|
47
|
+
" #Best Solution: [225.56303970871514, 294.69364950481685]\n",
|
48
|
+
" #Best Cost: 137723.03194110325\n",
|
49
|
+
"main()"
|
50
|
+
]
|
51
|
+
}
|
52
|
+
],
|
53
|
+
"metadata": {
|
54
|
+
"kernelspec": {
|
55
|
+
"display_name": "Python 3 (ipykernel)",
|
56
|
+
"language": "python",
|
57
|
+
"name": "python3"
|
58
|
+
},
|
59
|
+
"language_info": {
|
60
|
+
"codemirror_mode": {
|
61
|
+
"name": "ipython",
|
62
|
+
"version": 3
|
63
|
+
},
|
64
|
+
"file_extension": ".py",
|
65
|
+
"mimetype": "text/x-python",
|
66
|
+
"name": "python",
|
67
|
+
"nbconvert_exporter": "python",
|
68
|
+
"pygments_lexer": "ipython3",
|
69
|
+
"version": "3.12.4"
|
70
|
+
}
|
71
|
+
},
|
72
|
+
"nbformat": 4,
|
73
|
+
"nbformat_minor": 5
|
74
|
+
}
|
@@ -0,0 +1,103 @@
|
|
1
|
+
{
|
2
|
+
"cells": [
|
3
|
+
{
|
4
|
+
"cell_type": "code",
|
5
|
+
"execution_count": null,
|
6
|
+
"id": "3686dceb-7ecd-40c8-8f9c-eab71bd40f11",
|
7
|
+
"metadata": {
|
8
|
+
"scrolled": true
|
9
|
+
},
|
10
|
+
"outputs": [],
|
11
|
+
"source": [
|
12
|
+
"import math \n",
|
13
|
+
"import random\n",
|
14
|
+
"def display(board):\n",
|
15
|
+
" for row in board:\n",
|
16
|
+
" print(' '.join(str(num) if num != 0 else '.' for num in row))\n",
|
17
|
+
" print()\n",
|
18
|
+
"def fill(board):\n",
|
19
|
+
" for i in range(9):\n",
|
20
|
+
" choices = list(set(range(1,10)) - set(board[i]) - {0})\n",
|
21
|
+
" random.shuffle(choices)\n",
|
22
|
+
" for j in range(9):\n",
|
23
|
+
" if board[i][j] == 0:\n",
|
24
|
+
" board[i][j] = choices.pop()\n",
|
25
|
+
"def cost(board):\n",
|
26
|
+
" conflicts = 0\n",
|
27
|
+
" for n in range(9):\n",
|
28
|
+
" row = board[n]\n",
|
29
|
+
" col = [x[n] for x in board]\n",
|
30
|
+
" conflicts += len(row) - len(set(row))\n",
|
31
|
+
" conflicts += len(col) - len(set(col))\n",
|
32
|
+
" for l in [0,3,6]:\n",
|
33
|
+
" for k in [0,3,6]:\n",
|
34
|
+
" block = []\n",
|
35
|
+
" for i in range(0+l,3+l):\n",
|
36
|
+
" for j in range(0+k,3+k):\n",
|
37
|
+
" block.append(board[i][j])\n",
|
38
|
+
" conflicts += 9 - len(set(block))\n",
|
39
|
+
" return conflicts\n",
|
40
|
+
"def next(board, fixed):\n",
|
41
|
+
" neighbor = [[x for x in row] for row in board]\n",
|
42
|
+
" i = random.randint(0,8)\n",
|
43
|
+
" cols = [j for j in range(9) if (i,j) not in fixed]\n",
|
44
|
+
" if len(cols) >= 2:\n",
|
45
|
+
" j1, j2 = random.sample(cols, 2)\n",
|
46
|
+
" neighbor[i][j1], neighbor[i][j2] = neighbor[i][j2], neighbor[i][j1]\n",
|
47
|
+
" return neighbor\n",
|
48
|
+
"def simulated_annealing(board, initial_temp = 1.0, cooling_rate = 0.99, min_temp = 0.001):\n",
|
49
|
+
" fixed = [(x,y) for x in range(9) for y in range(9) if board[x][y] != 0]\n",
|
50
|
+
" fill(board)\n",
|
51
|
+
" current = best = board\n",
|
52
|
+
" temp = initial_temp\n",
|
53
|
+
" while temp > min_temp:\n",
|
54
|
+
" neighbor = next(current,fixed)\n",
|
55
|
+
" delta = cost(neighbor) - cost(current)\n",
|
56
|
+
" if delta < 0:\n",
|
57
|
+
" current = neighbor\n",
|
58
|
+
" if cost(neighbor) < cost(best):\n",
|
59
|
+
" best = neighbor\n",
|
60
|
+
" else:\n",
|
61
|
+
" if random.random() < math.exp(-delta/temp):\n",
|
62
|
+
" current = neighbor\n",
|
63
|
+
" temp *= cooling_rate\n",
|
64
|
+
" print(f\"Sudoku ({'Best Possible State | Attacks = '+str(cost(best)) if cost(best) else 'Solved'})\") \n",
|
65
|
+
" display(best)\n",
|
66
|
+
"\n",
|
67
|
+
"def main():\n",
|
68
|
+
" board =[[5, 3, 0, 0, 7, 0, 0, 0, 0],\n",
|
69
|
+
" [6, 0, 0, 1, 9, 5, 0, 0, 0],\n",
|
70
|
+
" [0, 9, 8, 0, 0, 0, 0, 6, 0],\n",
|
71
|
+
" [8, 0, 0, 0, 6, 0, 0, 0, 3],\n",
|
72
|
+
" [4, 0, 0, 8, 0, 3, 0, 0, 1],\n",
|
73
|
+
" [7, 0, 0, 0, 2, 0, 0, 0, 6],\n",
|
74
|
+
" [0, 6, 0, 0, 0, 0, 2, 8, 0],\n",
|
75
|
+
" [0, 0, 0, 4, 1, 9, 0, 0, 5],\n",
|
76
|
+
" [0, 0, 0, 0, 8, 0, 0, 7, 9]]\n",
|
77
|
+
" simulated_annealing(board) \n",
|
78
|
+
"main()"
|
79
|
+
]
|
80
|
+
}
|
81
|
+
],
|
82
|
+
"metadata": {
|
83
|
+
"kernelspec": {
|
84
|
+
"display_name": "Python 3 (ipykernel)",
|
85
|
+
"language": "python",
|
86
|
+
"name": "python3"
|
87
|
+
},
|
88
|
+
"language_info": {
|
89
|
+
"codemirror_mode": {
|
90
|
+
"name": "ipython",
|
91
|
+
"version": 3
|
92
|
+
},
|
93
|
+
"file_extension": ".py",
|
94
|
+
"mimetype": "text/x-python",
|
95
|
+
"name": "python",
|
96
|
+
"nbconvert_exporter": "python",
|
97
|
+
"pygments_lexer": "ipython3",
|
98
|
+
"version": "3.12.4"
|
99
|
+
}
|
100
|
+
},
|
101
|
+
"nbformat": 4,
|
102
|
+
"nbformat_minor": 5
|
103
|
+
}
|
@@ -0,0 +1,182 @@
|
|
1
|
+
{
|
2
|
+
"cells": [
|
3
|
+
{
|
4
|
+
"cell_type": "code",
|
5
|
+
"execution_count": null,
|
6
|
+
"id": "1ff278f1-8592-427e-b72a-032f21aa02e5",
|
7
|
+
"metadata": {},
|
8
|
+
"outputs": [],
|
9
|
+
"source": [
|
10
|
+
"import networkx as nx\n",
|
11
|
+
"import matplotlib.pyplot as plt\n",
|
12
|
+
"def show_tree(graph):\n",
|
13
|
+
" graph = {node : [adj for adj in graph[node]] for node in graph}\n",
|
14
|
+
" terminal_nodes = set()\n",
|
15
|
+
" for node in graph:\n",
|
16
|
+
" for i in range(len(graph[node])):\n",
|
17
|
+
" x = str(graph[node][i])\n",
|
18
|
+
" if x.isdigit():\n",
|
19
|
+
" while x in terminal_nodes:\n",
|
20
|
+
" x+=\" \"\n",
|
21
|
+
" graph[node][i] = x\n",
|
22
|
+
" terminal_nodes.add(x)\n",
|
23
|
+
" g = nx.DiGraph(graph)\n",
|
24
|
+
" levels = nx.single_source_shortest_path_length(g, next(iter(g.nodes)))\n",
|
25
|
+
" layers = {}\n",
|
26
|
+
" for node, level in levels.items():\n",
|
27
|
+
" layers[level] = layers.get(level, []) + [node]\n",
|
28
|
+
" pos = {}\n",
|
29
|
+
" for level, nodes in layers.items():\n",
|
30
|
+
" x_offset = (len(nodes) - 1)/2\n",
|
31
|
+
" for i, node in enumerate(nodes):\n",
|
32
|
+
" x = i - x_offset\n",
|
33
|
+
" y = -level\n",
|
34
|
+
" pos[node] = (x,y)\n",
|
35
|
+
" plt.figure(figsize = (8,4))\n",
|
36
|
+
" nx.draw(g, pos, with_labels = True, \n",
|
37
|
+
" node_size = 600, node_color = 'lightgreen',\n",
|
38
|
+
" font_size = 12, font_family = 'cursive',\n",
|
39
|
+
" arrows = False, width = 1.5, edge_color = 'red',\n",
|
40
|
+
" edgecolors = 'black', linewidths = 1.5,\n",
|
41
|
+
" margins = 0.1, clip_on = False)\n",
|
42
|
+
" plt.suptitle(\"Alpha Beta Pruning\")\n",
|
43
|
+
" plt.show()\n",
|
44
|
+
" plt.clf()\n",
|
45
|
+
"MIN = -float('inf')\n",
|
46
|
+
"MAX = float('inf')\n",
|
47
|
+
"def alphabeta(node, graph, ismax, pruned = [], alpha = MIN, beta = MAX, path = {}):\n",
|
48
|
+
" if str(node).isdigit():\n",
|
49
|
+
" return int(node), pruned, path\n",
|
50
|
+
" option = MIN if ismax else MAX\n",
|
51
|
+
" for child in graph[node]:\n",
|
52
|
+
" val, _, _ = alphabeta(child, graph, not ismax, pruned, alpha, beta, path)\n",
|
53
|
+
" if ismax:\n",
|
54
|
+
" option = max(option, val)\n",
|
55
|
+
" alpha = max(option, alpha)\n",
|
56
|
+
" path[node] = alpha\n",
|
57
|
+
" else:\n",
|
58
|
+
" option = min(option, val)\n",
|
59
|
+
" beta = min(option, beta)\n",
|
60
|
+
" path[node] = beta\n",
|
61
|
+
" if alpha >= beta:\n",
|
62
|
+
" i = graph[node].index(child)+1\n",
|
63
|
+
" pruned += [f\"{node}-{adj}\" for adj in graph[node][i:]]\n",
|
64
|
+
" break\n",
|
65
|
+
" return option, pruned, path\n",
|
66
|
+
"def show_path(node, graph, path, value):\n",
|
67
|
+
" for adj in graph[node]:\n",
|
68
|
+
" if str(adj).isdigit():\n",
|
69
|
+
" return [node,str(value)]\n",
|
70
|
+
" if path[adj] == value:\n",
|
71
|
+
" return [node] + show_path(adj, graph, path, value)\n",
|
72
|
+
"def get_graph():\n",
|
73
|
+
" graph = {}\n",
|
74
|
+
" print(\"Enter edge (u, v)\")\n",
|
75
|
+
" print(\"[PRESS ENTER TO STOP]\")\n",
|
76
|
+
" x = input()\n",
|
77
|
+
" while x:\n",
|
78
|
+
" x = x.split(maxsplit = 1)\n",
|
79
|
+
" u, adj = x[0], [v.strip() for v in x[1].strip(' []').split(',') if v]\n",
|
80
|
+
" graph[u] = graph.get(u,[]) + adj\n",
|
81
|
+
" x = input()\n",
|
82
|
+
" return graph\n",
|
83
|
+
"def example():\n",
|
84
|
+
" graph = {\n",
|
85
|
+
" 'A' : ['B', 'C'],\n",
|
86
|
+
" 'B' : ['D', 'E'],\n",
|
87
|
+
" 'C' : ['F', 'G'],\n",
|
88
|
+
" 'D' : ['H', 'I'],\n",
|
89
|
+
" 'E' : [10, 5],\n",
|
90
|
+
" 'F' : ['J', 'K'],\n",
|
91
|
+
" 'G' : ['L', 'M'],\n",
|
92
|
+
" 'H' : [11, 12],\n",
|
93
|
+
" 'I' : [8, 9],\n",
|
94
|
+
" 'J' : [8, 5],\n",
|
95
|
+
" 'K' : [12, 11],\n",
|
96
|
+
" 'L' : [12, 9],\n",
|
97
|
+
" 'M' : [8, 7]}\n",
|
98
|
+
"\n",
|
99
|
+
" show_tree(graph)\n",
|
100
|
+
" print(graph)\n",
|
101
|
+
" start = 'A'\n",
|
102
|
+
" \n",
|
103
|
+
" val, pruned, path = alphabeta(start, graph, True)#True means first node is max\n",
|
104
|
+
" path = show_path(start, graph, path, val)\n",
|
105
|
+
" print(\"Alpha Beta Pruning(Maximize):\", val, \" Pruned Branches:\", (', '.join(pruned) if pruned else None), \" Path:\",'->'.join(path))\n",
|
106
|
+
" \n",
|
107
|
+
" val, pruned, path = alphabeta(start, graph, False)#False means first node is min\n",
|
108
|
+
" path = show_path(start, graph, path, val)\n",
|
109
|
+
" print(\"Alpha Beta Pruning(Minimize):\", val, \" Pruned Branches:\", (', '.join(pruned) if pruned else None), \" Path:\",'->'.join(path))\n",
|
110
|
+
"\n",
|
111
|
+
"def main():\n",
|
112
|
+
" #example();return #change the example according to question\n",
|
113
|
+
" graph = get_graph()\n",
|
114
|
+
" start = input(\"Enter start node: \")\n",
|
115
|
+
" show_tree(graph)\n",
|
116
|
+
" print(graph)\n",
|
117
|
+
" val, pruned, path = alphabeta(start, graph, True)#True means first node is max\n",
|
118
|
+
" path = show_path(start, graph, path, val)\n",
|
119
|
+
" print(\"Alpha Beta Pruning(Maximize):\", val, \" Pruned Branches:\", (', '.join(pruned) if pruned else None), \" Path:\",'->'.join(path))\n",
|
120
|
+
" \n",
|
121
|
+
" val, pruned, path = alphabeta(start, graph, False)#False means first node is min\n",
|
122
|
+
" path = show_path(start, graph, path, val)\n",
|
123
|
+
" print(\"Alpha Beta Pruning(Minimize):\", val, \" Pruned Branches:\", (', '.join(pruned) if pruned else None), \" Path:\",'->'.join(path))\n",
|
124
|
+
" #Sample output\n",
|
125
|
+
" #Enter edge (u, v)\n",
|
126
|
+
" #[PRESS ENTER TO STOP]\n",
|
127
|
+
" #A B\n",
|
128
|
+
" #A C\n",
|
129
|
+
" #B D\n",
|
130
|
+
" #B E\n",
|
131
|
+
" #C F\n",
|
132
|
+
" #C G\n",
|
133
|
+
" #D H\n",
|
134
|
+
" #D I\n",
|
135
|
+
" #E 10\n",
|
136
|
+
" #E 5\n",
|
137
|
+
" #F J\n",
|
138
|
+
" #F K\n",
|
139
|
+
" #G L\n",
|
140
|
+
" #G M\n",
|
141
|
+
" #H 11\n",
|
142
|
+
" #H 12\n",
|
143
|
+
" #I 8\n",
|
144
|
+
" #I 9\n",
|
145
|
+
" #J 8\n",
|
146
|
+
" #J 5\n",
|
147
|
+
" #K 12\n",
|
148
|
+
" #K 11\n",
|
149
|
+
" #L 12\n",
|
150
|
+
" #L 9\n",
|
151
|
+
" #M 8\n",
|
152
|
+
" #M 7\n",
|
153
|
+
"\n",
|
154
|
+
" #Alpha Beta Pruning(Maximize): 10 Pruned Branches: I-9, J-5, M-7 Path: A->B->E->10\n",
|
155
|
+
" #Alpha Beta Pruning(Minimize): 8 Pruned Branches: I-9, J-5, M-7, K-11, L-9 Path: A->C->F->J->8\n",
|
156
|
+
"\n",
|
157
|
+
"main()"
|
158
|
+
]
|
159
|
+
}
|
160
|
+
],
|
161
|
+
"metadata": {
|
162
|
+
"kernelspec": {
|
163
|
+
"display_name": "Python 3 (ipykernel)",
|
164
|
+
"language": "python",
|
165
|
+
"name": "python3"
|
166
|
+
},
|
167
|
+
"language_info": {
|
168
|
+
"codemirror_mode": {
|
169
|
+
"name": "ipython",
|
170
|
+
"version": 3
|
171
|
+
},
|
172
|
+
"file_extension": ".py",
|
173
|
+
"mimetype": "text/x-python",
|
174
|
+
"name": "python",
|
175
|
+
"nbconvert_exporter": "python",
|
176
|
+
"pygments_lexer": "ipython3",
|
177
|
+
"version": "3.12.4"
|
178
|
+
}
|
179
|
+
},
|
180
|
+
"nbformat": 4,
|
181
|
+
"nbformat_minor": 5
|
182
|
+
}
|
noshot/data/AIDS CN NLP/AIDS/6. Consraint Satisfaction Problems (CSP)/(A) CSP House Allocation.ipynb
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
{
|
2
|
+
"cells": [
|
3
|
+
{
|
4
|
+
"cell_type": "code",
|
5
|
+
"execution_count": null,
|
6
|
+
"id": "5136c471-9d1d-4b2b-8f6b-e584ea42a133",
|
7
|
+
"metadata": {},
|
8
|
+
"outputs": [],
|
9
|
+
"source": [
|
10
|
+
"import networkx as nx\n",
|
11
|
+
"import matplotlib.pyplot as plt\n",
|
12
|
+
"def check(assign, loc):\n",
|
13
|
+
" #constraints given in the question\n",
|
14
|
+
" #change it accordinly\n",
|
15
|
+
"\n",
|
16
|
+
" a = assign['A']\n",
|
17
|
+
" b = assign['B']\n",
|
18
|
+
" c = assign['C']\n",
|
19
|
+
" d = assign['D']\n",
|
20
|
+
" \n",
|
21
|
+
" #1. C lives in a house higher than D\n",
|
22
|
+
" if c != -1 and d != -1 and c < d:return False\n",
|
23
|
+
"\n",
|
24
|
+
" #2. D lives next to A in Lower number House\n",
|
25
|
+
" if d != -1 and a != -1 and (a - d) != 1:return False\n",
|
26
|
+
"\n",
|
27
|
+
" #3. There is at least one house between D and B \n",
|
28
|
+
" if d != -1 and b != -1 and abs(d - b) == 1:return False\n",
|
29
|
+
"\n",
|
30
|
+
" #4. C doesn't live in house number 3\n",
|
31
|
+
" if c != -1 and c == 3:return False\n",
|
32
|
+
"\n",
|
33
|
+
" #5. B doesn't live in house number 1\n",
|
34
|
+
" if b != -1 and b == 1:return False\n",
|
35
|
+
" \n",
|
36
|
+
" if loc in assign.values():\n",
|
37
|
+
" return False\n",
|
38
|
+
" return True\n",
|
39
|
+
"def backtrack(houses, locs):\n",
|
40
|
+
" assign = {house : -1 for house in houses} \n",
|
41
|
+
" return rec_backtrack(assign, locs)\n",
|
42
|
+
"def rec_backtrack(assign, locs):\n",
|
43
|
+
" if check(assign, -1):\n",
|
44
|
+
" return assign\n",
|
45
|
+
" choices = [x for x in assign if assign[x] == -1]\n",
|
46
|
+
" house = choices[0] if choices else None\n",
|
47
|
+
" for loc in locs:\n",
|
48
|
+
" if check(assign, loc):\n",
|
49
|
+
" assign[house] = loc\n",
|
50
|
+
" res = rec_backtrack(assign, locs)\n",
|
51
|
+
" if res:\n",
|
52
|
+
" return res\n",
|
53
|
+
" assign[house] = -1\n",
|
54
|
+
" return None\n",
|
55
|
+
"def display_house(result):\n",
|
56
|
+
" g = nx.Graph()\n",
|
57
|
+
" nodes = list(result.keys())\n",
|
58
|
+
" nodes.sort(key = lambda x : result[x])\n",
|
59
|
+
" nodes = [f\"{node}({result[node]})\" for node in nodes]\n",
|
60
|
+
" for u, v in zip(nodes, nodes[1:]):\n",
|
61
|
+
" g.add_edge(u, v)\n",
|
62
|
+
" pos = {node : (0, i) for i, node in enumerate(nodes)}\n",
|
63
|
+
" nx.draw(g, pos, with_labels = True,\n",
|
64
|
+
" width = 1.5, edge_color = 'red',\n",
|
65
|
+
" node_size = 800, node_color = 'lightgreen',\n",
|
66
|
+
" font_size = 12, font_family = 'cursive',\n",
|
67
|
+
" edgecolors = 'black', linewidths = 1.5,\n",
|
68
|
+
" margins = 0.2, clip_on = False)\n",
|
69
|
+
" plt.suptitle(\"House Allocation(Constraint Satisfaction Problem)\")\n",
|
70
|
+
" plt.show()\n",
|
71
|
+
" plt.clf()\n",
|
72
|
+
"\n",
|
73
|
+
"def main():\n",
|
74
|
+
" #Info: \"There are 4 family namely A, B, C, D there are 4 houses namely 1,2,3,4\"\n",
|
75
|
+
" #1. C lives in a house higher than D\n",
|
76
|
+
" #2. D lives next to A in Lower number House\n",
|
77
|
+
" #3. There is at least one house between D and B\n",
|
78
|
+
" #4. C doesn't live in house number 3\n",
|
79
|
+
" #5. B doesn't live in house number 1\n",
|
80
|
+
" locs = [1,2,3,4]\n",
|
81
|
+
" houses = ['A','B','C','D']\n",
|
82
|
+
" sol = backtrack(houses, locs)\n",
|
83
|
+
" if sol:\n",
|
84
|
+
" display_house(sol)\n",
|
85
|
+
" for node in sol:\n",
|
86
|
+
" print(\"House:\",node,\" Location:\",sol[node])\n",
|
87
|
+
" else:\n",
|
88
|
+
" print(\"No Solution Exists\")\n",
|
89
|
+
"\n",
|
90
|
+
" #Sample Input/Output\n",
|
91
|
+
" #House: A Location: 2\n",
|
92
|
+
" #House: B Location: 3\n",
|
93
|
+
" #House: C Location: 4\n",
|
94
|
+
" #House: D Location: 1\n",
|
95
|
+
"main()"
|
96
|
+
]
|
97
|
+
}
|
98
|
+
],
|
99
|
+
"metadata": {
|
100
|
+
"kernelspec": {
|
101
|
+
"display_name": "Python 3 (ipykernel)",
|
102
|
+
"language": "python",
|
103
|
+
"name": "python3"
|
104
|
+
},
|
105
|
+
"language_info": {
|
106
|
+
"codemirror_mode": {
|
107
|
+
"name": "ipython",
|
108
|
+
"version": 3
|
109
|
+
},
|
110
|
+
"file_extension": ".py",
|
111
|
+
"mimetype": "text/x-python",
|
112
|
+
"name": "python",
|
113
|
+
"nbconvert_exporter": "python",
|
114
|
+
"pygments_lexer": "ipython3",
|
115
|
+
"version": "3.12.4"
|
116
|
+
}
|
117
|
+
},
|
118
|
+
"nbformat": 4,
|
119
|
+
"nbformat_minor": 5
|
120
|
+
}
|