Skip to content

Latest commit

 

History

History
44 lines (31 loc) · 884 Bytes

linear.md

File metadata and controls

44 lines (31 loc) · 884 Bytes

Linear Programming

Import the following optimization packages:

import optimus.optimization._
import optimus.optimization.enums.SolverLib
import optimus.optimization.model.MPFloatVar

Create a model and select a solver for it:

implicit val model: MPModel = MPModel(SolverLib.oJSolver)

Ok! Let's create a couple of variables:

val x = MPFloatVar("x", 100, 200)
val y = MPFloatVar("y", 80, 170)

Then we can define our optimization problem subject to a simple constraint using our known maths:

maximize(-2 * x + 5 * y)
add(y >:= -x + 200)

At last, we can solve the problem by starting the solver and displaying the results:

start()

println(s"objective: $objectiveValue")
println(s"x = ${x.value} y = ${y.value}")

Finally, don't forget to release the memory used by the internal solver:

release()