Commit 58393d8e by Weigert, Andreas

### changed file name

parent 0a18f092
No preview for this file type
 --- title: 'Tutorial 14: Optimization' output: html_notebook editor_options: chunk_output_type: inline --- This file is part of the lecture Business Intelligence & Analytics (EESYS-BIA-M), Information Systems and Energy Efficient Systems, University of Bamberg. ```{r} library(lpSolve) library(ggplot2) ``` ```{r lpSolve default example} # # Set up problem: maximize # x1 + 9 x2 + x3 subject to # x1 + 2 x2 + 3 x3 <= 9 # 3 x1 + 2 x2 + 2 x3 <= 15 # objective.in <- c(1, 9, 1) const.mat <- matrix(c(1, 2, 3, 3, 2, 2), nrow=2, byrow=TRUE) direction <- c("<=", "<=") const.rhs <- c(9, 15) direction <- "max" lp (direction, f.obj, f.con, f.dir, f.rhs) ``` ```{r The Stratton Company Case - Graphical solution} # Set up problem: maximize # 34 x1 + 40 x2 subject to # 4 x1 + 6 x2 <= 48 # 2 x1 + 2 x2 <= 18 # 2 x1 + x2 <= 16 # x1 >= 0 # x2 >= 0 graph <- ggplot(data = data.frame(x=c(0,0,8,9,0,12), y=c(16,9,0,0,8,0)), aes(x,y)) + geom_abline(slope = -2/3, intercept = 8, color="red") + geom_abline(slope = -1, intercept = 9, color = "blue") + geom_abline(slope = -2, intercept = 16, color = "green") + geom_point(data = data.frame(x_optimal = c(3), y_optimal = c(6)), aes(x_optimal,y_optimal)) + geom_text(data = data.frame(x_optimal = c(3), y_optimal = c(6)), label="optimal solution", aes(x_optimal,y_optimal)) + geom_point() graph ``` ```{r The Stratton Company Case - lpsolve} # Set up problem: maximize # 34 x1 + 40 x2 subject to # 4 x1 + 6 x2 <= 48 # 2 x1 + 2 x2 <= 18 # 2 x1 + x2 <= 16 # x1 >= 0 # x2 >= 0 objective.in <- c(34, 40) const.mat <- matrix(c(4, 6, 2, 2, 2, 1), nrow=3, byrow=TRUE) const.dir <- c("<=", "<=", "<=") const.rhs <- c(48, 18, 16) result <- lp ("max", f.obj, f.con, f.dir, f.rhs) direction <- "max" result <- lp(direction = direction, objective.in = objective.in, const.mat = const.mat, const.dir = const.dir, const.rhs = const.rhs) result result\$solution ``` ```{r The steal production plan case - lpsolve} # Set up problem: maximize # 25 x1 + 30 x2 + 29 x3 subject to # x1 >= 0 # x2 >= 0 # x3 >= 0 # x1 <= 6000 # x2 <= 4000 # x3 <= 3500 # 1/200 x1 + 1/140 x2 + 1/160 x3 <= 40 # 1/200 x1 + 1/200 x2 + 1/200 x3 <= 35 objective.in <- c(25, 30, 29) const.mat <- matrix(c(1/200, 1/140, 1/160, 1/200, 1/200, 1/200, 1, 0, 0, 0, 1, 0, 0, 0, 1),nrow=5, byrow=TRUE) const.dir <- c("<=", "<=") const.rhs <- c(40, 35, 6000, 4000, 3500) direction <- "max" result <- lp(direction = direction, objective.in = objective.in, const.mat = const.mat, const.dir = const.dir, const.rhs = const.rhs) result result\$solution ``` ```{r The farm - lpsolve} # Set up problem: maximize # 250 x1 + 45 x2 subject to # 0 <= x1 <= 50 # 0 <= x2 <= 200 # x1 + 0.2 x2 <= 40 # 150 x1 + 25 x2 <= 10000 objective.in <- c(250, 45) const.mat <- matrix(c(1,0, 1,0, 0,1, 0,1, 1,0.2, 150,25),nrow=6, byrow=TRUE) const.dir <- c(">=", "<=", ">=", "<=", "<=", "<=") const.rhs <- c(0, 50, 0, 200, 40, 10000) direction <- "max" result <- lp(direction = direction, objective.in = objective.in, const.mat = const.mat, const.dir = const.dir, const.rhs = const.rhs) result result\$solution ``` ```{r Photovoltaic cell production - lpsolve} objective.in <- c(5, 2, 4) const.mat <- matrix(c(6,1,1, 2,1,1, 4,3,0, 0,5,2),nrow=4, byrow=TRUE) const.dir <- c("<=", "<=", "<=", "<=") const.rhs <- c(125, 65, 150, 75) direction <- "max" result <- lp(direction = direction, objective.in = objective.in, const.mat = const.mat, const.dir = const.dir, const.rhs = const.rhs) result result\$solution ```
 --- title: 'Tutorial 14: Optimization' output: html_notebook editor_options: chunk_output_type: inline --- This file is part of the lecture Business Intelligence & Analytics (EESYS-BIA-M), Information Systems and Energy Efficient Systems, University of Bamberg. ```{r} library(lpSolve) library(ggplot2) ``` ```{r lpSolve default example} # # Set up problem: maximize # x1 + 9 x2 + x3 subject to # x1 + 2 x2 + 3 x3 <= 9 # 3 x1 + 2 x2 + 2 x3 <= 15 # objective.in <- c(1, 9, 1) const.mat <- matrix(c(1, 2, 3, 3, 2, 2), nrow=2, byrow=TRUE) direction <- c("<=", "<=") const.rhs <- c(9, 15) direction <- "max" lp (direction, f.obj, f.con, f.dir, f.rhs) ```
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!