fslaborg / flips

Fsharp LInear Programming System
https://flipslibrary.com/#/
MIT License
251 stars 32 forks source link

few additions to cplex solver to cover their options and callbacks APIs #128

Closed smoothdeveloper closed 3 years ago

smoothdeveloper commented 3 years ago

Flips.Solver.Cplex: settings & callbacks (related to #103)

also fix stack overflow in own type extensions of Flips.Types.*.GetDecisions() by calling to LinearExpression.Reduce

with those changes, using Flips.Solver.Cplex:

setting an option on cplex solver "state" object:

open Flips.Solver.Cplex.Internals

let state =
    CplexSolver.ICplexSolverState.create()
    |> CplexSolver.ICplexSolverState.setCplexBoolOption ILOG.CPLEX.Cplex.BooleanParam.MemoryEmphasis true

getting the decisions without crashing on a "large" problem (10k decisions)

let model = Flips.Docs.Samples.sampleProblem()
model.GetDecisions() |> System.Collections.Generic.HashSet

callbacks:

they can be written as object expression implementing CPLEX API, although right now, they don't seem to trigger.

let callback = 
  { new ILOG.CPLEX.Cplex.SolveCallback() with
      member x.Main() = printfn "solving... current objective: %f" (x.GetObjValue()) }

CplexSolver.Primitives.runSolverWithCallback model state callback