Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
LpSolver Example with Constraints
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
#A company wants to maximize the profit for two products A and B which are sold at $ 25 and $ 20 respectively. There are 1800 resource units available #every day and product A requires 20 units while B requires 12 units. Both of these products require a production time of 4 minutes and total #available working hours are 8 in a day. What should be the production quantity for each of the products to maximize profits? # max(Sales) = max(25 y1 + 20 y2) library(lpSolve) objective.in = c(25,20) objective.in const = matrix (c(20,12,4,4), nrow = 2, byrow = TRUE) const time_constraints = 480 resource_contraints = 1800 rhs = c(resource_contraints,time_constraints) direction = c("<=","<=") optimum = lp(direction = "max", objective.in, const, direction, rhs) optimum$solution optimum$objval
[
+
]
Show input
Absolute running time: 0.48 sec, cpu time: 0.57 sec, memory peak: 31 Mb, absolute service time: 0,5 sec
edit mode
|
history
|
discussion
[1] 25 20 [,1] [,2] [1,] 20 12 [2,] 4 4 [1] 45 75 [1] 2625