Solver Foundation Version 2.1 introduced a new API class called LinearReport that allows programmatic access of the report data. You can use this class to retreive sensitivity and infeasibility information.
Let’s discuss with a simple model:
SolverContext context = SolverContext.GetContext(); Model model = context.CreateModel();
//decisions Decision xs = new Decision(Domain.RealNonnegative, "Number_of_small_chess_boards"); Decision xl = new Decision(Domain.RealNonnegative, "Number_of_large_chess_boards");
model.AddDecisions(xs, xl);
//constraints Constraint constraintBoxWood = model.AddConstraint("BoxWood", 1 * xs + 3 * xl <= 200); Constraint constraintLathe = model.AddConstraint("Lathe", 3 * xs + 2 * xl <= 160);
//Goals model.AddGoal("Profit", GoalKind.Maximize, 5 * xs + 20 * xl);
Solution sol = context.Solve(); Report report = sol.GetReport();
To get the LinearReport, typecast report with LinearReport
LinearReport lpReport = report as LinearReport;
The following image shows some of the methods on the LinearReport that can used to retrieve sensitivity and infeasibility properties.
The following code demonstrates how to get the shadow prices of constraint constraintBoxWood from the example:
IEnumerable<KeyValuePair<string,Rational>> prices = lpReport.GetShadowPrices(constraintBoxWood);
or to get the shadow prices of all constraints:
IEnumerable<KeyValuePair<string, Rational>> prices = lpReport.GetAllShadowPrices();
Both of the above methods return pairs of each individual constraint’s name and its shadow price.
Also when a model is infeasible, you can get the list of infeasible constraints:
IEnumerable<string> infeasibleConstraints = lpReport.GetInfeasibilitySet();
GetInfeasibilitySet returns the list of constraint names that make the model infeasible
For more examples, refer to DietProblem and ColumnGeneration samples (as part of the installation) that demonstrate how to access infeasibility and sensitivity data programmatically.