{"id":17719902,"url":"https://github.com/specy/rooc","last_synced_at":"2025-04-06T06:06:49.456Z","repository":{"id":176966181,"uuid":"657697913","full_name":"Specy/rooc","owner":"Specy","description":"An optimization modeling language with solvers for MILP problems","archived":false,"fork":false,"pushed_at":"2025-03-02T18:02:52.000Z","size":3774,"stargazers_count":48,"open_issues_count":13,"forks_count":2,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-03-30T05:03:42.360Z","etag":null,"topics":["compiler","interpreter","linear-programming","math","optimization","rust","simplex","sveltekit","wasm"],"latest_commit_sha":null,"homepage":"https://rooc.specy.app","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Specy.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":"2023-06-23T16:22:45.000Z","updated_at":"2025-03-07T06:32:34.000Z","dependencies_parsed_at":"2023-10-27T15:31:21.979Z","dependency_job_id":"7abc5300-9723-419e-99e6-7d1f854ce2c2","html_url":"https://github.com/Specy/rooc","commit_stats":{"total_commits":266,"total_committers":1,"mean_commits":266.0,"dds":0.0,"last_synced_commit":"3a1233d46cd98ac769518801bb4a5b8ba883c9bd"},"previous_names":["specy/rooc"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Specy%2Frooc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Specy%2Frooc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Specy%2Frooc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Specy%2Frooc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Specy","download_url":"https://codeload.github.com/Specy/rooc/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247441042,"owners_count":20939239,"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":["compiler","interpreter","linear-programming","math","optimization","rust","simplex","sveltekit","wasm"],"created_at":"2024-10-25T15:13:25.876Z","updated_at":"2025-04-06T06:06:49.438Z","avatar_url":"https://github.com/Specy.png","language":"Rust","readme":"\u003cdiv align=\"center\"\u003e\n  \u003ch1\u003e\u003ccode\u003eROOC\u003c/code\u003e\u003c/h1\u003e\n  \u003cimg src='./logo-original.png' width='156px'/\u003e\n  \u003cp\u003e\u003cstrong\u003eOptimization modeling language\u003c/strong\u003e\u003c/p\u003e\n\u003c/div\u003e\n\n[![Crates.io](https://img.shields.io/crates/v/rooc.svg)](https://crates.io/crates/rooc)\n[![npm](https://img.shields.io/npm/v/@specy/rooc.svg)](https://www.npmjs.com/package/@specy/rooc)\n\n[Go to the language documentation](https://rooc.specy.app/docs/rooc)\n\n[Go to the library documentation](https://rooc.specy.app/docs/rooc)\n\n[Go to the rooc web modeling platform](https://rooc.specy.app/)\n\n\n**ROOC** stands for the courses I took in university—*Ricerca Operativa* (Operational Research) and *Ottimizzazione Combinatoria* (Combinatorial Optimization)—which deal with solving optimization models.\n\n# What it is\n**ROOC** is a modeling language designed to write formal optimization models, and together with data, transform it into a linear model which can then be solved using optimization techniques. \n\nThe language provides support for defining formal models, including functions, constants, arrays, graphs, tuples, etc... It also includes built-in utility functions for iterating over graphs, edges, arrays, ranges, and more.\n\nIf you just want to solve a problem, you can use the [web platform](https://rooc.specy.app) or implement your own through the [rust lib](https://crates.io/crates/rooc) or [typescript lib](https://www.npmjs.com/package/@specy/rooc)\n# Examples\n\nFor examples of models [look in the rooc docs](https://rooc.specy.app/docs/rooc/examples)\n\nHere is an example of the knapsack problem modeled in ROOC and solved through the rust library.\n\nIt shows most of the feature of the library and language, adding data, and solving the model with a binary solver\n```rust\n    let source = \"\n    max sum((value, i) in enumerate(values)) { value * x_i }\n    s.t.\n        sum((weight, i) in enumerate(weights)) { weight * x_i } \u003c= capacity\n    define\n        x_i as Boolean for i in 0..len(weights)\";\n\n    let constants = vec![\n        Constant::from_primitive(\n            \"weights\",\n            IterableKind::Integers(vec![10, 60, 30, 40, 30, 20, 20, 2]).into_primitive(),\n        ),\n        Constant::from_primitive(\n            \"values\",\n            IterableKind::Integers(vec![1, 10, 15, 40, 60, 90, 100, 15]).into_primitive(),\n        ),\n        Constant::from_primitive(\"capacity\", Primitive::Integer(102)),\n    ];\n    //in case you want to define your own functions that will be used during compilation\n    let fns: FunctionContextMap = IndexMap::new();\n\n\n    let solver = RoocSolver::try_new(source.to_string()).unwrap();\n\n    //use the built in solvers or make your own\n    let solution = solver\n        .solve_with_data_using(solve_binary_lp_problem, constants, \u0026fns)\n        .unwrap();\n\n    println!(\"{}\", solution);\n```\n\n\nFor more examples of using the rust lib look at the [examples folder](https://github.com/Specy/rooc/tree/main/examples)\n\n\n## Solvers\nCurrently in ROOC you can solve any linear models which can be:\n- MILP\n- Integer or binary only\n- Binary only\n- Real only \n\n# Modeling Example\nGiven the formal model of the [Dominating set](https://en.wikipedia.org/wiki/Dominating_set) problem, let's model it using graphs:\n```lua\nmin sum(u in nodes(G)) { x_u }\ns.t. \n    x_v + sum((_, u) in neigh_edges(v)) { x_u } \u003e= 1 for v in nodes(G)\nwhere\n    let G = Graph {\n        A -\u003e [B, C, D, E, F],\n        B -\u003e [A, E, C, D, J],\n        C -\u003e [A, B, D, E, I],\n        D -\u003e [A, B, C, E, H],\n        E -\u003e [A, B, C, D, G],\n        F -\u003e [A, G, J],\n        G -\u003e [E, F, H],\n        H -\u003e [D, G, I],\n        I -\u003e [C, H, J],\n        J -\u003e [B, F, I]\n    }\ndefine\n    x_u, x_v as Boolean for v in nodes(G), (_, u) in neigh_edges(v)\n```\nIt is compiled down to:\n```lua\nmin x_A + x_B + x_C + x_D + x_E + x_F + x_G + x_H + x_I + x_J\ns.t.\n        x_A + x_B + x_D + x_C + x_F + x_E \u003e= 1\n        x_B + x_D + x_E + x_J + x_C + x_A \u003e= 1\n        x_C + x_B + x_D + x_I + x_A + x_E \u003e= 1\n        x_D + x_E + x_H + x_C + x_A + x_B \u003e= 1\n        x_E + x_B + x_D + x_C + x_A + x_G \u003e= 1\n        x_F + x_J + x_G + x_A \u003e= 1\n        x_G + x_E + x_F + x_H \u003e= 1\n        x_H + x_D + x_I + x_G \u003e= 1\n        x_I + x_J + x_H + x_C \u003e= 1\n        x_J + x_F + x_I + x_B \u003e= 1\n```\nThe model can then be solved using the `Binary solver` pipeline, which will solve the compiled model and find the optimal solution which has value `3` with assignment:\n```\nF\tF\tF\tF\tT\tF\tF\tF\tT\tT\n```\n\n# Implemented Features \n- [x] Language\n  - [x] Static block functions (min, max, mod, avg)\n  - [x] Constant Graph definitions\n  - [x] Iterators\n  - [x] Tuples\n  - [x] Iterators utility functions (for graphs, edges, etc)\n  - [x] Primitive destructuring\n  - [x] Constants and multi dimensional arrays in the formal definition of a problem\n  - [x] Other utility functions\n  - [x] Error logging and parameter validation \n  - [x] Error traces\n  - [x] Primitives Operator overloading (for example, `+` for strings)\n  - [x] Definition of variable bounds\n  - [x] Javascript defined functions, define js functions to use in the model\n- [x] Simplex resolution\n  - [x] Linearization of a generic problem (done except for mod operator)\n  - [x] Transformation of a linear problem into the standard form\n  - [x] Two step method using artifical variables to find a valid basis for the standard form problem\n  - [x] Simplex to find the optimal solution of a standard form linear problem\n- [ ] Integer and binary problems resolution\n  - [x] Integer and binary problem definitions (bounds)\n  - [x] Integer solvers\n  - [x] Binary problem solution\n  - [x] Integer/Binary problem solution\n  - [x] MILP problem solution\n  - [ ] Logic constraints\n- [x] UI\n  - [x] Compilation to WASM\n  - [x] Create and manage your models\n  - [x] Automatic compilation to a LATEX block\n  - [x] LSP\n    - [x] Syntax errors\n    - [x] Hover types\n    - [x] Type errors\n    - [x] Code completion\n  - [x] Language documentation \n  - [x] Show the different steps of solving the problem\n  - [x] List of modifications from the start of the problem to the end of the solution\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspecy%2Frooc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspecy%2Frooc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspecy%2Frooc/lists"}