Fable.YALPS
0.6.0
dotnet add package Fable.YALPS --version 0.6.0
NuGet\Install-Package Fable.YALPS -Version 0.6.0
<PackageReference Include="Fable.YALPS" Version="0.6.0" />
paket add Fable.YALPS --version 0.6.0
#r "nuget: Fable.YALPS, 0.6.0"
// Install Fable.YALPS as a Cake Addin #addin nuget:?package=Fable.YALPS&version=0.6.0 // Install Fable.YALPS as a Cake Tool #tool nuget:?package=Fable.YALPS&version=0.6.0
Fable.YALPS
This provides F# / Fable bindings for Yet Another Linear Programming Solver (YALPS). Check it out for more information. The corresponding F# API translates naturally, but you may ignore anything regarding objects for fields on the model (see Differences for more information). One thing to note is that equality between constraint and variable keys is tested using JS strict equality and not structural equality.
Examples
open YALPS
open YALPS.Operators
let constraints = [
"wood", Constraint.lessEq 300.0
"labor" <== 110.0 // you can use the convenience operators instead
"storage" <== 400.0
]
let variables = [
"table", [ "wood", 30.0; "labor", 5.0; "profit", 1200.0; "storage", 30.0 ]
"dresser", [ "wood", 20.0; "labor", 10; "profit", 1600.0; "storage", 50.0 ]
]
let model = Model.createAllInteger Maximize "profit" constraints variables
let solution = Solver.solve model
// { status = Optimal
// result = 14400.0
// variables: [| "table", 8; "dresser", 3 |] }
With custom options:
let model = Model.createAllInteger Maximize "profit" constraints variables
let solution = model |> Solver.solveWith { Solver.defaultOptions with timeout = 100.0 }
Differences
To fit better with F# code, the ability for sequences to be substituted with objects (serving as a key-value map) was dropped. The underlying JS code still supports this, so dynamic casting will work:
let constraints = {|
wood = Constraint.lessEq 300.0
labor = {| max = 110.0 |}
storage = {| max = 400.0 |}
|}
let variables = {|
table = {| wood = 30.0; labor = 5.0; profit = 1200.0; storage = 30.0 |}
dresser = {| wood = 20.0; labor = 10.0; profit = 1600.0; storage = 50.0 |}
|}
open Fable.Core.JsInterop
let model = Model.createAllInteger Maximize "profit" !!constraints !!variables
Here is the simplified model type used in Fable.YALPS (only sequences and no objects).
type Model<'VariableKey, 'ConstraintKey> =
abstract direction: OptimizationDirection
abstract objective: 'ConstraintKey
abstract constraints: ('ConstraintKey * Constraint) seq
abstract variables: ('VariableKey * ('ConstraintKey * float) seq) seq
abstract integers: U2<bool, 'VariableKey seq>
abstract binaries: U2<bool, 'VariableKey seq>
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net8.0
- Fable.Core (>= 4.3.0)
- FSharp.Core (>= 8.0.200)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.