Fable.YALPS 0.3.0

.NET 6.0
dotnet add package Fable.YALPS --version 0.3.0
NuGet\Install-Package Fable.YALPS -Version 0.3.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Fable.YALPS" Version="0.3.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Fable.YALPS --version 0.3.0
#r "nuget: Fable.YALPS, 0.3.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install Fable.YALPS as a Cake Addin
#addin nuget:?package=Fable.YALPS&version=0.3.0

// Install Fable.YALPS as a Cake Tool
#tool nuget:?package=Fable.YALPS&version=0.3.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 are 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: Direction
  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
.NET net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.3.0 232 8/19/2022
0.2.0 228 5/29/2022
0.1.6 218 5/12/2022
0.1.5 219 5/10/2022
0.1.4 220 4/30/2022
0.1.3 205 4/30/2022
0.1.2 212 4/30/2022
0.1.1 219 4/30/2022
0.1.0 222 4/30/2022