Initializing help system before first use

Creating Xpress Solver Applications in Csharp

In this chapter we illustrate how to create a C# application that uses the Xpress Solver. We use a very simple application that only consists of this simple App.cs file:

using System;
using Optimizer;

namespace XpressApplication
{
  /// <summary>A very simple Xpress application.</summary>
  /// <remarks>
  /// The application that solves this optimization problem:
  ///  Minimize
  ///    3x1 + 5x2
  ///  Subject To
  ///    2x1 +  x2 >= 3
  ///    2x1 + 2x2 >= 5
  ///     x1 + 4x2 >= 4
  ///     x1,x2 >= 0
  /// and displays the results.
  /// For more detailed examples please see the directory
  /// examples/solver/optimizer/csharp in your Xpress installation.
  /// </remarks>
  class App
  {
    static void Main(string[] args)
    {
      using (XPRSprob prob = new XPRSprob(""))
      {
        prob.LoadLP("problem", 2, 3,
          new char[] { 'G', 'G', 'G' },                         // rowtype
          new double[] { 3, 5, 4 },                             // rhs
          null,
          new double[] { 3, 5 },                                // obj
          new int[] { 0, 3, 6 },                                // start
          null,
          new int[] { 0, 1, 2, 0, 1, 2 },                       // rowind
          new double[] { 2, 2, 1, 1, 2, 4 },                    // rowcoef
          new double[] { 0, 0 },                                // lb
          new double[] { XPRS.PLUSINFINITY, XPRS.PLUSINFINITY } // ub
        );

        prob.AddNames(Optimizer.Namespaces.Column,
          new String[] { "x1", "x2" }, 0, 1);
        prob.Optimize();
        double[] x = prob.GetSolution();
        Console.WriteLine("x1 = {0}", x[0]);
        Console.WriteLine("x2 = {0}", x[1]);
      }
    }
  }
}

This solves the very simple optimization problem \begin{array}{lrcl} \text{minimize} \\ & 3 x_1 + 5 x_2 \\ \text{subject to} \\ & 2 x_1 + x_2 & \geq & 3 \\ & 2 x_1 + 2x_2 & \geq & 5 \\ & x_1 + 4x_2 & \geq & 4 \\ & x_1,\,x_2 & \geq & 0 \end{array} and displays the results.

Note that there are much more convenient ways to create models (see the examples shipped with Xpress). Here we focus on how creating the application binaries and not the application content.

Creating Xpress applications in Visual Studio

Using NuGet packages

The Xpress Solver library is shipped as a NuGet package. Those packages have to be registered with Visual Studio. To do that, perform the following steps (with or without a project/solution) loaded (we assume that Xpress was installed into C:\xpressmp, adjust paths in the below configuration if you installed into a different folder):

  1. Select "Tools -> NuGet Package Manager -> Package Manager Settings"
  2. Select "NuGet Package Manager -> Package Sources"
  3. Click on the "+" icon to add a package with default settings.
  4. Modify the default settings:
    • Choose a reasonable name, for example "Xpress x.y.z" where x.y.z is the Xpress version number.
    • Set the source to C:\xpressmp\lib\nuget
  5. Click "Update" and make sure the newly added package source is checked in the list of package sources.
  6. Click "Update" then "Ok" to save the changes.

This is a one-time operation that you have to perform only once (or once for every version of Xpress that you install).

Now to create a C# application that uses the Xpress Solver, follow these steps:

  1. Create a new "C# Console Application" project (choosing an appropriate target framework).
  2. Select "Project -> Manage NuGet Packages ...
  3. From the pull down select the Xpress Solver package you added above
  4. Go to the "Browse" tab.
  5. Select FICO.Xpress.XPRSdn and click "Install"
  6. Go to "Project -> Add Existing Item ..."
  7. Change the file filter to either "All Files" or "Executable Files".
  8. Find the C:\xpressmp\bin\xprs.dll library and "Add" it.
  9. In the project explorer right-click the xprs.dll item and select "Properties".
  10. Change the "Copy to Output Directory" property to either "Copy always" or "Copy if newer".
  11. Add the C:\xpressmp\bin\xprl.dll in the same way.
  12. Copy the above source code over the default main source code file in your newly created project.
  13. Now your project is ready for compilation. In order to run it you must also point Xpress to your license path location:
    • Open your project's property dialog.
    • In "Debug ->Environment Variables" add a variable XPAUTH_PATH that points to the absolute path to your xpauth.xpr file.

Deprecated: Using xprsdn.dll directly

In order to create a C# application that uses the Xpress Solver, follow these steps:

  1. Create a new "C# Console Application" project (choosing an appropriate target framework).
  2. Select your project in the project or solution explorer and go to "Project -> Add Project Reference ...".
  3. In the dialog that appears select "Browse" and then click "Browse...".
  4. Find the C:\xpressmp\bin\xprsdn.dll library and add it.
  5. Close the dialog.
  6. Go to "Project -> Add Existing Item ..."
  7. Change the file filter to either "All Files" or "Executable Files".
  8. Find the C:\xpressmp\bin\xprs.dll library and "Add" it.
  9. In the project explorer right-click the xprs.dll item and select "Properties".
  10. Change the "Copy to Output Directory" property to either "Copy always" or "Copy if newer".
  11. Add the C:\xpressmp\bin\xprl.dll in the same way.
  12. Copy the above source code over the default main source code file in your newly created project.
  13. Now your project is ready for compilation. In order to run it you must also point Xpress to your license path location:
    • Open your project's property dialog.
    • In "Debug ->Environment Variables" add a variable XPAUTH_PATH that points to the absolute path to your xpauth.xpr file.


© 2001-2025 Fair Isaac Corporation. All rights reserved. This documentation is the property of Fair Isaac Corporation (“FICO”). Receipt or possession of this documentation does not convey rights to disclose, reproduce, make derivative works, use, or allow others to use it except solely for internal evaluation purposes to determine whether to purchase a license to the software described in this documentation, or as otherwise set forth in a written software license agreement between you and FICO (or a FICO affiliate). Use of this documentation and the software described in it must conform strictly to the foregoing permitted uses, and no other use is permitted.