{"id":17968188,"url":"https://github.com/compnerd/cassowary","last_synced_at":"2025-03-25T08:31:57.736Z","repository":{"id":48378613,"uuid":"195471847","full_name":"compnerd/cassowary","owner":"compnerd","description":"A Swift implementation of the cassowary simplex solver","archived":false,"fork":false,"pushed_at":"2025-03-11T15:40:35.000Z","size":82,"stargazers_count":54,"open_issues_count":4,"forks_count":9,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-20T00:11:33.188Z","etag":null,"topics":["cassowary","constraint-solver","swift"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/compnerd.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":"2019-07-05T22:04:43.000Z","updated_at":"2025-03-08T14:16:52.000Z","dependencies_parsed_at":"2025-03-10T00:17:45.273Z","dependency_job_id":"7785f530-58f9-4dd3-86e8-dfc36e287ffa","html_url":"https://github.com/compnerd/cassowary","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/compnerd%2Fcassowary","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/compnerd%2Fcassowary/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/compnerd%2Fcassowary/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/compnerd%2Fcassowary/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/compnerd","download_url":"https://codeload.github.com/compnerd/cassowary/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245426475,"owners_count":20613372,"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":["cassowary","constraint-solver","swift"],"created_at":"2024-10-29T14:20:29.222Z","updated_at":"2025-03-25T08:31:57.720Z","avatar_url":"https://github.com/compnerd.png","language":"Swift","funding_links":[],"categories":["Swift"],"sub_categories":[],"readme":"# cassowary\n\nThis is a Swift implementation of the cassowary\u003csup id=\"a1\"\u003e[1](#f1)\u003c/sup\u003e\nsimplex solver inspired by the C++ implementation, Kiwi\u003csup id=\"a2\"\u003e[2](#f2)\u003c/sup\u003e.\n\n## Constraints\n\nCassowary supports linear equations and non-strict inequalities.  Additionally,\na strength may be associated with each constraint in the system, constrolling\nits importance to the overall solution to the system.\n\n### Defining Variables and Constraints\n\nVariables are the values which the solver is trying to resolve.  These\ncorrespond to the `Variable` type in the implementation.  The variables can be\nused to create the expressions which form constraints of the system.  These must\nbe added to an instance of the solver.\n\n```swift\nimport cassowary\n\nlet simplex: Solver = Solver()\n\nlet x_l: Variable = Variable(\"x_l\")\nlet x_r: Variable = Variable(\"x_r\")\nlet x_m: Variable = Variable(\"x_m\")\n\nsimplex.add(constraint: 2.0 * x_m == x_l + x_r)\nsimplex.add(constraint: x_l + 10.0 \u003c= x_r)\nsimplex.add(constraint: x_l \u003e= -10.0)\nsimplex.add(constraint: x_r \u003c= 100.0)\n```\n\nThis creates a system with three variables (x\u003csub\u003el\u003c/sub\u003e, x\u003csub\u003er\u003c/sub\u003e,\nx\u003csub\u003em\u003c/sub\u003e) representings points on a line segment.  x\u003csub\u003em\u003c/sub\u003e is\nconstrained to the midpoint between x\u003csub\u003el\u003c/sub\u003e and x\u003csub\u003er\u003c/sub\u003e,\nx\u003csub\u003el\u003c/sub\u003e is constrained to be at least 10 to the left of x\u003csub\u003er\u003c/sub\u003e, and\nall variables must lie in the range [-10, 100].  All constraints must be\nsatisfied and are considered as `required` by the cassowary algorithm.\n\n**NOTE** The same constraint in the same form cannot be added to the solver\nmultiply.  Redundant constraints, as per cassowary, are supported.  That is, the\nfollowing set of constraints can be added to the solver:\n\n```\nx     == 10\nx + y == 30\n    y == 20\n```\n\n### Managing Constraint Strength\n\nCassowary supports constraints which are not required but are handled as\nbest-effort.  Such a constraint is modelled as having a _strength_ other than\n`required`.  The constraints are considered in order of the value of their\nstrengths.  Three standard strengths are defined by default:\n1. `strong`\n1. `medium`\n1. `weak`\n\nWe can add a constraint to our previous example to place x\u003csub\u003em\u003c/sub\u003e at 50 by\nadding a new `weak` constraint:\n\n```swift\nsimplex.add(constraint: x_m == 50.0, strength: .weak)\n```\n\n### Edit Variables\n\nThe system described thus far has been static.  In order to find solutions for\nparticular value of x\u003csub\u003em\u003c/sub\u003e, Cassowary provides the concept of _edit\nvariables_ which allows you to suggest values for the variable before evaluating\nthe system.  These variables can have any strength other than `required`.\n\nContinuing our example, we could make x\u003csub\u003em\u003c/sub\u003e editable and suggest a value\nof `60` for it.\n\n```swift\nsimplex.add(variable: x_m, .strong)\nsimplex.suggest(value: 60.0, for: x_m)\n```\n\n### Solving and Updating Variables\n\nThis implementation solves the system each time a constraint is added or\nremoved, or when a new value is suggested for an edit variable.  However, the\nvariable values are not updated automatically and you must request the solver to\nupdate the values.\n\n```swift\nsimplex.suggest(value: 90, for: x_m)\nsimplex.update()\n```\n\n#\n\u003cb name=\"f1\"\u003e1\u003c/b\u003e https://constraints.cs.washington.edu/solvers/cassowary-tochi.pdf [↩](#a1)\u003cbr/\u003e\n\u003cb name=\"f2\"\u003e2\u003c/b\u003e https://github.com/nucleic/kiwi [↩](#a2)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcompnerd%2Fcassowary","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcompnerd%2Fcassowary","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcompnerd%2Fcassowary/lists"}