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.
C#
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!

Definition

Namespace: Orx.MathProg.Solvers
Assembly: Orx.MathProg (in Orx.MathProg.dll) Version: 1.0.0
C#
public Opt<double> ValueOf(
	VarD0 var
)

Parameters

var  VarD0
Variable to query value of.

Return Value

OptDouble

See Also