GithubHelp home page GithubHelp logo

relund / gmoip Goto Github PK

View Code? Open in Web Editor NEW
5.0 3.0 2.0 215.39 MB

2D and 3D plots of linear/integer programming models in R

Home Page: https://relund.github.io/gMOIP/

R 18.89% HTML 78.66% TeX 1.66% Asymptote 0.79%
math linear-programming integer-programming bi-objective mixed-integer-programming visualization r r-package 3d-plot 2d-plot

gmoip's Introduction

CRAN_Status_Badge CRAN_Downloads_Badge R build status

Tools for 2D and 3D plots of single and multi-objective linear/integer programming models

The gMOIP package can be used to make 2D and 3D plots of linear programming (LP), integer linear programming (ILP), or mixed integer linear programming (MILP) models with up to three objectives. This include the polytope, integer points, ranges and iso profit curve. Plots of both the solution and criterion space are possible. For instance the non-dominated (Pareto) set for bi-objective LP/ILP/MILP programming models.

The package also include an inHull function for checking if a set of points is inside/at/outside the convex hull of a set of vertices (for arbitrary dimension).

Finally, the package also contains functions for generating (non-dominated) points in $\mathbb{R}_n$ and classifying non-dominated points as supported extreme, supported non-extreme and unsupported.

Usage

Consider the model $\max{cx | Ax \leq b}$ (could also be minimized) with 2 variables:

A <- matrix(c(-3,2,2,4,9,10), ncol = 2, byrow = TRUE)
b <- c(3,27,90)
coeff <- c(7.75, 10)  # coefficients c

The polytope of the LP model with non-negative continuous variables ($x \geq 0$):

plotPolytope(
   A,
   b,
   coeff,
   type = rep("c", ncol(A)),
   crit = "max",
   faces = rep("c", ncol(A)),
   plotFaces = TRUE,
   plotFeasible = TRUE,
   plotOptimum = TRUE,
   labels = "coord"
)

The polytope of the ILP model with LP faces ($x\in \mathbb{Z}_0$):

plotPolytope(
   A,
   b,
   coeff,
   type = rep("i", ncol(A)),
   crit = "max",
   faces = rep("c", ncol(A)),
   plotFaces = TRUE,
   plotFeasible = TRUE,
   plotOptimum = TRUE,
   labels = "coord"
)

The polytope of the MILP model (first variable integer) with LP faces:

plotPolytope(
   A,
   b,
   coeff,
   type = c("i", "c"),
   crit = "max",
   faces = c("c", "c"),
   plotFaces = TRUE,
   plotFeasible = TRUE,
   plotOptimum = TRUE,
   labels = "coord"
)

You can do the same with three variables:

A <- matrix( c(
   3, 2, 5,
   2, 1, 1,
   1, 1, 3,
   5, 2, 4
), nc = 3, byrow = TRUE)
b <- c(55, 26, 30, 57)
coeff <- c(20, 10, 15)
# LP model
view <- matrix( c(-0.412063330411911, -0.228006735444069, 0.882166087627411, 0, 0.910147845745087,
                  -0.0574885793030262, 0.410274744033813, 0, -0.042830865830183, 0.97196090221405,
                  0.231208890676498, 0, 0, 0, 0, 1), nc = 4)   
loadView(v = view)  # set view angle
plotPolytope(A, b, plotOptimum = TRUE, obj = coeff, labels = "n")
![](man/figures/README-3d.gif)

Note: interactive 3d plots cannot be displayed in a GitHub README file, and static images or animated gifs are used here instead. Visit the pkgdown online documentation to view plots which can be manipulated in the browser.

For more examples see example("gMOIP-package") or browseVignettes('gMOIP').

LaTeX support

You may create a TikZ file of the plot for LaTeX using

library(tikzDevice)
tikz(file = "plot_polytope.tex", standAlone=F, width = 7, height = 6)
plotPolytope(
   A,
   b,
   coeff,
   type = rep("i", ncol(A)),
   crit = "max",
   faces = rep("c", ncol(A)),
   plotFaces = TRUE,
   plotFeasible = TRUE,
   plotOptimum = TRUE,
   labels = "coord"
)
dev.off()

Installation

Install the latest stable release from CRAN:

install.packages("gMOIP")

Alternatively, install the latest development version from GitHub (recommended):

install.packages("remotes")
remotes::install_github("relund/gMOIP")

library(gMOIP)
browseVignettes('gMOIP')
example("gMOIP-package")

The package is highly dependent on the {rgl} package for plotting 3D graphics. If your build of {rgl} does not include OpenGL functions, use rgl::rglwidget() to display results, e.g. via options(rgl.printRglwidget = TRUE).

gmoip's People

Contributors

dmurdoch avatar relund avatar scottkosty avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

gmoip's Issues

Replacing eaf with moocore

Dear Lars,

I am planning to retire the eaf package and separate its functionality into two packages: moocore, which will have very few dependencies, and mooplot, which will handle plotting and interactivity.

In your case, it will be a matter of replacing eaf by moocore since the same function is_nondominated is in moocore.

It will still take a few months to get moocore into CRAN, but I wanted to let you know in advance.

inHull(): tol argument not taken into account in some cases

I just tested current master (98adb11). One issue I noticed is that the value of the tol argument to inHull() is not taken into account in some cases. Here is an example:

library("gMOIP")
pt_ <- c(9.01, 9)
v_ <- matrix(c(3,3, 8,8, 9,9),
              byrow = TRUE,
	      ncol = 2)
inHull(pts = pt_, vertices = v_, tol = 1e10)

The above returns -1 for me, where I expect it to return 0 since the value for tol is large.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.