-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathREADME.Rmd
186 lines (151 loc) · 4.97 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
---
always_allow_html: true
output:
github_document
editor_options:
chunk_output_type: console
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include=FALSE}
library(knitr)
library(rgl)
if (interactive()) setwd(dirname(rstudioapi::getActiveDocumentContext()$path))
rgl::setupKnitr()
opts_chunk$set(
collapse = TRUE,
#comment = "#>",
fig.path = "man/figures/README-",
out.width = "99%", fig.width = 8, fig.align = "center", fig.asp = 0.62,
echo = TRUE, warning=FALSE, message=FALSE,
include = TRUE
)
library(gMOIP)
```
<!-- badges: start -->
[![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/gMOIP)](https://CRAN.R-project.org/package=gMOIP)
[![CRAN_Downloads_Badge](http://cranlogs.r-pkg.org/badges/grand-total/gMOIP?color=brightgreen)](http://cranlogs.r-pkg.org/downloads/total/last-month/gMOIP)
[![R build status](https://github.com/relund/gMOIP/workflows/R-CMD-check/badge.svg)](https://github.com/relund/gMOIP/actions)
<!-- badges: end -->
# 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:
```{r model}
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$):
```{r lp}
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$):
```{r ilp}
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:
```{r milp}
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:
```{r}
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)
```
```{r 3d, include=TRUE}
# 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")
```
```{r, include=FALSE}
movie3d(spin3d(), duration = 10, type="gif", dir="./man/figures", movie = "README-3d", convert = NULL)
```
<center>
![](man/figures/README-3d.gif)
</center>
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](https://relund.github.io/gMOIP/) 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
```{r, eval=FALSE}
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:
```{r, eval=FALSE}
install.packages("gMOIP")
```
Alternatively, install the latest development version from GitHub (recommended):
```{r, eval=FALSE}
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)`.