From 47d42678de14f0420242e717ec81b822999c171d Mon Sep 17 00:00:00 2001 From: Dheeraj Bisht Date: Tue, 21 Mar 2023 03:13:03 +0530 Subject: [PATCH] init --- .eslintignore | 13 + .eslintrc.cjs | 20 + .gitignore | 10 + .npmrc | 1 + .prettierignore | 13 + .prettierrc | 9 + README.md | 22 + package.json | 31 + src/app.d.ts | 12 + src/app.html | 12 + src/routes/+page.svelte | 1 + static/docs/A star/Readme.md | 47 + static/docs/Data Compression/Readme.md | 21 + static/docs/Fractals/Readme.md | 9 + static/docs/Game of Life/Readme.md | 3 + .../Readme.md | 21 + static/docs/Maze World/Readme.md | 520 ++++++ static/docs/Random Walk/Readme.md | 26 + static/favicon.png | Bin 0 -> 1571 bytes svelte.config.js | 18 + tsconfig.json | 17 + vite.config.ts | 6 + yarn.lock | 1510 +++++++++++++++++ 23 files changed, 2342 insertions(+) create mode 100644 .eslintignore create mode 100644 .eslintrc.cjs create mode 100644 .gitignore create mode 100644 .npmrc create mode 100644 .prettierignore create mode 100644 .prettierrc create mode 100644 README.md create mode 100644 package.json create mode 100644 src/app.d.ts create mode 100644 src/app.html create mode 100644 src/routes/+page.svelte create mode 100644 static/docs/A star/Readme.md create mode 100644 static/docs/Data Compression/Readme.md create mode 100644 static/docs/Fractals/Readme.md create mode 100644 static/docs/Game of Life/Readme.md create mode 100644 static/docs/Locating Points on Sphere and Satellite Navigation System/Readme.md create mode 100644 static/docs/Maze World/Readme.md create mode 100644 static/docs/Random Walk/Readme.md create mode 100644 static/favicon.png create mode 100644 svelte.config.js create mode 100644 tsconfig.json create mode 100644 vite.config.ts create mode 100644 yarn.lock diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..3897265 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,13 @@ +.DS_Store +node_modules +/build +/.svelte-kit +/package +.env +.env.* +!.env.example + +# Ignore files for PNPM, NPM and YARN +pnpm-lock.yaml +package-lock.json +yarn.lock diff --git a/.eslintrc.cjs b/.eslintrc.cjs new file mode 100644 index 0000000..3ccf435 --- /dev/null +++ b/.eslintrc.cjs @@ -0,0 +1,20 @@ +module.exports = { + root: true, + parser: '@typescript-eslint/parser', + extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended', 'prettier'], + plugins: ['svelte3', '@typescript-eslint'], + ignorePatterns: ['*.cjs'], + overrides: [{ files: ['*.svelte'], processor: 'svelte3/svelte3' }], + settings: { + 'svelte3/typescript': () => require('typescript') + }, + parserOptions: { + sourceType: 'module', + ecmaVersion: 2020 + }, + env: { + browser: true, + es2017: true, + node: true + } +}; diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6635cf5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +.DS_Store +node_modules +/build +/.svelte-kit +/package +.env +.env.* +!.env.example +vite.config.js.timestamp-* +vite.config.ts.timestamp-* diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..b6f27f1 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +engine-strict=true diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..3897265 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,13 @@ +.DS_Store +node_modules +/build +/.svelte-kit +/package +.env +.env.* +!.env.example + +# Ignore files for PNPM, NPM and YARN +pnpm-lock.yaml +package-lock.json +yarn.lock diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..a77fdde --- /dev/null +++ b/.prettierrc @@ -0,0 +1,9 @@ +{ + "useTabs": true, + "singleQuote": true, + "trailingComma": "none", + "printWidth": 100, + "plugins": ["prettier-plugin-svelte"], + "pluginSearchDirs": ["."], + "overrides": [{ "files": "*.svelte", "options": { "parser": "svelte" } }] +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..5d3151b --- /dev/null +++ b/README.md @@ -0,0 +1,22 @@ +# Introduction + +This repo contains the visualizations of some algorithms, physics and stuffs i like ;P. + +# Table of contents + +| S/No. | Name | +| ----- | ------------------------------------------------------------- | +| 1. | [Solar System Simulation]() | +| 2. | [A\* Path Visualization]() | +| 3. | [Djikstra's Shortest Path Finding Visualization]() | +| 4. | [Fractals]() | +| 5. | [Random Number Generation]() | +| 6. | [Boid Algorithm]() | +| 7. | [Fourier Transform]() | +| 8. | [Locating Points on Sphere and Satellite Navigation System]() | +| 9. | [Chaos Theory & Logistic Map ]() | +| 10. | [OODA Loop]() | +| 11. | [Data Compression]() | +| 12. | [Game of Life]() | +| 13. | [Maze World]() | +| 14. | [Random Walk]() | diff --git a/package.json b/package.json new file mode 100644 index 0000000..430e590 --- /dev/null +++ b/package.json @@ -0,0 +1,31 @@ +{ + "name": "simulations-and-visuals", + "version": "0.0.1", + "private": true, + "scripts": { + "dev": "vite dev", + "build": "vite build", + "preview": "vite preview", + "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json", + "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch", + "lint": "prettier --plugin-search-dir . --check . && eslint .", + "format": "prettier --plugin-search-dir . --write ." + }, + "devDependencies": { + "@sveltejs/adapter-auto": "^2.0.0", + "@sveltejs/kit": "^1.5.0", + "@typescript-eslint/eslint-plugin": "^5.45.0", + "@typescript-eslint/parser": "^5.45.0", + "eslint": "^8.28.0", + "eslint-config-prettier": "^8.5.0", + "eslint-plugin-svelte3": "^4.0.0", + "prettier": "^2.8.0", + "prettier-plugin-svelte": "^2.8.1", + "svelte": "^3.54.0", + "svelte-check": "^3.0.1", + "tslib": "^2.4.1", + "typescript": "^5.0.0", + "vite": "^4.2.0" + }, + "type": "module" +} diff --git a/src/app.d.ts b/src/app.d.ts new file mode 100644 index 0000000..f59b884 --- /dev/null +++ b/src/app.d.ts @@ -0,0 +1,12 @@ +// See https://kit.svelte.dev/docs/types#app +// for information about these interfaces +declare global { + namespace App { + // interface Error {} + // interface Locals {} + // interface PageData {} + // interface Platform {} + } +} + +export {}; diff --git a/src/app.html b/src/app.html new file mode 100644 index 0000000..effe0d0 --- /dev/null +++ b/src/app.html @@ -0,0 +1,12 @@ + + + + + + + %sveltekit.head% + + +
%sveltekit.body%
+ + diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte new file mode 100644 index 0000000..ee0e095 --- /dev/null +++ b/src/routes/+page.svelte @@ -0,0 +1 @@ +

