F# wrappers for Ceres Solver and IpOpt with aardvark-style native dependencies.
open CeresSharp
open Aardvark.Base
// Solve a simple system: { x = y, x² + y² = 1 }
use p = new Problem()
use x = p.AddParameterBlock [| 1.0 |]
use y = p.AddParameterBlock [| -1.0 |]
p.AddCostFunction(2, x, y, TrivialLoss, fun x y ->
[| x.[0] - y.[0]; x.[0] * x.[0] + y.[0] * y.[0] - 1.0 |]
)
let residual = p.Solve {
maxIterations = 50
solverType = DenseQr
functionTolerance = 1E-16
gradientTolerance = 1E-16
parameterTolerance = 1E-16
print = false
}
printfn "x = %.4f, y = %.4f" x.Result.[0] y.Result.[0]open IpOptSharp
open Aardvark.Base
// Find the largest equilateral triangle inscribed in a unit circle
let a = ref (V2d(-1.0, -1.0))
let b = ref (V2d(1.0, -1.0))
let c = ref (V2d(0.0, 1.0))
let (status, objective) =
ipopt {
let! a = a
let! b = b
let! c = c
// Maximize the circumference
let circumference = Vec.length (b - a) + Vec.length (c - b) + Vec.length (a - c)
IpOpt.Maximize circumference
// Constrain vertices to the unit circle
IpOpt.Equal(a.Length, 1.0)
IpOpt.Equal(b.Length, 1.0)
IpOpt.Equal(c.Length, 1.0)
}
printfn "status: %A, objective: %.4f" status objectivecmakedotnet >= 6.0- C/C++ compiler
- setup environment variable
GITHUB_TOKENwith a token having at least read-access to packages on github (see here how to create a token) - run
buildnative dotnet tool restoredotnet paket restoredotnet build src/Aardvark.Optimization.sln
New Packages can be created by simply adding a new version in RELEASE_NOTES.md and pushing the file to the master branch.
The GitHub CI Action will take care of building native code and publishing packages to NuGet/GitHub Packages