H. Microsoft solver foundation integration


MOSEK Provides a plug-in to the Microsoft Solver Foundation (MSF). This enables Solver foundation Services to use MOSEK as a solver to solve LP,QP and MIP problems. The current implementation does not include the following features:

The MSF plug-in is available in the dll mosekmsflink.dll which must be installed in the Global Assembly Cache (GAC) or placed in the same directory as the executable at run-time. The MOSEK dotnet dll (mosekdotnet.dll) must also be available along with the MOSEK native libraries. The above mentioned files are distributed with MOSEK and can be found in:

mosek\5\tools\platform\win\bin

.

The dll Microsoft.Solver.Foundation.dll contains the MSF functionality and is provided by the MSF distribution.

H.1. Calling MOSEK from MFS

The following sections gives an example of how to call MOSEK from the MSF layer.

The code example below reads an mps file and solves it using MOSEK.

mosek\5\tools\examples\dotnet\msfcmd.cs
using System; using System.IO; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.SolverFoundation.Services; using SolverFoundation.Plugin.Mosek; using System.Configuration; namespace Microsoft.SolverFoundation.Samples { class Program { static void Main(string[] args) { { SolverContext context = SolverContext.GetContext(); // Load a model from file using(TextReader streamReader = new StreamReader(args[0])) { context.LoadModel(FileFormat.MPS,streamReader); } // Select the Mosek interior point optimizer. MosekInteriorPointMethodDirective d = new MosekInteriorPointMethodDirective(); // Mosek specific parameters may optionally be set. // d[mosek.dparam.optimizer_max_time] = 100.0; // Optionally write log information to console using two lines below System.Diagnostics.ConsoleTraceListener listener = new System.Diagnostics.ConsoleTraceListener(); d.AddListener(listener); // Solve the problem Solution sol = context.Solve(d); // Print solution Report report = sol.GetReport(); } } } }

The solver is selected by parsing the appropriate subclass of Directive to the Solve function. The following Directive classes are available:

MosekSimplexDirective

Selects the Simplex algorithm.

MosekMipDirective

Selects the MIP solver.

MosekInteriorPointMethodDirective

Selects the interior point solver.

For the program to run a App.config file must be present containing the code shown below.

mosek\5\tools\examples\dotnet\msfcmd.exe.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
 <section name="MsfConfig"
          type="Microsoft.SolverFoundation.Services.MsfConfigSection,
                Microsoft.Solver.Foundation,
                Version=1.0,
                Culture=neutral,
                PublicKeyToken=31bf3856ad364e35"
          allowLocation="true"
          allowDefinition="Everywhere"
          allowExeDefinition="MachineToApplication"
          restartOnExternalChanges="true"
          requirePermission="true" />
 </configSections>
 <MsfConfig>
  <MsfPluginSolvers>
   <MsfPluginSolver name="MosekMip"
               capability="MILP"
               assembly="mosekmsflink"
               solverclass="SolverFoundation.Plugin.Mosek.MosekMipSolver"
               directiveclass="SolverFoundation.Plugin.Mosek.MosekMipDirective"
               parameterclass="SolverFoundation.Plugin.Mosek.MosekMipSolverParams"/>
    <MsfPluginSolver name="MosekIP"
               capability="QP"
               assembly="mosekmsflink"
               solverclass="SolverFoundation.Plugin.Mosek.MosekInteriorPointSolver"
               directiveclass="SolverFoundation.Plugin.Mosek.MosekInteriorPointMethodDirective"
               parameterclass="SolverFoundation.Plugin.Mosek.MosekInteriorPointSolverParams"/>
    <MsfPluginSolver name="MosekSimplex"
               capability="LP"
               assembly="mosekmsflink"
               solverclass="SolverFoundation.Plugin.Mosek.MosekSimplexSolver"
               directiveclass="SolverFoundation.Plugin.Mosek.MosekSimplexDirective"
               parameterclass="SolverFoundation.Plugin.Mosek.MosekSimplexSolverParams"/>
    </MsfPluginSolvers>
  </MsfConfig>
</configuration>
 

The App.config file must be placed in the same directory as the executable (in this case msfcmd.exe) and have the name name EXENAME.exe.config where EXENAME is replace by the name of the executable.

The files for this example can be found in

mosek\5\tools\examples\dotnet\

A template for visual studio 2008 containing the relevant App.config file and references can be installed by running

mosek\5\tools\examples\dotnet\MsfMosekPluginTemplate.vsi

. The template should now be available from within Visual Studio.

Mon Sep 14 15:46:04 2009