Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

How to: Respond to the Solving Event from a Solver

Solver Foundation 3.0

You can subscribe to the solving event that is raised by a solver and respond to the event. The following procedure demonstrates how to add a solving event and cancel the solve process after the absolute gap between the primal and dual objectives of interior point method solver is acceptable.

To respond to the solving event

  1. Create a C# Solver Foundation Console Application.

  2. Add the following using statement to the top of the Program code file.

    using Microsoft.SolverFoundation.Common;
  3. Add the following statement to the try statement to subscribe to the solving event.

    context.Solving += 
        new EventHandler<SolvingEventArgs>(context_Solving);
  4. Add the following code that checks the absolute gap between the primal and dual objectives of the interior point method solver. If the absolute gap is acceptable, the solver can stop the solve process.

    static void context_Solving(object sender, SolvingEventArgs e)
        if ((double) e[InteriorPointProperties.AbsoluteGap] < 0.1) 
© 2015 Microsoft