项目作者: relund

项目描述 :
2D and 3D plots of linear/integer programming models in R
高级语言: HTML
项目地址: git://github.com/relund/gMOIP.git
创建时间: 2017-01-21T23:59:20Z
项目社区:https://github.com/relund/gMOIP

开源协议:

下载


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
nondominated (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
(nondominated) points in $\mathbb{R}_n$ and classifying nondominated
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:

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

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

  1. plotPolytope(
  2. A,
  3. b,
  4. coeff,
  5. type = rep("c", ncol(A)),
  6. crit = "max",
  7. faces = rep("c", ncol(A)),
  8. plotFaces = TRUE,
  9. plotFeasible = TRUE,
  10. plotOptimum = TRUE,
  11. labels = "coord"
  12. )

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

  1. plotPolytope(
  2. A,
  3. b,
  4. coeff,
  5. type = rep("i", ncol(A)),
  6. crit = "max",
  7. faces = rep("c", ncol(A)),
  8. plotFaces = TRUE,
  9. plotFeasible = TRUE,
  10. plotOptimum = TRUE,
  11. labels = "coord"
  12. )

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

  1. plotPolytope(
  2. A,
  3. b,
  4. coeff,
  5. type = c("i", "c"),
  6. crit = "max",
  7. faces = c("c", "c"),
  8. plotFaces = TRUE,
  9. plotFeasible = TRUE,
  10. plotOptimum = TRUE,
  11. labels = "coord"
  12. )

You can do the same with three variables:

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


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

  1. library(tikzDevice)
  2. tikz(file = "plot_polytope.tex", standAlone=F, width = 7, height = 6)
  3. plotPolytope(
  4. A,
  5. b,
  6. coeff,
  7. type = rep("i", ncol(A)),
  8. crit = "max",
  9. faces = rep("c", ncol(A)),
  10. plotFaces = TRUE,
  11. plotFeasible = TRUE,
  12. plotOptimum = TRUE,
  13. labels = "coord"
  14. )
  15. dev.off()

Installation

Install the latest stable release from CRAN:

  1. install.packages("gMOIP")

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

  1. install.packages("remotes")
  2. remotes::install_github("relund/gMOIP")
  3. library(gMOIP)
  4. browseVignettes('gMOIP')
  5. 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).