{"id":22089927,"url":"https://github.com/dhchenx/simplex-alg-js","last_synced_at":"2025-08-21T11:15:53.467Z","repository":{"id":137901261,"uuid":"286591954","full_name":"dhchenx/simplex-alg-js","owner":"dhchenx","description":"Simplex algorithm \u0026 Big M method in Javascript, Match-Picking Game","archived":false,"fork":false,"pushed_at":"2020-08-10T23:34:31.000Z","size":735,"stargazers_count":3,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-11T07:23:18.354Z","etag":null,"topics":["algorithm","big-m","html","javascript","match-picking","operations-research","simplex-algorithm"],"latest_commit_sha":null,"homepage":"","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dhchenx.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2020-08-10T22:34:47.000Z","updated_at":"2024-10-07T16:27:47.000Z","dependencies_parsed_at":null,"dependency_job_id":"93ec13fc-a197-4607-9e60-2c427905f5fe","html_url":"https://github.com/dhchenx/simplex-alg-js","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/dhchenx/simplex-alg-js","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dhchenx%2Fsimplex-alg-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dhchenx%2Fsimplex-alg-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dhchenx%2Fsimplex-alg-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dhchenx%2Fsimplex-alg-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dhchenx","download_url":"https://codeload.github.com/dhchenx/simplex-alg-js/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dhchenx%2Fsimplex-alg-js/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271469227,"owners_count":24765124,"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","status":"online","status_checked_at":"2025-08-21T02:00:08.990Z","response_time":74,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["algorithm","big-m","html","javascript","match-picking","operations-research","simplex-algorithm"],"created_at":"2024-12-01T02:14:44.979Z","updated_at":"2025-08-21T11:15:53.461Z","avatar_url":"https://github.com/dhchenx.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Simplex algorithm \u0026 Big M method in JavaScript\n\n\u003e Developed by Donghua Chen, Beijing Jiaotong University\n\nSource codes: (1) [Simplex Algorithm in JavaScript](Simplex-Algorithm.htm); (2) [Match-Picking Game](Match-PickingGame.htm).\n\n## Overview\n**Management Operations Research** is a very useful course, which contains various kinds of useful management and operations research algorithm. Through the program designing, we apply our knowledge to solve the problem by programming based on the algorithm in the textbook, and then it can help us to know better about the true meaning and spirit of different algorithm in operations research. This program reports contains two part of program: A common solving program based on the Simplex Algorithm \u0026 Big M Method and A game of picking matches. The programs adopt the JavaScript program language, which is easy to run in any platform with a browser.\n\n## History\nThis project hosts the source codes of my undergraduate study about Operations Research. The project contains two algorithms' implementation, namely, Simplex algorithm and **Pick Matches Game** based on the Big M method.\n\nThe most interesting part of this project is that their algorithms are designed in JavaScript, a lightweight computer programming language usually used in web browsers for displaying web pages. It also means you can run the algorithm simply by open the HTML source file in your web browsers. And it works perfectly. No IDE, no compiler!\n\n## Simplex Algorithm \u0026 Big M Method\n\n### Program design\nThe algorithms adopted by this program are all based on the simple simplex method in the book and the solving algorithm of the big M method. The overall design process of this program is that the user enters the number of variables and constraints → the user enters the variable coefficients in the objective function and constraint equations automatically generated by the software → the user clicks the button to let the software automatically complete the program solving process → the program gives the final series The solved simplex table and the final solution.\n\nCore code:\n```js\nfunction InitTable() {\n        var t = new Array();\n        var Count = parseInt(VN);\n        //obtain total counts of table\n        for (i = 0; i \u003c CN; i++) {\n            s = document.getElementById(\"equ\" + i).options[document.getElementById(\"equ\" + i).selectedIndex].text;\n            if (s == \"\u003c=\") {\n                Count++;\n            }\n            if (s == \"\u003e=\") {\n                Count = Count + 2;\n            }\n            if (s == \"=\") {\n                Count++;\n            }\n        }\n        Count = Count + 1; //add z var\n        //simplify function\n        for (j = 1; j \u003c= VN; j++) {\n…\n        }\n        for (k = j; k \u003c Count; k++) {\n            t[0][k] = 0;\n        }\n        //handle table header\n        for (k = 1; k \u003c= VN; k++) {\n        }\n        //handle constraints\n        var index;\n        index = 1;\n        for (i = 1; i \u003c= CN; i++) {\n            t[i] = new Array(Count);\n            t[i][0] = 0;\n            for (j = 1; j \u003c Count; j++) {\n                if (j \u003c= VN) {\n                   …\n                }\n                if (j \u003e VN) {\n…\n                }\n            }\n            bb = document.getElementById(\"equ\" + (i - 1)).options[document.getElementById(\"equ\" + (i - 1)).selectedIndex].text;\n            if (bb == \"\u003c=\") {\n             …\n            }\n            if (bb == \"\u003e=\") {\n              …\n            }\n            if (bb == \"=\") {\n        …\n            }\n        }\n        ////////////////////////////////////////////////////////\n        a = new Array(parseFloat(CN) + 1);\n        for (i = 0; i \u003c a.length; i++) {\n            a[i] = new Array(Count - 1);\n        }\n        b = new Array(parseFloat(CN) + 1); \n        row = parseFloat(CN) + 1;\n        col = Count - 1;\n        M = new Array(col+1);\n        //////////////////////////////////////////////\n        for (i = 0; i \u003c row; i++) {\n            for (j = 0; j \u003c col; j++) {\n                a[i][j] = t[i][j + 1];\n            }\n            b[i] = rhs[i];\n        }\n        //////////////////////////////////////////\n        var te;\n        for(i=0;i\u003ccol+1;i++)\n        M[i]=0;\n        for (j = 0; j \u003c col; j++) {\n            if (a[0][j] == \"M\"||a[0][j]==\"-M\") {\n              …\n                }\n            }\n        }\n        showtable();\n    }\n\n```\n\n### Demo of simplex algorithm\n(1) Enter the number of variables and the number of constraints, and select the type of objective function to be solved.\n \n![step 1](simplex/figure1.jpg)\n\n(2) Click the button Create Table, and enter the relevant parameters in the objective function and constraint input box automatically generated by the software, as shown in the figure below:\n \n![step 2](simplex/figure2.jpg)\n\n(3) Click the button InitTable to initialize the simplex table, as shown in the figure below.\n \n![step 3](simplex/figure3.jpg)\n\n(4) Click the Do button, and then a prompt box will pop up, prompting you to obtain the optimal solution.\n \n![step 14](simplex/figure4.jpg)\n\n(5) To obtain the optimal solution of the operation, enter a series of tables, and the final table is the optimal solution.\n \n![step 5](simplex/figure5.jpg)\n\nFrom the last table, we can find the optimal solution (x1, x2, s1, s2)=(3.5, 1.5, 7.5, 0, 0), which is exactly the same as the book result, which verifies the correctness of the algorithm design.\n\n### Demo of the Big M method\n\n![step 6](simplex/figure6.jpg)\n\nFinally, we get the optimal solution (x1,x2,s1,e2,a2,e3)=(5,5,0.25,0,0,0), which is exactly the same as the result of the sample problem in the book, so it verifies that the big M in the program The correctness of law design.\n\n## Match-picking Game\nThe idea of this match-picking game is derived from the recursive part of the dynamic programming in the English textbook of Operations Research. The match-picking game there is a single-player-to-computer game, and the match-picking game in this report is a two-player game. The core idea is still the principle of recursion, but this recursion is stepwise. The interface of the program is shown in the figure below:\n\n ![step 0](match-picking/figure1.jpg)\n\n Core code:\n ```js\nfunction init() {\n                t1.value = 1;\n                t2.value = 1;\n                matches = parseInt(count.value);\n                curr = parseInt(tt.value);\n                if (curr == 1) {\n                    b1.disabled = false;\n                    b2.disabled = true;\n                } else {\n                    b1.disabled = true;\n                    b2.disabled = false;\n                }\n                ad.innerHTML = \"Initial Count = \" + matches+\"\u003c/br\u003e\";\n            }\n            function pick() {\n                var t = 0;\n                if (curr == 1) {\n                    t = parseInt(t1.value)\n                    if (!(t \u003c= 3 \u0026\u0026 t \u003e= 1)) {\n                        alert(\"the picked matches must be between 1 and 3\");\n                        return;\n                    }\n                    matches -= t;\n                    curr = 2;\n                    t1.value = 1;\n                    b1.disabled = true;\n                    b2.disabled = false;\n                } else {\n                    t = parseInt(t2.value)\n                    if (!(t \u003c= 3 \u0026\u0026 t \u003e= 1)) {\n                        alert(\"the picked matches must be between 1 and 3\");\n                        return;\n                    }\n                    matches -= t;\n                    curr = 1;\n                    t2.value = 1;\n                    b1.disabled = false;\n                    b2.disabled = true;  \n                }\n                     if (curr == 2) {\n                ad.innerHTML += \"*Player \u003ci\u003e1\u003c/i\u003e Selected \u003cb\u003e\" + t + \"\u003c/b\u003e matches\u003cbr/\u003e\";\n                } else {\n                ad.innerHTML += \"*Player \u003ci\u003e2\u003c/i\u003e Selected \u003cb\u003e\" + t + \"\u003c/b\u003e matches;\u003cbr/\u003e \";\n            }\n            count.value = matches;\n            if (matches \u003c= 1) {\n                if (curr == 2) {\n                    alert(\"Player 2 lose\");\n                    ad.innerHTML += \"Player 2 lose!\";\n                    return;\n                } else {\n                ad.innerHTML += \"Player 1 lose\";\n                    alert(\"Player 1 lose!\");\n                    return;\n                }\n            }\n            }\n\n ```\n\nLet's demonstrate how to play the game.\n(1) First set the relevant parameters of the game.\n\n ![step 1](match-picking/figure2.jpg)\n\nWe set the total number of matches in the game to 10, and Player 1 picks it first. Then we get the following game interface:\n\n ![step 2](match-picking/figure3.jpg)\n \n(2) Player 1 first picks up matches. First, Player1 enters the number of matches to be picked up into the text box, press Player 1, and then it is Player2's turn, as shown in the figure below:\n\n ![step 3](match-picking/figure4.jpg)\n \nThen Player 2 enters the number of matches to be picked, and clicks the button to alternate.\n\n(3) When the last match is left, a dialog box pops up to remind who has lost.\n\n\n## Conclusions\nOperations research itself is an important question, and its essential role is very large in today's society, but only through the combination of theory and practice and applying the knowledge of books to practice, what we have learned will become alive. The programming implementation of the relevant algorithms of the course, what we learned is not only the boring knowledge in the books, but also the ability to use knowledge across disciplines, combining programming and operations research theory, and showing strong vitality through our course practice .\n\n## LICENES\nThis project is under [GPL-2.0 License](LICENSE). ","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdhchenx%2Fsimplex-alg-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdhchenx%2Fsimplex-alg-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdhchenx%2Fsimplex-alg-js/lists"}