library(mosaicCalc)
## Loading required package: mosaic
## Registered S3 method overwritten by 'mosaic':
## method from
## fortify.SpatialPolygonsDataFrame ggplot2
##
## The 'mosaic' package masks several functions from core packages in order to add
## additional features. The original behavior of these functions should not be affected by this.
##
## Attaching package: 'mosaic'
## The following objects are masked from 'package:dplyr':
##
## count, do, tally
## The following object is masked from 'package:Matrix':
##
## mean
## The following object is masked from 'package:ggplot2':
##
## stat
## The following objects are masked from 'package:stats':
##
## binom.test, cor, cor.test, cov, fivenum, IQR, median, prop.test,
## quantile, sd, t.test, var
## The following objects are masked from 'package:base':
##
## max, mean, min, prod, range, sample, sum
## Loading required package: mosaicCore
##
## Attaching package: 'mosaicCore'
## The following objects are masked from 'package:dplyr':
##
## count, tally
## The legacy packages maptools, rgdal, and rgeos, underpinning the sp package,
## which was just loaded, were retired in October 2023.
## Please refer to R-spatial evolution reports for details, especially
## https://r-spatial.org/r/2023/05/15/evolution4.html.
## It may be desirable to make the sf package available;
## package maintainers should consider adding sf to Suggests:.
##
## Attaching package: 'mosaicCalc'
## The following object is masked from 'package:stats':
##
## D
Optimasi adalah proses mencari solusi optimal (minimum atau maksimum) dengan memperhatikan batasan yang ada. optimasi memaksimalkan atau meminimalkan beberapa fungsi relative terhadap beberapa set, sering mewakili berbagai pilihan yang tersedia dalam situasi tertentu. Fungsinya memungkinkan perbandingan pilihan yang berbeda untuk menentukan mana yang bias dijadikan pilihan yang terbaik.
3 Cari Metode atau algoritma yang sering digunakan pada Optimasi, berdasarkan: 1. Optimasi Satu Dimensi
f <- function(x) {sin(x) + sin(2 * x) + cos(3 * x)}
optimize(f, interval = c(0, 2 * pi))
## $minimum
## [1] 3.033129
##
## $objective
## [1] -1.054505
f <- function(x) 2*(x[1]-1)^2+5*(x[2]-3)^2+10
optim(c(1,1),f)
## $par
## [1] 1.000168 3.000232
##
## $value
## [1] 10
##
## $counts
## function gradient
## 75 NA
##
## $convergence
## [1] 0
##
## $message
## NULL
library(lpSolve)
objective.in <- c(25, 20)
const.mat <- matrix(c(20, 12, 1/15, 1/15), nrow=2, byrow=TRUE)
const.rhs <- c(1800, 8)
const.dir <- c("<=", "<=")
optimum <- lp(direction="max", objective.in, const.mat, const.dir, const.rhs)
# Optimal values of x1 and x2
optimum$solution
## [1] 45 75
#objective at minimum
optimum$objval
## [1] 2625