|
#light
open System
open System.Runtime.InteropServices
open Microsoft.SolverFoundation.Common
open Microsoft.SolverFoundation.Services
/// Need a simple class to hold the value
type RowBound = { Value:double }
do
let context = SolverContext.GetContext()
let model = context.CreateModel()
let rational x = Rational.op_Implicit(x:float)
let constant x = Term.op_Implicit(x:float)
let maxbound(t,x) = Model.LessEqual([|t; x|])
let minbound(t,x) = Model.GreaterEqual([|t; x|])
/// Data source for Parameters
let constant1 = [| { Value = 430.0 } |]
let constant2 = [| { Value = 460.0 } |]
let constant3 = [| { Value = 420.0 } |]
let boundC1 = Parameter(Domain.RealNonnegative,
"boundC1")
/// The trick is to use an empty array [| |]
/// as the third parameter.
boundC1.SetBinding(constant1, "Value", [| |])
model.AddParameter(boundC1)
let boundC2 = Parameter(Domain.RealNonnegative,
"boundC2")
boundC2.SetBinding(constant2, "Value", [| |])
model.AddParameter(boundC2)
let boundC3 = Parameter(Domain.RealNonnegative,
"boundC3")
boundC3.SetBinding(constant3, "Value", [| |])
model.AddParameter(boundC3)
let x = Decision(Domain.Real, "x")
let y = Decision(Domain.Real, "y")
let z = Decision(Domain.Real, "z")
model.AddDecision(x)
model.AddDecision(y)
model.AddDecision(z)
let AddConstraint = model.AddConstraint("x>=0",
minbound(x, constant 0.0))
let AddConstraint = model.AddConstraint("y>=0",
minbound(y, constant 0.0))
let AddConstraint = model.AddConstraint("z>=0",
minbound(z, constant 0.0))
let AddGoal = model.AddGoal("goal", GoalKind.Maximize,
constant 3.0 * x + constant 2.0 * y + constant 5.0 * z)
let AddConstraint = model.AddConstraint("c1",
maxbound(constant 1.0 * x + constant 2.0 * y +
constant 1.0 * z, boundC1))
let AddConstraint = model.AddConstraint("c2",
maxbound(constant 3.0 * x + constant 2.0 * z, boundC2))
let AddConstraint = model.AddConstraint("c3",
maxbound(constant 1.0 * x + constant 4.0 * y, boundC3))
let sd = SimplexDirective()
sd.Algorithm <- SimplexAlgorithm.Dual
sd.GetSensitivity <- true
let sol = context.Solve([|(sd :> Directive)|])
let report = sol.GetReport()
Console.WriteLine(report) |