Solve(MathModel) |
Solves the given model and returns:
- Ok of the solution if the execution is successfully completed,
- experienced Err otherwise.
Assume we have just tried to solve the model. ISolver solver = new X(); // where X : ISolver
var resSolution = await solver.Solve(model);
The result of the solution, resSolution here, can be used in different ways (). #1: Handle error case and Unwrap if (resSolution.IsErr)
{
// do something with the error:
// * return a proper result
// * throw an exception using the error message 'resSolution.ErrorMessage().Unwrap()'
}
MathModelSolution solution = resSolution.Unwrap();
// use the solution
#2: Use ThrowIfErr shorthand and Unwrap MathModelSolution solution = resSolution.ThrowIfErr().Unwrap();
// use the solution
#3: Map the solution to Res of the desired result Res<double> resObjVal = resSolution.Map(soln => soln.ObjectiveValue.UnwrapOr(double.PositiveInfinity));
// note that soln.ObjectiveValue can be None if the resSolution.IsOk (solver worked properly);
// however, the model is infeasible.
|
Solve(CancellationToken, MathModel) |
Solves the given model with a cancellationToken and returns:
- Ok of the solution if the execution is successfully completed,
- experienced Err otherwise.
Assume we have just tried to solve the model. ISolver solver = new X(); // where X : ISolver
var resSolution = await solver.Solve(model);
The result of the solution, resSolution here, can be used in different ways (). #1: Handle error case and Unwrap if (resSolution.IsErr)
{
// do something with the error:
// * return a proper result
// * throw an exception using the error message 'resSolution.ErrorMessage().Unwrap()'
}
MathModelSolution solution = resSolution.Unwrap();
// use the solution
#2: Use ThrowIfErr shorthand and Unwrap MathModelSolution solution = resSolution.ThrowIfErr().Unwrap();
// use the solution
#3: Map the solution to Res of the desired result Res<double> resObjVal = resSolution.Map(soln => soln.ObjectiveValue.UnwrapOr(double.PositiveInfinity));
// note that soln.ObjectiveValue can be None if the resSolution.IsOk (solver worked properly);
// however, the model is infeasible.
|