{"id":20231789,"url":"https://github.com/philipmw/linear-problems-learning","last_synced_at":"2025-07-05T19:14:54.052Z","repository":{"id":89532931,"uuid":"244248753","full_name":"philipmw/linear-problems-learning","owner":"philipmw","description":"Philip's progression of learning how to solve linear problems.","archived":false,"fork":false,"pushed_at":"2021-11-01T21:18:28.000Z","size":34,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-14T00:30:38.861Z","etag":null,"topics":["assignment-problem","linear-algebra","linear-programming","lpsolve"],"latest_commit_sha":null,"homepage":"","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/philipmw.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}},"created_at":"2020-03-02T00:47:36.000Z","updated_at":"2021-11-01T21:18:30.000Z","dependencies_parsed_at":null,"dependency_job_id":"3184f09a-26b0-467e-ad41-a42c36394b89","html_url":"https://github.com/philipmw/linear-problems-learning","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/philipmw%2Flinear-problems-learning","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/philipmw%2Flinear-problems-learning/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/philipmw%2Flinear-problems-learning/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/philipmw%2Flinear-problems-learning/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/philipmw","download_url":"https://codeload.github.com/philipmw/linear-problems-learning/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241678157,"owners_count":20001682,"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":["assignment-problem","linear-algebra","linear-programming","lpsolve"],"created_at":"2024-11-14T07:49:23.185Z","updated_at":"2025-03-03T14:10:07.682Z","avatar_url":"https://github.com/philipmw.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Philip's exploration of linear problems #\n\nThis is my playground for exploring how to express problems such that they be solved by a\n[linear solver](https://en.wikipedia.org/wiki/Linear_programming).\n\nMy goal with this project is to learn by challenging myself with progressively difficult\nlinear problems, and documenting it here for myself and maybe other LP neophytes.\n\nPlease collaborate with me, either through GitHub pull requests or by email.\nI'd love collaboration both in improving my understanding of linear problems and\nthe R code quality.\n\n## Background and terms used\n\nThe real-world problem that motivates me is assigning rowers to rowboats in the sport\nof [rowing](https://en.wikipedia.org/wiki/Rowing_(sport)).\n\nEach row boat has some number of seats for rowers.\nBoats range from a \"single\" (one rower) to an \"eight\", (eight rowers, one coxswain).\nRowing style can be [sweep](https://en.wikipedia.org/wiki/Sweep_rowing) or\n[sculling](https://en.wikipedia.org/wiki/Sculling).\nIn sweep rowing, each rower is on port or starboard side, and some rowers have a preference\nor a requirement (due to injury) for a specific side.\nLastly, different seats have differing responsibilities.\nSome rowers prefer those responsibilities, while other rowers avoid them.\n\nIdeally, the number of rowers fits exactly into available boats, so every seat\nis occupied. But often there is a mismatch.\nWhen there are empty seats, we \"sponge\" them: put a sponge in the rollers, so\nthe seat doesn't slide back and forth on the rollers during rowing.\nOn the other hand, when there is a small number of extra rowers, they ride\non the coaching launch to observe and maybe swap into someone's seat halfway\nthrough the practice.\n\nThis, assigning rowers to rowboats needs to take into consideration available boats, rower skill,\nand rower preferences.\n\nNormally, the coach does the assignment in an ad-hoc approach, using intuition.\nSometimes this is suboptimal yet takes a long time.\n\nI believe this problem can be efficiently solved by a computer.\n\n## Progression\n\nFor each script, see the comment block at the top for more info.\n\nProblems solved using `lp.assign()`:\n\n1. `simple quad lineup.R`: a super simple assignment problem where four rowers want to row a quad.\n   Each rower has an affinity for a specific seat, and we maximize the affinity.\n1. `port vs starboard.R`: one boat, and rowers have an affinity for port vs starboard.\n1. `quad and launch.R`: Instead of rowers having affinities for particular seats, rowers have\n   affinities for roles.  This better matches the real world. Now each seat of a boat has an\n   affinity for a role (such as 1-seat having an affinity for the bow role), and so the solver\n   tries to assign to 1-seat a rower who most has an affinity for the bow role.\n   This problem also adds a \"launch seat\" for extra rowers, which has no affinity.\n1. `sponges midboat.R`: seats define how important they are to be filled by a rower versus a sponge.\n1. `any quantity of rowers.R`: generate as many launch seats as needed to accommodate all rowers.\n1. `any quantity of boats.R`: generate as many sponges as needed to accommodate all seats.\n1. `frostbite.R`: an assignment problem for Greenlake Frostbite 2021.\n    This one is the most comprehensive so far. It supports real rowers and real boats,\n    sweep/scull preferences, port/starboard preferences, and stroke/bow preferences.\n    It fills extra seats with sponges, and it puts overflow rowers on a launch.\n    Lastly, it factors logic into separate functions to keep code clean.\n\nHere I've reached the limit of `lp.assign()` and reached for `lp()`:\n\n1. `two rowers three seats.R`: a small extension to an assignment problem, adding several constraints.\n    We have two rowers, and we have two boats: a double and a single.\n    One constraint forces some rower into a single.\n    Another forces two rowers into a double, preventing a situation where one of the double's seats is empty.\n\nMiscellaneous programs:\n\n1. `assignment matrix to list.R`: a large assignment matrix is unwieldy to read.\n   We know each row and column have exactly one 1, with the rest being 0. That's a lot of wasted visual space.\n   This small program converts the matrix to a list, taking only those row/col pairs having value 1.\n   The list is much easier to read.\n\n## Environment known to work\n\n* macOS Big Sur\n* R 4.1.1 (installed through Homebrew)\n\nOne-time setup in R:\n\n    install.packages(\"lpSolve\")\n\nRun one of these programs on the command line:\n\n    $ R --no-save --no-echo \u003c \"port vs starboard.R\"\n\n# References\n\n* [Assignment problem](https://en.wikipedia.org/wiki/Assignment_problem)\n* [Linear programming](https://en.wikipedia.org/wiki/Linear_programming)\n* [lpSolve documentation](https://cran.r-project.org/web/packages/lpSolve/lpSolve.pdf)\n* [Rowing (sport)](https://en.wikipedia.org/wiki/Rowing_(sport))","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphilipmw%2Flinear-problems-learning","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphilipmw%2Flinear-problems-learning","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphilipmw%2Flinear-problems-learning/lists"}