Visualizations and Simulations

diff --git a/static/docs/A star/Readme.md b/static/docs/A star/Readme.md new file mode 100644 index 0000000..a92dc5e --- /dev/null +++ b/static/docs/A star/Readme.md @@ -0,0 +1,47 @@ +# Introduction + +It is a searching algorithm that is used to find the shortest path between an initial and a final point. + +A\* was initially designed as a graph traversal problem, to help build a robot that can find its own course. It still remains a widely popular algorithm for graph traversal. + +It is an extension of Dijkstra’s shortest path algorithm (Dijkstra’s Algorithm). The extension here is that, instead of using a priority queue to store all the elements, we use heaps (binary trees) to store them. + +The A\* Search Algorithm also uses a heuristic function that provides additional information regarding how far away from the goal node we are. This function is used in conjunction with the f-heap (Fibonacci heap) data structure in order to make searching more efficient. + +It searches for shorter paths first, thus making it an optimal and complete algorithm. + +- An optimal algorithm will find the least cost outcome for a problem. +- A complete algorithm finds all the possible outcomes of a problem. + +# Working + +Initially, the Algorithm calculates the cost to all its immediate neighboring nodes,n, and chooses the one incurring the least cost. This process repeats until no new nodes can be chosen and all paths have been traversed. Then, you should consider the best path among them. If f(n) represents the final cost, then it can be denoted as : + +f(n) = g(n) + h(n), where : + +g(n) = cost of traversing from one node to another. This will vary from node to node + +h(n) = heuristic approximation of the node's value. This is not a real value but an approximation cost + +Calculating g is not a big deal but to calculate h we can: + +1. Calculate the exact value of h (which is certainly time consuming). +1. Approximate the value of h using some heuristics (less time consuming). + - Manhattan Distance + - Diagonal Distance + - Euclidean Distance + +We can also think of Dijkstra as a special case of A\* Search Algorithm, where h = 0 for all nodes. + +# Complexity Analysis + +TIME COMPLEXITY: O(E), where E is the number of edges in the graph +SPACE COMPLEXITY: O(V), where V is the total number of vertices. + +# Limitations + +A major drawback of the algorithm is its space and time complexity. It takes a large amount of space to store all possible paths and a lot of time to find them. + +Although being the best path finding algorithm around, A\* Search Algorithm doesn’t produce the shortest path always, as it relies heavily on heuristics / approximations to calculate – h + +A heuristic algorithm sacrifices optimality, with precision and accuracy for speed, to solve problems faster and more efficiently. diff --git a/static/docs/Data Compression/Readme.md b/static/docs/Data Compression/Readme.md new file mode 100644 index 0000000..7b0eba3 --- /dev/null +++ b/static/docs/Data Compression/Readme.md @@ -0,0 +1,21 @@ +# Introduction + +In information theory, data compression, source coding, or bit-rate reduction is the process of encoding information using fewer bits than the original representation. + +Any particular compression is either lossy or lossless. + +- Lossless compression reduces bits by identifying and eliminating statistical redundancy. + + - No information is lost in lossless compression. + - PNG images use lossless compression. + +- Lossy compression reduces bits by removing unnecessary or less important information. + + - JPEG images can and often do use lossy compression. + +A device that performs data compression is referred to as an **encoder**, and one that performs the reversal of the process (decompression) as a **decoder**. + +Compressed files usually end with .zip, .sit and .tar. These are called extensions, and they indicate different compression formats--different types of software used to compress files. + +- For PCs, .zip is most common, .sit is used often with Macs and .tar used with Linux. When you see a file with one of these extensions, it may be either a single large file or a group of files bundled together. +- Files ending in .sea or .exe are called **self-extracting files**. These are compressed files that do not require any special software to decompress. diff --git a/static/docs/Fractals/Readme.md b/static/docs/Fractals/Readme.md new file mode 100644 index 0000000..cbedafe --- /dev/null +++ b/static/docs/Fractals/Readme.md @@ -0,0 +1,9 @@ +# Introduction + +- Self Similarity +- Fine Shape at small scale +- Reccursive Defination + +# Koch Curve + +# Stocastic Fractals diff --git a/static/docs/Game of Life/Readme.md b/static/docs/Game of Life/Readme.md new file mode 100644 index 0000000..ee4da78 --- /dev/null +++ b/static/docs/Game of Life/Readme.md @@ -0,0 +1,3 @@ +# Introduction + +# Cellular Automaton diff --git a/static/docs/Locating Points on Sphere and Satellite Navigation System/Readme.md b/static/docs/Locating Points on Sphere and Satellite Navigation System/Readme.md new file mode 100644 index 0000000..23217b6 --- /dev/null +++ b/static/docs/Locating Points on Sphere and Satellite Navigation System/Readme.md @@ -0,0 +1,21 @@ +## Different types of Navigation systems + +Automotive navigation system + +Marine navigation systems using sonar + +Satellite navigation system + +- Global Positioning System, a group of satellites and computers that can provide information on any person, vessel, or vehicle's location via a GPS receiver + - GPS navigation device, a device that can receive GPS signals for the purpose of determining the device's location and possibly to suggest or give directions +- GLONASS, satellite navigation system run by Russia +- Galileo global navigation satellite system +- IRNSS, regional satellite system run by India. + +Surgical navigation system, a system that determines the position of surgical instruments in relation to patient images such as CT or MRI scans. + +Inertial guidance system, a system which continuously determines the position, orientation, and velocity (direction and speed of movement) of a moving object without the need for external reference + +Robotic mapping, the methods and equipment by which an autonomous robot is able to construct (or use) a map or floor plan and to localize itself within it + +XNAV for deep space navigation diff --git a/static/docs/Maze World/Readme.md b/static/docs/Maze World/Readme.md new file mode 100644 index 0000000..8f5106e --- /dev/null +++ b/static/docs/Maze World/Readme.md @@ -0,0 +1,520 @@ +# Introduction + +## Some Vocabulary + +**cell**: an open passage in the maze +**grid**: the grid is the combination of all passages and barriers in the maze +**perfect maze**: a maze is perfect if it has one and only one solution +**wall**: an impassable barrier in the maze + +# Maze-Generating Algorithms + +## Aldous-Broder + +[![Click to see Aldous Broder in Action](images/aldous_broder_7x7.png?raw=true) +_Click to see Aldous Broder in Action_](images/aldous_broder_7x7.gif?raw=true) + +###### The Algorithm + +1. Choose a random cell. +2. Choose a random neighbor of the current cell and visit it. If the neighbor has not yet been visited, add the traveled edge to the spanning tree. +3. Repeat step 2 until all cells have been visited. + +###### Results + +perfect, unbiased + +###### Notes + +This algorithm treats the cells of a maze as a graph, and solves to find a Uniform Spanning Tree that covers that graph. Like most tree-based maze algorithms, this one is a little slow. + +## Backtracking Generator + +[![Click to see the Backtracking Generator in Action](images/backtracking_7x7.png?raw=true) +_Click to see the Backtracking Generator in Action_](images/backtracking_7x7.gif?raw=true) + +###### The Algorithm + +1. Randomly choose a starting cell. +2. Randomly choose a wall at the current cell and open a passage through it to any random, unvisited, adjacent cell. This is now the current cell. +3. If all adjacent cells have been visited, back up to the previous and repeat step 2. +4. Stop when the algorithm has backed all the way up to the starting cell. + +###### Results + +perfect + +###### Notes + +This is perhaps the most common maze-generation algorithm because it is easy to understand and implement. And it produces high-quality mazes. + +## Binary Tree + +[![Click to see the Binary Tree in Action](images/binary_tree_7x7.png?raw=true) +_Click to see the Binary Tree in Action_](images/binary_tree_7x7.gif?raw=true) + +###### The Algorithm + +1. For every cell in the grid, knock down a wall either North or West. + +###### Optional Parameters + +- _skew_: String {'NW', 'NE', 'SE', 'SW'} +- Determines which corner of the maze to start looping from. Thus, it also determines the direction of the skew inherant in this algorithm. (default 'NW') + +###### Results + +perfect, biased, skewed + +###### Notes + +This algorithm produces mazes with a serious flaw: the North and West borders of the maze are completely open. Generally, this makes solving the maze too easy to be fun. However, if the person solving the maze can't see the entire thing at one time, this algorithm is still useful. + +On the positive side, this algorithm is extremely fast and very easy to implement. + +## Cellular Automaton + +[![Click to see the Cellular Automaton in Action](images/cell_auto_7x7.png?raw=true) +_Click to see the Cellular Automaton in Action_](images/cell_auto_7x7.gif?raw=true) + +###### The Algorithm + +Cells survive if they have one to three neighbours. If a cell has exactly three neighbours, it is born. It is similar to Conway's Game of Life, but adapted to fix the rules of maze walls. + +###### Optional Parameters + +- _comlpexity_: Float [0.0, 1.0] +- Determines the number of times to seed from a given cell. (default 1.0) +- _density_: Float [0.0, 1.0] +- Determines how many cells to seed from. (default 1.0) + +###### Results + +imperfect, slightly biased + +###### Notes + +Using Cellular Automation to generate a maze is a really fun idea, but it is definitely the slowest maze-generating algorithm. The algorithm does not guarantee a "perfect" maze. In fact, mazes generated like this have all kinds of strange and unique problems. That, if you are a maze purist, you will hate. But if you are trying to make mazes hard to solve you might find interesting. + +## Dungeon Rooms + +[![Click to see Dungeon Rooms in Action](images/dungeon_rooms_11x11.png?raw=true) +_Click to see Dungeon Rooms in Action_](images/dungeon_rooms_11x11.gif?raw=true) + +###### The Algorithm + +This is a variation on Hunt-and-Kill where the initial maze has rooms carved out of it, instead of being completely filled. + +###### Optional Parameters + +- _rooms_: List(List(tuple, tuple)) +- A list of lists, containing the top-left and bottom-right grid coords of where you want rooms to be created. For best results, the corners of each room should have odd-numbered coordinates. +- _grid_: 2D Numpy Array, filled with booleans, all set to `True`, OR with a valid maze inside +- A pre-built maze array filled with one, or many, rooms. +- _hunt_order_: String ['random', 'serpentine'] +- Determines how the next cell to hunt from will be chosen. (default 'random') + +###### Results + +imperfect, slightly biased + +###### Notes + +Theseus traversed a maze to find a minotaur in the center. Similar things happen in a lot of games; players will traverse a maze to find a room filled with enemies or treasure. I developed this algorithm to aid this use-case. + +## Eller's + +[![Click to see the Eller's in Action](images/ellers_7x7.png?raw=true) +_Click to see the Eller's in Action_](images/ellers_7x7.gif?raw=true) + +###### The Algorithm + +1. Put the each cell of the first row in its own set. +2. Join adjacent cells. But not if they are already in the same set. Merge the sets of these cells. +3. For each set in the row, create at least one vertical connection down to the next row. +4. Put any unconnected cells in the next row into their own set. +5. Repeat steps 2 through 4 until the last row. +6. In the last row, join all adjacent cells that do not share a set. + +###### Optional Parameters + +- _xskew_: Float [0.0, 1.0] +- Probability of joining cells in the same row. (default 0.5) +- _yskew_: Float [0.0, 1.0] +- Probability of joining cells in the same column. (default 0.5) + +###### Results + +perfect + +###### Notes + +This is a classic set-theory algorithm. It is not the fastest algorithm, as it requires relabeling whole sets of cells at every step. + +## Growing Tree + +[![Click to see the Growing Tree in Action](images/growing_tree_7x7.png?raw=true) +_Click to see the Growing Tree in Action_](images/growing_tree_7x7.gif?raw=true) + +###### The Algorithm + +1. Let C be a list of cells, initially empty. Add one a random cell from the maze to C. +2. Choose a cell from C, and carve a passage to any unvisited neighbor of that cell, adding that neighbor to C as well. If there are no unvisited neighbors, remove the cell from C. +3. Repeat step 2 until C is empty. + +###### Optional Parameters + +- _backtrack_chance_: Float [0.0, 1.0] +- Splits the logic to either use Recursive Backtracking (RB) or Prim's (random) to select the next cell to visit. (default 1.0) + +###### Results + +perfect + +###### Notes + +This algorithm is very flexible. Instead of defining exactly what must be done, it lays out a general construct. The exact order in which we choose a new cell from set C in step 2 is left undefined. That means we can pick one at random (and mimick the Prim's algorithm), or always pick the most recent one (and mimick the Backtracking algorithm). This implementation allows the developer to set the percentage of time Backtracking is chosen versus Prim's. This gives a lot of variety to the final complexity and look of the final maze. + +## Hunt-and-Kill + +[![Click to see Hunt-and-Kill in Action](images/huntandkill_7x7.png?raw=true) +_Click to see Hunt-and-Kill in Action_](images/huntandkill_7x7.gif?raw=true) + +###### The Algorithm + +1. Randomly choose a starting cell. +2. Perform a random walk from the current cell, carving passages to unvisited neighbors, until the current cell has no unvisited neighbors. +3. Select a new grid cell; if it has been visited, walk from it. +4. Repeat steps 2 and 3 a sufficient number of times that there the probability of a cell not being visited is extremely small. + +###### Optional Parameters + +- _hunt_order_: String ['random', 'serpentine'] +- Determines how the next cell to hunt from will be chosen. (default 'random') + +###### Results + +perfect + +###### Notes + +Generally, you might think random-walk algorithms are very slow. But Hunt-and-Kill is quite efficient. And I really like the end results of this algorithm: the mazes are not easy to solve. + +In this implementation of Hunt-and-kill there are two different ways to select a new grid cell in step 2. The first is serpentine through the grid (the classic solution), the second is to randomly select a new cell enough times that the probability of an unexplored cell is very, very low. The second option includes a small amount of risk, but it creates a more interesting, harder maze. Thus, the second option is default in this implementation. + +## Kruskal's + +[![Click to see the Kruskal's in Action](images/kruskal_7x7.png?raw=true) +_Click to see the Kruskal's in Action_](images/kruskal_7x7.gif?raw=true) + +###### The Algorithm + +1. Create a set of all walls in the grid. +2. Randomly select a wall from the grid. If that wall connects two disjoint trees, join the trees. Otherwise, remove that wall from the set. +3. Repeat step 2 until there are no more walls left in the set. + +###### Results + +perfect + +###### Notes + +Like Prim's, it is based on a namesake algorithm for finding a Minimal Spanning Tree (MST) over a graph. + +## Prim's + +[![Click to see the Prim's in Action](images/prims_7x7.png?raw=true) +_Click to see the Prim's in Action_](images/prims_7x7.gif?raw=true) + +###### The Algorithm + +1. Choose an arbitrary cell from the grid, and add it to some (initially empty) set visited nodes (V). +2. Randomly select a wall from the grid that connects a cell in V with another cell not in V. +3. Add that wall to the Minimal Spanning Tree (MST), and the edge’s other cell to V. +4. Repeat steps 2 and 3 until V includes every cell in G. + +###### Results + +perfect + +###### Notes + +This is a classic. Like Kruskal's, it is based on the idea of finding a MST in a graph. But Prim's is purely random. In fact, randomized variations on other maze-generating algorithms are frequently called "Prim's variations". + +## Recursive Division + +[![Click to see the Division in Action](images/division_7x7.png?raw=true) +_Click to see the Division in Action_](images/division_7x7.gif?raw=true) + +###### The Algorithm + +1. Start with an empty grid. +2. Build a wall that bisects the grid (horizontal or vertical). Add a single passage through the wall. +3. Repeat step 2 with the areas on either side of the wall. +4. Continue, recursively, until the maze passages are the desired resolution. + +###### Results + +perfect, biased, skewed + +###### Notes + +The algorithm is very simple to understand, and reasonably simple to implement. But the results will always look skewed. A big line that perfect divides a maze makes it easier for the human eye to solve: it reduces your visual search space. This is doubly true for humans that happen to know the maze was created by division. + +This implementation tries, as far as is possible, to reduce this skew by alternating the cuts between horizontal and vertical. (Obviously, if you made 7 vertical cuts in a row the maze would be very easy to solve.) + +## Sidewinder + +[![Click to see the Sidewinder in Action](images/sidewinder_7x7.png?raw=true) +_Click to see the Sidewinder in Action_](images/sidewinder_7x7.gif?raw=true) + +###### The Algorithm + +1. Select cells in the maze, row-by-row. +2. Add the current cell to a “run” set. +3. For the current cell, randomly decide whether to carve East. +4. If a passage East was carved, make the new cell the current cell and repeat steps 2-4. +5. If a passage East was not carved, choose any one of the cells in the run set and carve a passage North. Then empty the run set. Repeat steps 2-5. +6. Continue until all rows have been processed. + +###### Optional Parameters + +- _skew_: Float [0.0, 1.0] +- If the skew is set less than 0.5 the maze will be skewed East-West, if it set greater than 0.5 it will be skewed North-South. (default 0.5) + +###### Results + +perfect, flawed + +###### Notes + +The algorithm is simple and optimally fast. However, the North side of the maze will always be one, long, open corridor. For my tastes, this makes the maze too easy to solve. There are use-cases where that will not matter though; if the person solving the maze cannot see the whole thing at one time. + +Research is needed to create a post-processing step to fix this flaw. (Though that will mean varrying from the original algorithm.) + +## Wilson's + +[![Click to see the Wilson's in Action](images/wilsons_7x7.png?raw=true) +_Click to see the Wilson's in Action_](images/wilsons_7x7.gif?raw=true) + +###### The Algorithm + +1. Choose a random cell and add it to the Uniform Spanning Tree (UST). +2. Select any cell that is not in the UST and perform a random walk until you find a cell that is. +3. Add the cells and walls visited in the random walk to the UST. +4. Repeat steps 2 and 3 until all cells have been added to the UST. + +###### Optional Parameters + +- _hunt_order_: String ['random', 'serpentine'] +- Determines how the next cell to hunt from will be chosen. (default 'random') + +###### Results + +perfect, unbiased + +###### Notes + +Like all random-walk algorithms, Wilson's isn't terribly fast. However, this still converges faster than Aldous-Broder. And it produces similarly nice results. + +# Maze-Transmuting Algorithms + +## Cul-de-sac Filler + +![Cul-de-Sac Filler results](images/cul_de_sac_filling.png) + +###### The Algorithm + +1. Scan the maze, looking for cells with connecting halls that go in exactly two directions. +2. At each of these places, travel in both directions until you find your first intersection. +3. If the first intersection for both paths is the same, you have a loop. +4. Fill in the cell you started at with a wall, breaking the loop. + +###### Results + +- This works great for simple loops, and even multi-loops. It would probably fail for big, empty rules. + +###### Notes + +This is a classic algorithm. However, it seems fairly slow by design. Still, if your maze has many cul-de-sacs / loops it could be very helpful. + +## Dead End Filler + +![Dead End Filler results](images/dead_end_steps.png) + +###### The Algorithm + +1. Scan the maze in any order, looking for dead ends. +2. Fill in each dead end, and the dead-end passages attached to them. + +###### Results + +- Run this algorithm enough times on a perfect maze and it will leave only the solution cells open! + +###### Notes + +If you generate a maze which is just _all_ loops (called a heavily braided maze), this algorithm won't do much. But it nearly all other scenarios it works like a charm. + +## Perturbation + +![Perturbation results](images/perturbation_sprial.png) + +###### The Algorithm + +1. Start with a complete, valid maze. +2. Add a small number of random walls, blocking current passages. +3. Go through the maze and reconnect all passages that are not currently open, by randomly opening walls. +4. Repeat steps 3 and 4 a prescribed number of times. + +###### Optional Parameters + +- _new_walls_: Integer [1, 2, ...] +- The number of randomly positioned new walls you create throughout the maze. (default 1) +- _repeat_: Integer [1, 2, ...] +- The number of times sets of new walls will be added to the maze; the maze being fixed after each set. (default 1) + +###### Results + +This usually produces perfect mazes (if the input maze was perfect). But there is a small chance that not all inner walls of the maze will be fully connected. + +###### Notes + +In math and physics, perturbation theory is idea that you can solve a new problem by starting with the known solution to an old problem and making a small change. Here, we take a previously-generated maze and perturb it slightly by adding a couple walls, then re-open any parts of the maze we have closed off. This is an amazingly powerful tool. It can fix nearly any flaw in a maze. Or you can start with a non-maze, say a nice spiral or a cute drawing, and turn it into a maze using first-order perturbations. + +With great power comes great responsibility. If you use this method on a grid that does not contain a maze, it will fail. If you run too many iterations of this algorithm, your end maze will look nothing like the original. But if used wisely, this is an extremely powerful tool. + +# Maze-Solving Algorithms + +## Chain Algorithm + +The idea here is that you break the maze up into a sequence of smaller mazes. + +- There are undoubtedly cases where this helps and cases where this is a terrible idea. Caveat emptor. + +This algorithm uses the Wall Follower algorithm to solve the sub-mazes. + +- As such, it is significantly more complicated and memory-intensive than your standard Wall Follower. + +### The Algorithm + +1. draw a straight-ish line from start to end, ignore the walls. +2. Follow the line from start to end. + 1. If you bump into a wall, you have to go around. + 2. Send out backtracking robots in the 1 or 2 open directions. + 3. If the robot can find your new point, continue on. + 4 .If the robot intersects your line at a point that is further down stream, pick up the path there. +3. repeat step 2 until you are at the end. + 1. If both robots return to their original location and direction, the maze is unsolvable. + +### Results + +- 1 solution +- not the shortest solution +- works against imperfect mazes + +## Collision Solver + +On a perfect maze, this is little different than the Dead End Filler algorithm. But in heavily braided and imperfect mazes, this algorithm simply iterates over the whole maze a few more times and finds the optimal solutions. + +### The Algorithm + +1. step through the maze, flooding all directions equally +2. if two flood paths meet, create a wall where they meet +3. fill in all dead ends +4. repeat until there are no more collisions + +### Results + +- finds shortests solutions +- works against imperfect mazes + +## Random Mouse + +Random mouse may never finish. Technically. It is certainly inefficient in time, but very efficient in memory. + +### The Algorithm: + +A mouse just wanders randomly around the maze until it finds the cheese. + +### Results + +- 1 solution +- not the shortest solution +- works against imperfect mazes + +## Recursive Backtracker + +###### The Algorithm: + +1. Pick a random direction and follow it +2. Backtrack if and only if you hit a dead end. + +###### Results + +- 1 solution +- not the shortest solution +- works against imperfect mazes + +###### Notes + +Mathematically, there is very little difference between this algorithm and Random Mouse. The only difference is that at each point, Random Mouse might go right back where it came from. But Backtracker will only do that if it reaches a dead end. + +## Shortest Path Finder + +###### The Algorithm: + +1. create a possible solution for each neighbor of the starting position +2. find the neighbors of the last element in each solution, branches create new solutions +3. repeat step 2 until you reach the end +4. The first solution to reach the end wins. + +###### Results + +- finds all solutions +- finds shortest solution(s) +- works against imperfect mazes + +###### Notes + +In CS terms, this is a Breadth-First Search algorithm that is cut short when the first solution is found. + +## Shortest Paths Finder + +###### The Algorithm + +1. create a possible solution for each neighbor of the starting position +2. find the neighbors of the last element in each solution, branches create new solutions +3. repeat step 2 until you al solutions hit dead ends or reach the end +4. remove all dead end solutions + +###### Results + +- finds all solutions +- works against imperfect mazes + +###### Notes + +In CS terms, this is a Breadth-First Search algorithm. It finds all unique, non-looped solutions to the maze. + +Though this version is optimized to improve speed, nothing could be done about the fact that this algorithm uses substantially more memory than just the maze grid itself. + +## Trémaux's Algorithm + +###### The Algorithm + +1. Every time you visit a cell, mark it once. +2. When you hit a dead end, turn around and go back. +3. When you hit a junction you haven't visited, pick a new passage at random. +4. If you're walking down a new passage and hit a junction you have visited, treat it like a dead end and go back. +5. If walking down a passage you have visited before (i.e. marked once) and you hit a junction, take any new passage available, otherwise take an old passage (i.e. marked once). +6. When you finally reach the end, follow cells marked exactly once back to the start. +7. If the Maze has no solution, you'll find yourself at the start with all cells marked twice. + +###### Results + +- Finds one non-optimal solution. +- Works against imperfect mazes. + +###### Notes + +This Maze-solving method is designed to be used by a human inside the Maze. diff --git a/static/docs/Random Walk/Readme.md b/static/docs/Random Walk/Readme.md new file mode 100644 index 0000000..a5103f1 --- /dev/null +++ b/static/docs/Random Walk/Readme.md @@ -0,0 +1,26 @@ +# Introduction + +# Random Walk, Brownian Motion and Ito Process + +Ito process is a continuous-time trajectory with random evolution, so non-smooth and very kinky - also has a fractal look. + +- Ito process consists in fact of two parts: the drift part (deterministic evolution) and the diffusion part (where all the kinkiness and fractalness comes from). +- If Ito process does not posses the diffusion part, it just looks like a continuous smooth trajectory. +- If Ito process has only diffusion component, you won't be able to spot it i.e. when the diffusion component is present, it's hard to say whether there is a drift component or not, because of the noise diffusion provides. +- An Ito Process is a Brownian Motion with possibly non-zero mean. + +A Brownian Motion is a continuous time series of random variables whose increments are i.i.d. normally distributed with 0 mean. + +- It is a special case of an Ito process, and is the main building block for the diffusion component. +- Any diffusion is just a time scaled Brownian motion. +- Its increments are uncorrelated (in fact, they are independent) whereas in general Ito process there can be loads of cross-correlation happening. + +A random walk is a discrete time process whose increments are +/-1 with equal probability. + +- As it is discrete time process hence not comparable with Ito processes which are continuous-time things. +- Random walk must also have independent increments - that's why Brownian motion sometimes referred to as a (continuous-time) random walk. + +# Variations + +Levy Flight +Self Avoiding Walk diff --git a/static/favicon.png b/static/favicon.png new file mode 100644 index 0000000000000000000000000000000000000000..825b9e65af7c104cfb07089bb28659393b4f2097 GIT binary patch literal 1571 zcmV+;2Hg3HP)Px)-AP12RCwC$UE6KzI1p6{F2N z1VK2vi|pOpn{~#djwYcWXTI_im_u^TJgMZ4JMOsSj!0ma>B?-(Hr@X&W@|R-$}W@Z zgj#$x=!~7LGqHW?IO8+*oE1MyDp!G=L0#^lUx?;!fXv@l^6SvTnf^ac{5OurzC#ZMYc20lI%HhX816AYVs1T3heS1*WaWH z%;x>)-J}YB5#CLzU@GBR6sXYrD>Vw(Fmt#|JP;+}<#6b63Ike{Fuo!?M{yEffez;| zp!PfsuaC)>h>-AdbnwN13g*1LowNjT5?+lFVd#9$!8Z9HA|$*6dQ8EHLu}U|obW6f z2%uGv?vr=KNq7YYa2Roj;|zooo<)lf=&2yxM@e`kM$CmCR#x>gI>I|*Ubr({5Y^rb zghxQU22N}F51}^yfDSt786oMTc!W&V;d?76)9KXX1 z+6Okem(d}YXmmOiZq$!IPk5t8nnS{%?+vDFz3BevmFNgpIod~R{>@#@5x9zJKEHLHv!gHeK~n)Ld!M8DB|Kfe%~123&Hz1Z(86nU7*G5chmyDe ziV7$pB7pJ=96hpxHv9rCR29%bLOXlKU<_13_M8x)6;P8E1Kz6G<&P?$P^%c!M5`2` zfY2zg;VK5~^>TJGQzc+33-n~gKt{{of8GzUkWmU110IgI0DLxRIM>0US|TsM=L|@F z0Bun8U!cRB7-2apz=y-7*UxOxz@Z0)@QM)9wSGki1AZ38ceG7Q72z5`i;i=J`ILzL z@iUO?SBBG-0cQuo+an4TsLy-g-x;8P4UVwk|D8{W@U1Zi z!M)+jqy@nQ$p?5tsHp-6J304Q={v-B>66$P0IDx&YT(`IcZ~bZfmn11#rXd7<5s}y zBi9eim&zQc0Dk|2>$bs0PnLmDfMP5lcXRY&cvJ=zKxI^f0%-d$tD!`LBf9^jMSYUA zI8U?CWdY@}cRq6{5~y+)#h1!*-HcGW@+gZ4B};0OnC~`xQOyH19z*TA!!BJ%9s0V3F?CAJ{hTd#*tf+ur-W9MOURF-@B77_-OshsY}6 zOXRY=5%C^*26z?l)1=$bz30!so5tfABdSYzO+H=CpV~aaUefmjvfZ3Ttu9W&W3Iu6 zROlh0MFA5h;my}8lB0tAV-Rvc2Zs_CCSJnx@d`**$idgy-iMob4dJWWw|21b4NB=LfsYp0Aeh{Ov)yztQi;eL4y5 zMi>8^SzKqk8~k?UiQK^^-5d8c%bV?$F8%X~czyiaKCI2=UH