MathModelSolutionValueOf Method
Returns Some of the value of the 0-dimensional variable provided that:
- the solution IsFeasible, and
- the queried var belongs to the solved model.
Returns None otherwise.
VarD0 fitness = Variable("fit").IsBinary(); // irrelevant to the model
VarD0 utility = Variable("util").IsBinary();
Objective maxUtility = maximize | utility;
MathModel model = MathModel.New().WithObjective(maxUtility).HasNoConstraints();
Scip solver = new();
var resSolution = await solver.Solve(model);
MathModelSolution solution = resSolution.Unwrap(); // normally, check if it is 'IsOk' before unwrapping!
var valUtility = solution.ValueOf(utility);
Assert.Equal(Some(1), valUtility); // alternatively:
Assert.True(valUtility.IsSome);
Assert.True(1, valUtility.Unwrap());
var valFitness = solution.ValueOf(fitness);
Assert.True(valFitness.IsNone); // "valFitness.Unwrap()" would've thrown!
Namespace: Orx.MathProg.SolversAssembly: Orx.MathProg (in Orx.MathProg.dll) Version: 1.0.0
public Opt<double> ValueOf(
VarD0 var
)
- var VarD0
- Variable to query value of.
OptDouble