{"id":13477015,"url":"https://github.com/je-suis-tm/graph-theory","last_synced_at":"2025-04-06T08:15:15.835Z","repository":{"id":41371918,"uuid":"133557089","full_name":"je-suis-tm/graph-theory","owner":"je-suis-tm","description":"Julia and Python complex system applications in ecology, epidemiology, sociology, economics \u0026 finance; network science models including Bianconi-Barabási, Barabási-Albert, Watts-Strogatz, Waxman Model \u0026 Erdős-Rényi; graph theory algorithms involving Gillespie, Bron Kerbosch, Ramsey, Bellman Ford, A*, Kruskal, Borůvka, Prim, Dijkstra, DSatur, Randomized Distributed, Vizing, Topological Sort, DFS, BFS","archived":false,"fork":false,"pushed_at":"2022-04-29T20:05:46.000Z","size":40624,"stargazers_count":368,"open_issues_count":0,"forks_count":91,"subscribers_count":14,"default_branch":"master","last_synced_at":"2025-03-30T07:11:12.511Z","etag":null,"topics":["agent-based-modeling","agent-based-simulation","barabasi-albert","bianconi-barabasi","compartmental-model","complex-network","complex-systems","dynamic-network","dynamic-system","epidemic-model","graph-coloring","graph-theory","maximal-cliques","minimum-spanning-tree","minimum-spanning-trees","random-graph","sars-cov-2","sir-model","spatial-models","watts-strogatz"],"latest_commit_sha":null,"homepage":"https://je-suis-tm.github.io/graph-theory","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/je-suis-tm.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-05-15T18:29:18.000Z","updated_at":"2025-03-25T20:22:24.000Z","dependencies_parsed_at":"2022-09-05T04:00:35.519Z","dependency_job_id":null,"html_url":"https://github.com/je-suis-tm/graph-theory","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/je-suis-tm%2Fgraph-theory","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/je-suis-tm%2Fgraph-theory/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/je-suis-tm%2Fgraph-theory/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/je-suis-tm%2Fgraph-theory/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/je-suis-tm","download_url":"https://codeload.github.com/je-suis-tm/graph-theory/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247451667,"owners_count":20940944,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["agent-based-modeling","agent-based-simulation","barabasi-albert","bianconi-barabasi","compartmental-model","complex-network","complex-systems","dynamic-network","dynamic-system","epidemic-model","graph-coloring","graph-theory","maximal-cliques","minimum-spanning-tree","minimum-spanning-trees","random-graph","sars-cov-2","sir-model","spatial-models","watts-strogatz"],"created_at":"2024-07-31T16:01:37.228Z","updated_at":"2025-04-06T08:15:15.793Z","avatar_url":"https://github.com/je-suis-tm.png","language":"Jupyter Notebook","funding_links":[],"categories":["Jupyter Notebook","LLM / AI Agents for Finance"],"sub_categories":[],"readme":"# Graph Theory\n\n\u0026nbsp;\n\n## Intro\n\nGraph theory, sometimes we call it complex network, complex system or network science or network analysis, is one of the most avant-garde research areas in discrete mathematics, also one of my favorite subjects. Here, “graph” is the preferred name, because too many people associate the word “network” with internet. Given the bonanza of data science, graph theory is constantly overshadowed by the hype of machine learning. Yet some of the top-notch technology companies such as Google and Facebook heavily rely on the research of graph theory. \n\nThis repository intends to increase the exposure of graph theory to all my readers. It contains common graph algorithms, popular network models, interesting agent-based simulations and amazing complex systems. The codes range from the level of elementary to sophisticated with wide applications in ecology, epidemiology, sociology, economics, finance, etc. Both Julia and Python are used to construct different scripts. As I am slowly climbing up the learning curve, more and more fascinating content will emerge en masse. Stay tuned!\n\n\u0026nbsp;\n\n## Table of Contents\n\n### Algorithms\n\n* \u003ca href=https://github.com/je-suis-tm/graph-theory/blob/master/a_star%20maze.ipynb\u003eA* Search\u003c/a\u003e \n\n* \u003ca href=https://github.com/je-suis-tm/graph-theory/blob/master/k%20core.ipynb\u003eBatagelj Zaveršnik\u003c/a\u003e \n\n* \u003ca href=https://github.com/je-suis-tm/graph-theory/blob/master/bellman_ford%20forex%20arbitrage.ipynb\u003eBellman Ford\u003c/a\u003e \n\n* \u003ca href=https://github.com/je-suis-tm/graph-theory/blob/master/BFS%20DFS%20on%20DCG.ipynb\u003eBiDirectional BFS\u003c/a\u003e \n\n* \u003ca href=https://github.com/je-suis-tm/graph-theory/blob/master/minimum%20spanning%20tree.ipynb\u003eBorůvka\u003c/a\u003e \n\n* \u003ca href=https://github.com/je-suis-tm/graph-theory/blob/master/BFS%20DFS%20on%20DCG.ipynb\u003eBreadth First Search\u003c/a\u003e \n\n* \u003ca href=https://github.com/je-suis-tm/graph-theory/blob/master/maximal%20clique.ipynb\u003eBron Kerbosch\u003c/a\u003e \n\n* \u003ca href=https://github.com/je-suis-tm/graph-theory/blob/master/BFS%20DFS%20on%20DCG.ipynb\u003eDepth First Search\u003c/a\u003e \n\n* \u003ca href=https://github.com/je-suis-tm/graph-theory/blob/master/dijkstra%20shortest%20path.ipynb\u003eDijkstra\u003c/a\u003e \n\n* \u003ca href=https://github.com/je-suis-tm/graph-theory/blob/master/graph%20coloring.ipynb\u003eDSatur\u003c/a\u003e\n\n* \u003ca href=https://github.com/je-suis-tm/graph-theory/blob/master/habitat%20competition.ipynb\u003eGillespie\u003c/a\u003e \n\n* \u003ca href=https://github.com/je-suis-tm/graph-theory/blob/master/topological%20sort.ipynb\u003eKahn\u003c/a\u003e \n\n* \u003ca href=https://github.com/je-suis-tm/graph-theory/blob/master/minimum%20spanning%20tree.ipynb\u003eKruskal\u003c/a\u003e \n\n* \u003ca href=https://github.com/je-suis-tm/graph-theory/blob/master/k%20core.ipynb\u003eMatula Beck\u003c/a\u003e \n\n* \u003ca href=https://github.com/je-suis-tm/graph-theory/blob/master/minimum%20spanning%20tree.ipynb\u003ePrim\u003c/a\u003e \n\n* \u003ca href=https://github.com/je-suis-tm/graph-theory/blob/master/maximal%20independent%20set.ipynb\u003eRamsey\u003c/a\u003e \n\n* \u003ca href=https://github.com/je-suis-tm/graph-theory/blob/master/maximal%20independent%20set.ipynb\u003eRandomized Distributed\u003c/a\u003e \n\n* \u003ca href=https://github.com/je-suis-tm/graph-theory/blob/master/graph%20coloring.ipynb\u003eVizing\u003c/a\u003e\n\n\u0026nbsp;\n\n### Applications\n\n* \u003ca href=https://github.com/je-suis-tm/graph-theory#16-diversity-trumps-ability\u003eDiversity Trumps Ability\u003c/a\u003e\n\n* \u003ca href=https://github.com/je-suis-tm/graph-theory#17-graph-coloring\u003eEdge Coloring\u003c/a\u003e \n\n* \u003ca href=https://github.com/je-suis-tm/graph-theory#12-epidemic-outbreak\u003eEpidemic Outbreak\u003c/a\u003e \n\n* \u003ca href=https://github.com/je-suis-tm/graph-theory#7-forex-arbitrage\u003eForex Arbitrage\u003c/a\u003e \n\n* \u003ca href=https://github.com/je-suis-tm/graph-theory#15-habitat-competition\u003eHabitat Competition\u003c/a\u003e \n\n* \u003ca href=https://github.com/je-suis-tm/graph-theory#14-habitat-occupancy\u003eHabitat Occupancy\u003c/a\u003e \n\n* \u003ca href=https://github.com/je-suis-tm/graph-theory#10-k-core\u003eK Core\u003c/a\u003e \n\n* \u003ca href=https://github.com/je-suis-tm/graph-theory#5-knights-tour\u003eKnight's Tour\u003c/a\u003e \n\n* \u003ca href=https://github.com/je-suis-tm/graph-theory#11-maximal-clique\u003eMaximal Clique\u003c/a\u003e \n\n* \u003ca href=https://github.com/je-suis-tm/graph-theory#18-maximal-independent-set\u003eMaximal Independent Set\u003c/a\u003e \n\n* \u003ca href=https://github.com/je-suis-tm/graph-theory#1-maze\u003eMaze\u003c/a\u003e \n\n* \u003ca href=https://github.com/je-suis-tm/graph-theory#2-minimum-spanning-tree\u003eMinimum Spanning Tree\u003c/a\u003e \n\n* \u003ca href=https://github.com/je-suis-tm/graph-theory#6-missionaries-and-cannibals\u003eMissionaries and Cannibals\u003c/a\u003e \n\n* \u003ca href=https://github.com/je-suis-tm/graph-theory#13-portfolio-optimization\u003ePortfolio Optimization\u003c/a\u003e \n\n* \u003ca href=https://github.com/je-suis-tm/graph-theory#3-shortest-path\u003eShortest Path\u003c/a\u003e  \n\n* \u003ca href=https://github.com/je-suis-tm/graph-theory#20-sliding-puzzle\u003eSliding Puzzle\u003c/a\u003e \n\n* \u003ca href=https://github.com/je-suis-tm/graph-theory#19-sudoku\u003eSudoku\u003c/a\u003e \n\n* \u003ca href=https://github.com/je-suis-tm/graph-theory#9-text-mining\u003eText Mining\u003c/a\u003e \n\n* \u003ca href=https://github.com/je-suis-tm/graph-theory#17-graph-coloring\u003eVertex Coloring\u003c/a\u003e \n\n* \u003ca href=https://github.com/je-suis-tm/graph-theory#4-water-jug\u003eWater Jug\u003c/a\u003e \n\n* \u003ca href=https://github.com/je-suis-tm/graph-theory#8-word-ladder\u003eWord Ladder\u003c/a\u003e \n\n\u0026nbsp;\n\n### Models\n\n* \u003ca href=https://github.com/je-suis-tm/graph-theory/blob/master/barabasi%20albert%20model.ipynb\u003eBarabási-Albert\u003c/a\u003e\n\n* \u003ca href=https://github.com/je-suis-tm/graph-theory/blob/master/bianconi%20barabasi%20model.ipynb\u003eBianconi-Barabási\u003c/a\u003e\n\n* \u003ca href=https://github.com/je-suis-tm/graph-theory/blob/master/watts%20strogatz%20model.ipynb\u003eErdős–Rényi\u003c/a\u003e\n\n* \u003ca href=https://github.com/je-suis-tm/graph-theory/blob/master/watts%20strogatz%20model.ipynb\u003eWatts-Strogatz\u003c/a\u003e\n\n* \u003ca href=https://github.com/je-suis-tm/graph-theory/blob/master/habitat%20occupancy.ipynb\u003eLevins\u003c/a\u003e\n\n* \u003ca href=https://github.com/je-suis-tm/graph-theory/blob/master/habitat%20competition.ipynb\u003eSchelling’s\u003c/a\u003e\n\n* \u003ca href=https://github.com/je-suis-tm/graph-theory/blob/master/habitat%20competition.ipynb\u003eTilman\u003c/a\u003e\n\n* \u003ca href=https://github.com/je-suis-tm/graph-theory/blob/master/diversity%20trumps%20ability.ipynb\u003eWaxman\u003c/a\u003e\n\n\u0026nbsp;\n\n## Applications\n\n### 1. Maze\n\nWalking out of a maze seems extremely complex in recursion algorithm. In graph theory, it is just a walk in the park. The only bit that takes some effort is building the data structure. Once we got graph ADT, we can use BFS/DFS/Dijkstra/A* to find the way out of the maze, although DFS may not be able to point out the shortest route.\n\n*Click \u003ca href=https://github.com/je-suis-tm/graph-theory/blob/master/a_star%20maze.ipynb\u003ehere\u003c/a\u003e to be redirected to the script.*\n\n![alt text](https://github.com/je-suis-tm/graph-theory/blob/master/preview/a_star.png)\n\n### 2. Minimum Spanning Tree\n\nImagine a telecommunications company Orange tries to create a cable network connecting every family in Côte d’Azur. There are possibly millions of different routes to build such a network. Yet, the company only wants to satisfy every customer with the minimum cost. This creates a typical minimum spanning tree problem. Minimum spanning tree is a subset of a graph to connect all vertices without any cycle to achieve the minimum total weight. In this chapter, we will demonstrate how Borůvka’s algorithm, Kruskal’s algorithm and Prim’s algorithm obtain such a topological output. \n\n*Click \u003ca href=https://github.com/je-suis-tm/graph-theory/blob/master/minimum%20spanning%20tree.ipynb\u003ehere\u003c/a\u003e to be redirected to the script.*\n\n![alt text](https://github.com/je-suis-tm/graph-theory/blob/master/preview/minimum%20spanning%20tree%20subset.jpg)\n\n### 3. Shortest Path\n\nWhenever we hear the phrase 'shortest path', we should instinctively shout out Dijkstra's algorithm in our mind. This Dutchman came up with the revolutionary algorithm named after himself while searching for the shortest path to Rotterdam without pencil and paper. The algorithm is a special case of A* algorithm without heuristic function. It is also widely used as a subroutine for other traversal algorithms, such as Bellman-Ford. Apart from Dijkstra, the shortest path problem, which could be thought as an optimization problem, can also be solved in \u003ca href=https://github.com/je-suis-tm/recursion-and-dynamic-programming\u003edynamic programming\u003c/a\u003e.\n\n*Click \u003ca href=https://github.com/je-suis-tm/graph-theory/blob/master/dijkstra%20shortest%20path.ipynb\u003ehere\u003c/a\u003e to be redirected to the script.*\n\n![alt text](https://github.com/je-suis-tm/graph-theory/blob/master/preview/dijkstra.jpg)\n\n### 4. Water Jug\n\nWater jug is a simple and interesting problem. Assuming there are two jugs, a m-gallon and a n-gallon. And the target is to get x gallon water in either jug. There are many ways to solve this problem. Recursion can also solve water jug problem but it is very costly. Building a graph data structure would be a much easier way. The key is to set up edges based upon the rule of the game to connect all possible scenarios together. With BFS starts from the initial status, it can efficiently find the target status and return the route for us which would be the answer.\n\n*Click \u003ca href=https://github.com/je-suis-tm/graph-theory/blob/master/water%20jug%20problem.ipynb\u003ehere\u003c/a\u003e to be redirected to the script.*\n\n![alt text](https://github.com/je-suis-tm/graph-theory/blob/master/preview/water%20jug.gif)\n\n### 5. Knight's Tour\n\nKnight's tour is a game where a knight travels all the squares on a k by k chessboard. And each square can only be travelled once. The solution can be obtained by DFS with a list that records whether each square on the chessboard has been visited. The rules of a knight's movement are very different from pawns or king. The edges of the graph should indicate the valid move from one square to another.\n \n*Click \u003ca href=https://github.com/je-suis-tm/graph-theory/blob/master/knights%20tour.ipynb\u003ehere\u003c/a\u003e to be redirected to the script.*\n\n![alt text](https://github.com/je-suis-tm/graph-theory/blob/master/preview/knights%20tour.gif)\n\n### 6. Missionaries and Cannibals\n\nMissionaries and cannibals is a classic river problem. I actually prefer its alternative version called jealous husband. There are k missionaries and k cannibals. They need to cross a river. There is a boat with the capacity of only two people. There should be at least one person to sail the boat. These rules are subjected to one constraint. Cannibals cannot outnumber missionaries on both sides of the river. Again, the solution is similar to water jug problem. We have to set up edges based upon the rule of the game to connect all possible and valid scenarios together. As usual, BFS always return the optimized result rather than DFS.\n\n*Click \u003ca href=https://github.com/je-suis-tm/graph-theory/blob/master/missionaries%20and%20cannibals%20problems.ipynb\u003ehere\u003c/a\u003e to be redirected to the script.*\n\n![alt text](https://github.com/je-suis-tm/graph-theory/blob/master/preview/missionaries%20and%20cannibals.gif)\n\n### 7. Forex Arbitrage\n\nFinding the shortest path on a map is not the only problem Dijkstra can solve. Financial market is another application. As we all know, currency pairs have both bid and ask price. The market is weak-efficient. There could be an opportunity for triangle arbitrage or rectangle arbitrage. We can exchange from currency A to currency B then to currency C if we can churn out more profit rather than directly exchanging currency A to currency C. We set each currency as the vertex and the exchange rate from one currency to another as the weight of the edge. The arbitrage with some logarithm transformation would be the criteria for Dijkstra. However, Dijkstra cannot properly handle a graph structure with negative weights. We will introduce an improved version called Bellman-Ford which is able to detect the negative cycle during the traversal.\n\n*Click \u003ca href=https://github.com/je-suis-tm/graph-theory/blob/master/bellman_ford%20forex%20arbitrage.ipynb\u003ehere\u003c/a\u003e to be redirected to the script.*\n\n![alt text](https://github.com/je-suis-tm/graph-theory/blob/master/preview/arbitrage.png)\n\n### 8. Word Ladder\n\nWord ladder problem is a game developed by the author of Alice in Wonderland. Given one word, we try to change it into another word. Each time we can only change one letter and it should also be a valid word. This is a great test for vocabulary. The difficult part of building a graph structure is to build edges. Connect one word to another with only one letter changed takes a bit of work. BFS is the perfect solution for this.\n\n*Click \u003ca href=https://github.com/je-suis-tm/graph-theory/blob/master/word%20ladder.ipynb\u003ehere\u003c/a\u003e to be redirected to the script.*\n\n![alt text](https://github.com/je-suis-tm/graph-theory/blob/master/preview/word%20ladder.png)\n\n### 9. Text Mining\n\nIs machine learning the best solution to text mining? What if graph theory beats it in both time and space complexity?\n\nThe whole project is designed for \u003ca href=https://github.com/je-suis-tm/web-scraping/blob/master/MENA%20Newsletter.py\u003eMENA Newsletter\u003c/a\u003e. The idea is to use graph structure traversal algorithm to remove similar contents and extract key information from the metadata of text.\n\n*For more details, please refer to the \u003ca href=https://github.com/je-suis-tm/graph-theory/blob/master/Text%20Mining%20project/README.md\u003eread me\u003c/a\u003e page of a separate directory or \u003ca href=https://je-suis-tm.github.io/graph-theory/text-mining\u003egraph theory\u003c/a\u003e section on my personal blog.*\n\n![alt text](https://github.com/je-suis-tm/graph-theory/blob/master/Text%20Mining%20project/preview/wordcloud.png)\n\n### 10. K Core\n\nK core, also known as k degenerate, is a subset of the original graph in which all vertices have degree at least k. By some definition, k core is required to be a connected graph. The standard algorithm to find a k core graph is to remove all the vertices that have degree less than k. We must be careful that removing a vertex reduces the degree of all the vertices adjacent to it, hence the degree of adjacent vertices can also drop below k. And thus, we may have to remove those vertices as well.\n\n*Click \u003ca href=https://github.com/je-suis-tm/graph-theory/blob/master/k%20core.ipynb\u003ehere\u003c/a\u003e to be redirected to the script.*\n\n![alt text](https://github.com/je-suis-tm/graph-theory/blob/master/preview/kcore.png)\n\n### 11. Maximal Clique\n\nA \u003ca href=https://en.wikipedia.org/wiki/Clique_(graph_theory)\u003eclique\u003c/a\u003e is a subset of vertices of an undirected graph such that every two distinct vertices in the clique are adjacent. A maximal clique is a clique that cannot be extended by including one more adjacent vertex, meaning it is not a subset of a larger clique. Think of maximal clique as a maximum social group where everybody knows each other. Finding a maximal clique is an \u003ca href=https://en.wikipedia.org/wiki/NP-completeness\u003eNP-complete\u003c/a\u003e problem. \u003ca href=https://en.wikipedia.org/wiki/Bron–Kerbosch_algorithm\u003eBron–Kerbosch algorithm\u003c/a\u003e with degeneracy ordering is the most efficient way to find out all maximal cliques. Its time complexity can be optimized to O(3**(n/3)).\n\n*Click \u003ca href=https://github.com/je-suis-tm/graph-theory/blob/master/maximal%20clique.ipynb\u003ehere\u003c/a\u003e to be redirected to the script.*\n\n![alt text](https://github.com/je-suis-tm/graph-theory/blob/master/preview/maximal%20clique.jpg)\n\n### 12. Epidemic Outbreak\n\nAmid the outbreak of the novel corona virus, we have observed a bonanza of agent-based simulation in epidemiology. By leveraging the probability generating function of a random graph, whether it is \u003ca href=https://github.com/je-suis-tm/graph-theory/blob/master/barabasi%20albert%20model.ipynb\u003eBarabási-Albert\u003c/a\u003e following power-law distribution or \u003ca href=https://github.com/je-suis-tm/graph-theory/blob/master/watts%20strogatz%20model.ipynb\u003eErdős–Rényi\u003c/a\u003e following Poisson distribution, we are able to consume the least computing power to estimate the prevalence and the duration of COVID-19.\n\n*For more details, please refer to the \u003ca href=https://github.com/je-suis-tm/graph-theory/blob/master/Epidemic%20Outbreak%20project/README.md\u003eread me\u003c/a\u003e page of a separate directory or \u003ca href=https://je-suis-tm.github.io/graph-theory/epidemic-outbreak\u003egraph theory\u003c/a\u003e section on my personal blog.*\n\n![alt text](https://github.com/je-suis-tm/graph-theory/blob/master/Epidemic%20Outbreak%20project/preview/gillespie.gif)\n\n### 13. Portfolio Optimization\n\nModern portfolio theory was introduced in 1952 by Nobel laureate Harry Markowitz. It is part of investment class 101. But I watched a video by \u003ca href=https://www.wolfram.com/training/videos/FIN015\u003eWolfram\u003c/a\u003e recently. It challenged the traditional approach and introduced graph theory to asset diversification. There are plenty of quant shops deploying fancy mathematic tools to solve the market. The real question for us is, as fancy as it sounds, does graph theory work on portfolio optimization?\n\n*For more details, please refer to the \u003ca href=https://github.com/je-suis-tm/graph-theory/blob/master/Portfolio%20Optimization%20project/README.md\u003eread me\u003c/a\u003e page of a separate directory or \u003ca href=https://je-suis-tm.github.io/graph-theory/portfolio-optimization\u003egraph theory\u003c/a\u003e section on my personal blog.*\n\n![alt text](https://github.com/je-suis-tm/graph-theory/blob/master/Portfolio%20Optimization%20project/preview/outta%20sample%20mean%20variance.png)\n\n### 14. Habitat Occupancy\n\nIn the traditional study of community ecology, metapopulation model is used to map out the patchy habitat occupancy and extinction. It only requires one ordinary differential equation to monitor a single species. However, one of the biggest malaise is its landscape connectivity. With complex network, we can incorporate spatial structure into the deterministic system to create an agent-based simulation.\n\n*Click \u003ca href=https://github.com/je-suis-tm/graph-theory/blob/master/habitat%20occupancy.ipynb\u003ehere\u003c/a\u003e to be redirected to the script. Please note this script is written in Julia.*\n\n![alt text](https://github.com/je-suis-tm/graph-theory/blob/master/preview/levins%20model.gif)\n\n### 15. Habitat Competition\n\n\u003ca href=https://github.com/je-suis-tm/graph-theory/blob/master/habitat%20occupancy.ipynb\u003eLevins model\u003c/a\u003e has exceptional explanatory power for habitat fragmentation. Tilman model expands it to a more generalized form for multiple species. The stronger species can out-compete and displace weaker species. In this example, our agent-based simulation will illustrate the vis-à-vis among native species and invasive species. With the blessing of the spatial structure, some of the native species in remote area may be able to survive the invasion. \n\n![alt text](https://github.com/je-suis-tm/graph-theory/blob/master/preview/tilman%20model.gif)\n\nIn the later chapter of this script, we will introduce Schelling’s model from sociology to investigate how the segregation is formed when multiple groups are presented in the system. Schelling’s model shows some unique traits such as \u003ca href=https://github.com/je-suis-tm/graph-theory/blob/master/maximal%20clique.ipynb\u003emaximal clique\u003c/a\u003e when implemented on a random geometric graph.\n\n*Click \u003ca href=https://github.com/je-suis-tm/graph-theory/blob/master/habitat%20competition.ipynb\u003ehere\u003c/a\u003e to be redirected to the script. Please note this script is written in Julia.*\n\n![alt text](https://github.com/je-suis-tm/graph-theory/blob/master/preview/schelling's%20model.gif)\n\n### 16. Diversity Trumps Ability\n\nIn 2004, Lu Hong and Scott E. Page published a game-changing paper on diversity. They used agent-based model to prove that a diverse group of people is better than a group of best-performing individuals. Despite the high citations of this paper, plenty of scholars dispute the idea which makes the theory rather controversial. The caveat is the experiment of solving problems on lattice is too simple and straight forward whereas in real life the situation is more dynamic. Hence, the objective of this experiment is to convert lattice problem into the context of avant-garde random graphs. With the agent-based simulation on Waxman model, we are able to retain as many of the properties of a real life problem as possible and simplify the situation with respect to our ability to analyze the performance of different agents.\n\n*Click \u003ca href=https://github.com/je-suis-tm/graph-theory/blob/master/diversity%20trumps%20ability.ipynb\u003ehere\u003c/a\u003e to be redirected to the script. Please note this script is written in Julia.*\n\n![alt text](https://github.com/je-suis-tm/graph-theory/blob/master/preview/waxman%20model.gif)\n\n### 17. Graph Coloring\n\nGraph coloring is a color assignment problem on graph structures. The color could be assigned to the vertex or the edge. No adjacent vertex or edge should have the same color. The coloring may sound like an easy problem. To find an optimal coloring for vertices or edges is in fact NP-hard.\n\n\nOne of the most popular algorithms for vertex coloring is DSatur Algorithm by Daniel Brélaz. It beats greedy algorithm in random graph. The faux pas of DSatur is its inability to capture the optimal vertex coloring for all types of graph structures.\n\n![alt text](https://github.com/je-suis-tm/graph-theory/blob/master/preview/vertex%20coloring.png)\n\nOne of the most common and the easiest algorithms for edge coloring is Vizing's algorithm. It is a simple greedy algorithm to prove Vizing's theorem where the upper bound of the chromatic index equals to the maximum degree of the graph structure plus one. The malaise of Vizing is its inability to capture the optimal edge coloring for all types of graph structures.\n\n*Click \u003ca href=https://github.com/je-suis-tm/graph-theory/blob/master/graph%20coloring.ipynb\u003ehere\u003c/a\u003e to be redirected to the script.*\n\n![alt text](https://github.com/je-suis-tm/graph-theory/blob/master/preview/edge%20coloring.png)\n\n### 18. Maximal Independent Set\n\nAn independent set is a subset of a graph such that no two vertices inside are connected. A maximal independent set is an independent set that cannot include any extra vertices without violating the definition. A maximum independent set is one of the maximal independent sets with maximum cardinality. \n\nThere are tons of algorithms to find maximal independent set. Maximal independent set is an NP-complete problem for computer scientists. Currently the most popular one is randomized distributed algorithm.\n\n![alt text](https://github.com/je-suis-tm/graph-theory/blob/master/preview/maximal%20independent%20set.png)\n\nFinding maximal independent set is NP-complete but finding maximum independent set is NP-hard. Intuitively, the easiest way to find a maximum independent set is a brute force algorithm to select maximum independent set from all the maximal independent sets. `NetworkX` prefers Ramsey algorithm to approximate maximum independent set. Thus, it is worth the effort to make a little introduction of Ramsey algorithm.\n\n*Click \u003ca href=https://github.com/je-suis-tm/graph-theory/blob/master/maximal%20independent%20set.ipynb\u003ehere\u003c/a\u003e to be redirected to the script.*\n\n![alt text](https://github.com/je-suis-tm/graph-theory/blob/master/preview/maximum%20independent%20set.png)\n\n### 19. Sudoku\n\nSudoku is a combinatorial number-placement puzzle. Despite its Japanese name, the game was actually invented by an American and later gained popularity in Japan. There are many ways for computer algorithms to solve Sudoku. Here we use \u003ca href=https://github.com/je-suis-tm/graph-theory/blob/master/graph%20coloring.ipynb\u003evertex coloring\u003c/a\u003e to solve the puzzle via \u003ca href=https://github.com/je-suis-tm/graph-theory/blob/master/maximal%20independent%20set.ipynb\u003emaximum independent set\u003c/a\u003e. Vertex coloring guarantees no adjacent vertex should have the same color. As long as we can create a proper data structure for Sudoku puzzle, we are able to find the optimal vertex coloring scheme. \n\nHowever, the optimal graph coloring is in fact an NP-hard problem. There are plenty of greedy algorithms but none really work very well on Sudoku. To avoid brute force, we tackle the optimal vertex coloring via maximum independent set. The maximum independent set is also an NP-hard problem with plenty of approximation algorithms not working well on Sudoku. So we apply a trick. The maximum independent set in a graph ADT is a \u003ca href=https://github.com/je-suis-tm/graph-theory/blob/master/maximal%20clique.ipynb\u003emaximum clique\u003c/a\u003e in a complement graph. It is much easier to search all the maximal cliques via \u003ca href=https://github.com/je-suis-tm/graph-theory/blob/master/maximal%20clique.ipynb\u003eBron Kerbosch algorithm\u003c/a\u003e. We merely need to discover the maximal clique with maximum cardinality. \n\n*Click \u003ca href=https://github.com/je-suis-tm/graph-theory/blob/master/sudoku.ipynb\u003ehere\u003c/a\u003e to be redirected to the script.*\n\n![alt text](https://github.com/je-suis-tm/graph-theory/blob/master/preview/sudoku.png)\n\n### 20. Sliding Puzzle\n\nSliding puzzle is a fun game. Let's be a bit nostalgic. In windows 7, you can pin a picture puzzle to the desktop from the gadgets. That can be considered as a sliding puzzle. To make our life easier, we merely intent to seek solutions to number puzzle. The objective is the same. Move the tiles to ensure the entire puzzle is sorted in numerical orders. In translation, the puzzle needs to go from one status to another. Your instinct should immediately tell that we are going to tackle this problem via graph theory. \n\n*Click \u003ca href=https://github.com/je-suis-tm/graph-theory/blob/master/sliding%20puzzle.ipynb\u003ehere\u003c/a\u003e to be redirected to the script.*\n\n![alt text](https://github.com/je-suis-tm/graph-theory/blob/master/preview/sliding%20puzzle.gif)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fje-suis-tm%2Fgraph-theory","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fje-suis-tm%2Fgraph-theory","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fje-suis-tm%2Fgraph-theory/lists"}