library(knitr) library(rgl) rgl::setupKnitr() options(rgl.useNULL=TRUE) opts_chunk$set( collapse = TRUE, #comment = "#>", warning=FALSE, message=FALSE, include = TRUE, out.width = "99%", fig.width = 8, fig.align = "center", fig.asp = 0.62 ) if (!requireNamespace("rmarkdown", quietly = TRUE) || !rmarkdown::pandoc_available("1.14")) { warning(call. = FALSE, "These vignettes assume rmarkdown and pandoc version 1.14 (or higher). These were not found. Older versions will not work.") knitr::knit_exit() }
With gMOIP
you can make 3D plots of the polytope/feasible region/solution space of a linear programming (LP), integer linear programming (ILP) model, or mixed integer linear programming (MILP) model. This vignette gives examples on how to make plots given a model with three variables.
First we load the package:
library(gMOIP)
We define the model:
A <- matrix( c( -1, 1, 0, 1, 4, 0, 2, 1, 0, 3, -4, 0, 0, 0, 4 ), nc = 3, byrow = TRUE) b <- c(5, 45, 27, 24, 10) obj <- c(5, 45, 15)
We load the preferred view angle for the RGL window:
view <- matrix( c(0.976349174976349, -0.202332556247711, 0.0761845782399178, 0, 0.0903248339891434, 0.701892614364624, 0.706531345844269, 0, -0.196427255868912, -0.682940244674683, 0.703568696975708, 0, 0, 0, 0, 1), nc = 4)
The LP polytope:
loadView(v = view, close = F, zoom = 0.75) plotPolytope(A, b, plotOptimum = TRUE, obj = obj, labels = "coord")
Note you can zoom/turn/twist the figure with your mouse (rglwidget
).
The ILP model (note since the vertices are integer the LP and ILP faces are equal):
loadView(v = view, close = F, zoom = 0.75) plotPolytope(A, b, faces = c("c","c","c"), type = c("i","i","i"), plotOptimum = TRUE, obj = obj, argsTitle3d = list(main = "With LP faces"), argsPlot3d = list(box = F, axes = T) )
Let us have a look at some MILP models (we use static images). MILP model with variable 1 and 3 integer:
loadView(v = view, close = T, zoom = 0.75) plotPolytope(A, b, faces = c("c","c","c"), type = c("i","c","i"), plotOptimum = TRUE, obj = obj)
MILP model with variable 2 and 3 integer:
loadView(v = view, zoom = 0.75) plotPolytope(A, b, faces = c("c","c","c"), type = c("c","i","i"), plotOptimum = TRUE, obj = obj)
MILP model with variable 1 and 2 integer:
loadView(v = view, zoom = 0.75) plotPolytope(A, b, faces = c("c","c","c"), type = c("i","i","c"), plotOptimum = TRUE, obj = obj)
MILP model with variable 1 integer:
loadView(v = view, zoom = 0.75) plotPolytope(A, b, type = c("i","c","c"), plotOptimum = TRUE, obj = obj, plotFaces = FALSE)
MILP model with variable 2 integer:
loadView(v = view, zoom = 0.75) plotPolytope(A, b, type = c("c","i","c"), plotOptimum = TRUE, obj = obj, plotFaces = FALSE)
MILP model with variable 3 integer:
loadView(v = view, zoom = 0.75) plotPolytope(A, b, type = c("c","c","i"), plotOptimum = TRUE, obj = obj, plotFaces = FALSE)
rm(list = ls(all.names = TRUE))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.