.NET version of the example
As is explained in Section Using the Optimizer with BCL .NET, before accessing directly the problem held in Xpress Optimizer we need to initialize explicitly the Optimizer .NET. The cut manager callback is implemented in this .NET example by the method usrcme.
using Optimizer;
using BCL;
namespace Examples
{
public class xbcutex
{
static XPRBvar[] start = new XPRBvar[4]; // Start times of jobs
public static int usrcme(XPRSprob xprsp, object vd)
{
XPRBcut[] ca = new XPRBcut[2];
XPRBprob xprbp = (XPRBprob)vd; // Get the BCL problem
xprbp.beginCB(xprsp); // Coordinate BCL and Optimizer
int num = xprsp.Nodes;
if(num == 2) // Only generate cuts at node 2
{
ca[0] = xprbp.newCut(start[1]+2 <= start[0], 2);
ca[1] = xprbp.newCut((4*start[2]) - (5.3*start[3]) <= -17, 2);
System.Console.WriteLine("Adding constraints:");
for(int i=0;i<2;i++) ca[i].print();
if(xprbp.addCuts(ca,2) != 0)
System.Console.WriteLine("Problem with adding cuts.");
}
xprbp.endCB(); // Reset BCL to main problem
return 0; // Call this function once per node
}
public static void Main()
{
XPRB.init(); // Initialize BCL
XPRS.Init(); // Initialize Optimizer
XPRBprob xprbp = new XPRBprob("Jobs");// Create a new problem
for(int j=0;j<4;j++) // Create 'start' variables
start[j] = xprbp.newVar("start");
... // Define constraints and an objective function
XPRSprob xprsp = p.getXPRSprob(); // Get Optimizer problem
xprbp.setCutMode(1); // Enable the cut mode
CutmgrCallback del = new CutmgrCallback(usrcme);
xprsp.AddCutmgrCallback(del, (object)xprbp); // Define the cut manager callback
xprbp.mipOptimize(); // Solve the problem as MIP
}
}
}
