How to: Create a Solver Report
You can use the Solver Foundation reporting APIs to access solver data and create reports. Additionally, you can use third-party solvers to extend a report to include data about custom properties.
To create a solver report
Add the following Imports or using statement.
Imports Microsoft.SolverFoundation.Services
using Microsoft.SolverFoundation.Services;
Create a model to calculate the amount of petroleum to buy from two different sources.
Dim context As SolverContext = SolverContext.GetContext() context.ClearModel() Dim model As Model = context.CreateModel() Dim vz As Decision = New Decision(Domain.RealNonnegative, "barrels_venezuela") Dim sa As Decision = New Decision(Domain.RealNonnegative, "barrels_saudiarabia") model.AddDecisions(vz, sa) model.AddConstraints("limits", 0 <= vz <= 9000, 0 <= sa <= 6000) model.AddConstraints("production", 0.3 * sa + 0.4 * vz >= 2000) model.AddGoal("cost", GoalKind.Minimize, 20 * sa + 15 * vz) Dim solution As Solution = context.Solve(New Directive()) Dim report As Report = solution.GetReport()
SolverContext context = SolverContext.GetContext(); context.ClearModel(); Model model = context.CreateModel(); Decision vz = new Decision(Domain.RealNonnegative, "barrels_venezuela"); Decision sa = new Decision(Domain.RealNonnegative, "barrels_saudiarabia"); model.AddDecisions(vz, sa); model.AddConstraints("limits", 0 <= vz <= 9000, 0 <= sa <= 6000); model.AddConstraints("production", 0.3 * sa + 0.4 * vz >= 2000); model.AddGoal("cost", GoalKind.Minimize, 20 * sa + 15 * vz); Solution solution = context.Solve(new Directive()); Report report = solution.GetReport();
Create the default report.
Console.WriteLine("This is the default report: \n" + report.ToString())
Console.WriteLine("This is the default report: \n" + report);
Get the values of properties from the report object to create a summary.
Console.WriteLine("This is the custom report: ") Console.WriteLine("The {0} model used the {1} capability and {2} solution directive and had an {3} quality setting.", report.ModelName.ToString(), report.SolverCapability.ToString(), report.SolutionDirective.ToString(), report.SolutionQuality.ToString()) Console.WriteLine("The {0} solver finished in {1} ms with a total time of {2} ms.", report.SolverType.ToString(), report.SolveTime.ToString(), report.TotalTime.ToString()) Console.ReadLine()
// Demonstrates how to create a customized report. Console.WriteLine("This is the custom report: "); Console.WriteLine("The {0} model used the {1} capability and {2} solution directive and had an {3} quality setting.", report.ModelName.ToString(), report.SolverCapability.ToString(), report.SolutionDirective.ToString(), report.SolutionQuality.ToString()); Console.WriteLine("The {0} solver finished in {1} ms with a total time of {2} ms.", report.SolverType.ToString(), report.SolveTime.ToString(), report.TotalTime.ToString()); Console.ReadLine();