{"id":21028522,"url":"https://github.com/dirkschumacher/optplot","last_synced_at":"2025-12-28T12:44:40.444Z","repository":{"id":145906672,"uuid":"132023678","full_name":"dirkschumacher/optplot","owner":"dirkschumacher","description":"An R package for plotting optimization problems/models","archived":false,"fork":false,"pushed_at":"2018-05-03T19:26:55.000Z","size":136,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-10T15:11:30.975Z","etag":null,"topics":["mixed-integer-programming","plot","r","visualization"],"latest_commit_sha":null,"homepage":"","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dirkschumacher.png","metadata":{"files":{"readme":"README.Rmd","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":"2018-05-03T16:43:14.000Z","updated_at":"2023-07-25T14:16:50.000Z","dependencies_parsed_at":null,"dependency_job_id":"43b020fd-c4e0-4a0b-b167-bb3fcdb8c924","html_url":"https://github.com/dirkschumacher/optplot","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/dirkschumacher%2Foptplot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dirkschumacher%2Foptplot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dirkschumacher%2Foptplot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dirkschumacher%2Foptplot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dirkschumacher","download_url":"https://codeload.github.com/dirkschumacher/optplot/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243467024,"owners_count":20295309,"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":["mixed-integer-programming","plot","r","visualization"],"created_at":"2024-11-19T11:56:05.738Z","updated_at":"2025-12-28T12:44:40.382Z","avatar_url":"https://github.com/dirkschumacher.png","language":"R","readme":"---\noutput: github_document\n---\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n```{r setup, include = FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  comment = \"#\u003e\",\n  fig.path = \"man/figures/README-\",\n  out.width = \"100%\"\n)\n```\n# optplot\n\nThe goal of `optplot` is provide functions to plot optimization problems/models such as mixed-integer linear programs. Work in progress. Contributions welcome.\n\n[![Travis build status](https://travis-ci.org/dirkschumacher/optplot.svg?branch=master)](https://travis-ci.org/dirkschumacher/optplot)\n[![lifecycle](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental)\n[![CRAN status](https://www.r-pkg.org/badges/version/optplot)](https://cran.r-project.org/package=optplot)\n\n## Installation\n\nYou can install the released version of optplot from [CRAN](https://CRAN.R-project.org) with:\n\n``` r\ninstall.packages(\"optplot\")\n```\n\nAnd the development version from [GitHub](https://github.com/) with:\n\n``` r\n# install.packages(\"devtools\")\ndevtools::install_github(\"dirkschumacher/optplot\")\n```\n## Example\n\nThis is a basic example which shows you how to plot the popular Travling Salesperson Problem. It uses the `ompr` package to model the MILP.\n\n```{r example}\n# based on the Miller–Tucker–Zemlin (MTZ) formulation\n# More info here: https://www.unc.edu/~pataki/papers/teachtsp.pdf)\nlibrary(ompr)\nlibrary(magrittr)\nset.seed(1234)\nn \u003c- 10\nmodel \u003c- MILPModel() %\u003e%\n  # we create a variable that is 1 iff we travel from city i to j\n  add_variable(x[i, j], i = 1:n, j = 1:n, \n               type = \"integer\", lb = 0, ub = 1) %\u003e%\n  \n  # a helper variable for the MTZ formulation of the tsp\n  add_variable(u[i], i = 1:n, lb = 1, ub = n) %\u003e% \n  \n  # minimize travel distance\n  set_objective(sum_expr(colwise(runif(n^2)) * x[i, j], i = 1:n, j = 1:n), \"min\") %\u003e%\n  \n  # you cannot go to the same city\n  set_bounds(x[i, i], ub = 0, i = 1:n) %\u003e%\n  \n  # leave each city\n  add_constraint(sum_expr(x[i, j], j = 1:n) == 1, i = 1:n) %\u003e%\n  #\n  # visit each city\n  add_constraint(sum_expr(x[i, j], i = 1:n) == 1, j = 1:n) %\u003e%\n  \n  # ensure no subtours (arc constraints)\n  add_constraint(u[i] \u003e= 2, i = 2:n) %\u003e% \n  add_constraint(u[i] - u[j] + 1 \u003c= (n - 1) * (1 - x[i, j]), i = 2:n, j = 2:n)\n```\n\n\nHaving defined the model, we can extract the constraint matrix $A$, the right hand side vector $b$ and the objective coefficent vector $c$.\n\n```{r}\nmat \u003c- ompr::extract_constraints(model)\nA \u003c- mat$matrix\nb \u003c- mat$rhs\ncv \u003c- ompr::objective_function(model)$solution\n```\n\n\n```{r milp-plot}\noptplot::milp_plot(A, b, cv)\n```\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdirkschumacher%2Foptplot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdirkschumacher%2Foptplot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdirkschumacher%2Foptplot/lists"}