Rabbits & Pheasants

The following example utilizes the standard constraint solver. The problem to be solved is to determine the number of pheasants & rabbits that match the following constraints: the total number of animals is twenty and we have the total number of legs equals fifty six.

open System
open Operations.Research.Types
open Operations.Research.Models
open Operations.Research.Solvers.Google.Constraint

let r = Variable.integer "r" 0 100 |> toExpression
let p = Variable.integer "p" 0 100 |> toExpression

let mdl =
  Model.Default
  |> DecisionVars [r; p]
  |> Constraints [
    r + p === 20
    4*r + 2*p === 56
  ]

let result = Solve mdl

match result with
| Solution sol ->
    printfn "%s: %f" (r.var().Name) (sol.Variables.[r.var().Name])
    printfn "%s: %f" (p.var().Name) (sol.Variables.[p.var().Name])
| Error e ->
    printfn "%A" e