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.

    
    Imports Microsoft.SolverFoundation.Services
    
    
    
  2. 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()
    
    
    
  3. Create the default report.

    
    Console.WriteLine("This is the default report: \n" + report.ToString())
    
    
    
  4. 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()
    
    
    
Show:
© 2014 Microsoft