Export (0) Print
Expand All

How to: Create a Custom Solver Report using the SFS APIs

Solver Foundation 3.0

If you are using or creating a third-party solver, you can use the Solver Foundation Services reporting APIs to access the solver data and to extend the report to include data about custom properties.

To create a custom solver report

  1. Add the following Imports or using statements.

    
    using Microsoft.SolverFoundation.Services;
    using Microsoft.SolverFoundation.Common;
    
    
    
  2. Create a custom report class that inherits from LinearReport and that creates a new property called solutionGoals.

    
    class CustomReport : LinearReport {
      private readonly ILinearModel _linearModel;
      private LinearSolutionMapping _lpSolutionMapping;
    
      public CustomReport(
        SolverContext context, 
        ISolver solver,
        Solution solution,
        LinearSolutionMapping solutionMapping) :
        base(context, solver, solution, solutionMapping) {
        _lpSolutionMapping = solutionMapping;
        _linearModel = solver as ILinearModel;
        if (_linearModel == null)
          throw new ArgumentNullException();
      }
    
      public string solutionGoals {
        get {
          ValidateSolution();
          string temp = "";
          foreach (var goal in Solution.Goals) {
            temp += "The value of " + goal.Name +
              " is " + goal.ToString() + ".  ";
          }
          return temp;
        }
      }
    
    }
    
    
    
  3. Generate a report using the custom property.

    
    Report report = solution.GetReport();
    CustomReport customReport = report as CustomReport;
    Console.WriteLine(customReport.solutionGoals);
    
    
    
Show:
© 2014 Microsoft