Export (0) Print
Expand All

How to: Create a Solver Report

Solver Foundation 3.0

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

  1. Add the following Imports or using statement.

    
    using Microsoft.SolverFoundation.Services;
    
    
    
  2. Create a model to calculate the amount of petroleum to buy from two different sources.

    
    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();
    
    
    
  3. Create the default report.

    
    Console.WriteLine("This is the default report: \n" + report);
    
    
    
  4. Get the values of properties from the report object to create a summary.

    
    // 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();
    
    
    
Show:
© 2014 Microsoft