@@ -68,6 +68,11 @@ Use verify [file] to test your solution and see how it does. When you are finish
6868
6969#Solution
7070
71+ ###Primary Resources
72+ - https://algs4.cs.princeton.edu/44sp
73+ - https://www.cs.princeton.edu/~wayne/kleinberg-tardos/pdf/06DynamicProgrammingII.pdf
74+
75+
7176##First Analysis
7277
7378###Provided Case 1: Time Added Back
@@ -622,7 +627,11 @@ time each time one is added.
622627[ 8, 2, 2, 0, 0] ,
623628[ 8, 2, 1, 1, 0]] ,
624629
625- - [ ] Need to check with this theory.
630+ - [X] Need to check with this theory.
631+ This theory also does not work as from theory -
632+ https://algs4.cs.princeton.edu/44sp/
633+ https://www.cs.princeton.edu/~wayne/kleinberg-tardos/pdf/06DynamicProgrammingII.pdf :
634+ ` Reweighting. Adding a constant to every edge length does not necessarily make Dijkstra’s algorithm produce shortest paths. `
626635
627636
628637####More Theory
@@ -643,15 +652,6 @@ Summary:
643652→ Johnson’s Algorithm
644653
645654
646- Updated Algorithm
647- 2 . Check if the time we have would be enough save a bunny that requires the same amount of time.
648- 3 . If No, Check if there is a way to increase/add more time to save a bunny.
649- 4 . 3 . If Yes, add time, and save the bunny.
650- 5 . 3 . If No, return the number of bunnies saved.
651- 6 . If Yes, Check if by saving that bunny we would still have more time to keep the Bulkhead.
652-
653-
654-
655655https://medium.com/cantors-paradise/dijkstras-shortest-path-algorithm-in-python-d955744c7064
656656http://theory.stanford.edu/~amitp/GameProgramming/
657657https://www.geeksforgeeks.org/a-search-algorithm
@@ -843,8 +843,8 @@ def BellmanFord(edges, source, time, N, last):
843843
844844```
845845
846- Then the next idea was to use all the computed paths by
847- completed Bellman-Ford.
846+ Then the next idea was to use all the computed
847+ paths by completed Bellman-Ford.
848848
849849``` python
850850
@@ -871,6 +871,119 @@ So I choose to use existing solution for submission.
871871I choose Python as the programming language as the solutions and examples
872872were better and more, and I use it as tooling language to validate ideas.
873873
874+ ###Further analysis after submission
875+ The submitted solution was third-party and I wanted to find better
876+ optimium solution.
877+
878+ #####First Example:
879+ ``` python
880+ adjacencyMatrix= [
881+ [0 ,2 ,2 ,2 ,- 1 ],# 0 = Start
882+ [9 ,0 ,2 ,2 ,- 1 ],# 1 = Bunny 0
883+ [9 ,3 ,0 ,2 ,- 1 ],# 2 = Bunny 1
884+ [9 ,3 ,2 ,0 ,- 1 ],# 3 = Bunny 2
885+ [9 ,3 ,2 ,2 ,0 ],# 4 = Bulkhead
886+ ]
887+ time= 1
888+ ```
889+
890+ The shortest paths are from 0, 1, 2 and 3 are:
891+ [ 0, 2, 1, 1, -1] ,[ 8, 0, 1, 1, -1] ,[ 8, 2, 0, 1, -1] ,[ 8, 2, 1, 0, -1]
892+
893+ Rough algorithm could be:
894+
895+ Find the miminum value.
896+ If there are more than one, put them in a queue, i.e. Here there is two 1's,
897+ Select the minimum value.
898+ Reduce the total time provided.
899+
900+ Move to next stage who's minimum value was selected.
901+ Select the next minimum value excluding the previous stage.
902+
903+ Check if the available time is enough to reach next stage.
904+ The remaining time must be greater than or equal to shortest time it takes to reach next level.
905+
906+ Steps taken based on the algorithm based on the shortest path:
907+
908+ Previous vertices pv = null
909+ Remaining time rt = 2
910+
911+ Step 1[ 0, 2, 1, 1, -1]
912+ Remove first and last index from the list, say AL, =[ 2, 1, 1]
913+ Sort =[ 1,1,2]
914+ Add sorted list to queue
915+ Dequeue: Choose the first number from the sorted list
916+ The next path np = Select the first index in AL = 2
917+ rt = 2 - 1 = 1
918+ Is rt - np > 0, go to next step.
919+
920+
921+ Step 2[ 8, 2, 0, 1, -1]
922+ Previous vertices:0
923+ Remove first, last index, self, and previous vertices index AL =[ 2, 1]
924+ This filtration might cause issue while selecting as the index are removed
925+ But we need it for sorting
926+ Sort =[ 1, 2]
927+ Add sorted list to queue
928+ Choose the first number from the sorted list
929+ The next path = Select the index in the shortest path whose value is dequeued
930+ [ x, x, x, 1, x] = 3, the only option remaining
931+ Probable problem:
932+ rt = 1 - 1 = 0
933+ Is rt - np > 0, go to next step. No
934+
935+
936+ #####Second Example:
937+ Adjacency Matrix =[[ 0, 1, 1, 1, 1] ,[ 1, 0, 1, 1, 1] ,[ 1, 1, 0, 1, 1] ,[ 1, 1, 1, 0, 1] ,[ 1, 1, 1, 1, 0]]
938+ Time = 3
939+ Shortest Path sp =[[ 0, 1, 1, 1, 1] ,[ 1, 0, 1, 1, 1] ,[ 1, 1, 0, 1, 1] ,[ 1, 1, 1, 0, 1]]
940+
941+
942+ Previous vertices pv = null
943+ Remaining time rt = 3
944+ list = sp[ 0] =[ 0, 1, 1, 1, 1]
945+
946+ while i > 0:
947+
948+ Step 1[ 0, 1, 1, 1, 1]
949+ pv = null
950+ Remove first and last index from the list, say AL, =[ 1, 1, 1]
951+ Sort =[ 1,1,1]
952+ Add sorted list to queue
953+ Dequeue: Choose the first number from the sorted list = 1
954+ Choose the first index whose value is 1.
955+ nextIndex = sp[ 1]
956+ rt = 3 - 1 = 2
957+ Is rt - np > 0,
958+ Go to next step: nextIndex
959+
960+
961+ Step 2[ 1, 0, 1, 1, 1]
962+ pv = 0
963+ Remove first and last index from the list, say AL, =[ 1, 1, 1]
964+ Sort =[ 1,1,1]
965+ Add sorted list to queue
966+ Dequeue: Choose the first number from the sorted list = 1
967+ Choose the first index whose value is 1
968+ nextIndex = sp[ 1]
969+ rt = 2 - 1 = 1
970+ Is rt - np > 0,
971+ Go to next step: nextIndex
972+
973+ Step 3[ 1, 1, 0, 1, 1]
974+ pv = 1
975+ Remove first, last and previous index from the list, say AL, =[ 1]
976+ Sort =[ 1] // No need to sort if there's one one item
977+ Add sorted list to queue // No need
978+ Dequeue: Choose the first number from the sorted list = 1
979+ Choose the first index whose value is 1
980+ nextIndex = sp[ 1]
981+ rt = 2 - 1 = 1
982+ Is rt - np > 0,
983+ Go to next step: nextIndex
984+
985+
986+
874987
875988######Tabs On Brower
876989- [ ] https://www.hackerearth.com/practice/algorithms/graphs/shortest-path-algorithms/tutorial/