fslaborg / flips

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

Add interfaces #129

Closed matthewcrews closed 3 years ago

matthewcrews commented 3 years ago

Before I merge this I'd like to get some quick feedback. There are two approaches to the modeling of ILinearExpression. One is to model it as a sequence of elements like this:

[<RequireQualifiedAccess>]
type LinearElement =
    | Constant of float
    | Decision of coefficient:float * decision:Decision

type ILinearExpression =
    abstract member Elements : seq<LinearElement>

I don't like this because it puts a lot of burden on the people interpreting the ILinearExpression to write code which will not blow a stack will iterating through a potentially long sequence.

I prefer this approach:

type ILinearExpression =
    abstract member Decisions : ISet<IDecision>
    abstract member Coefficients : IReadOnlyDictionary<IDecision, float>
    abstract member Offset : float

Which is much easier to use for someone writing a Solver backend. This is the form I prefer to work with when mapping from the the Flips.Model to the Solver model.