Using the Optimizer with BCL .NET
Using the Optimizer with BCL .NET is very similar to the other interfaces already seen and the same considerations regarding BCL-compatible functions remain true. The BCL .NET interface also requires an explicit intialization of the Optimizer .NET interface (by calling XPRS.Init()) before the Optimizer problem is accessed.
The following are .NET implementations of the code extracts showing the use of BCL-compatible functions:
Setting and accessing parameters:
int rows; XPRB.init(); // Initialize BCL XPRS.Init(); // Initialize Xpress Optimizer XPRSprob opt_prob; XPRBprob bcl_prob; bcl_prob = new XPRBprob("Example1"); // Create a new problem in BCL ... // Define the problem bcl_prob.loadMat(); opt_prob = bcl_prob.getXPRSprob(); opt_prob.MaxTime = 60; // Set a time limit of 60 seconds opt_prob.MIPAddCutoff = 0.999; // Set an ADDCUTTOFF value rows = opt_prob.OriginalRows; // Get number of rows bcl_prob.setSense(BCLconstant.XPRB_MAXIM); // Select maximization bcl_prob.lpOptimize(); // Maximize the LP problem
Using Xpress Optimizer callbacks (multi-threaded MIP):
public class IntSolExample public static void PrintSolution(XPRSprob opt_prob, object my_object) { XPRBprob bcl_prob = (XPRBprob)my_object; bcl_prob.beginCB(opt_prob); int num = opt_prob.MIPSols; bcl_prob.sync(BCLconstant.XPRB_XPRS_SOL); // Update BCL solution values System.Console.WriteLine("Solution "+num+": Objective value: "+bcl_prob.getObjVal()); XPRBvar x = bcl_prob.getVarByName("x_1"); if( x.getColNum() > -1 ) // Test whether variable is in the matrix System.Console.WriteLine(x.getName() + ": " + x.getSol()); bcl_prob.endCB(); } public static void Main() { XPRB.init(); XPRS.Init(); XPRBprob bcl_prob = new XPRBprob("Example1"); XPRBvar x = bcl_prob.newVar("x_1", BCLconstant.XPRB_BV); // Define a variable ... // Define the rest of the problem XPRSprob opt_prob = bcl_prob.getXPRSprob(); // Define an integer solution callback IntsolCallback printsol = new IntsolCallback(PrintSolution); opt_prob.AddIntsolCallback(printsol, (object)bcl_prob); bcl_prob.setSense(BCLconstant.XPRB_MAXIM); bcl_prob.mipOptimize(); // Maximize the MIP problem } }
The code extract below shows how to access MIP solution information directly through the Optimizer library functions using the column or row indices saved for BCL modeling objects. In this case there is no need for synchronization of BCL with the local solution information.
public class IntSolExample2 public static void XPRSIntSolEvent(XPRSprob opt_prob, object my_object) { XPRBprob bcl_prob = (XPRBprob)my_object; int ncol = opt_prob.OriginalCols; // Get the number of columns double[] sol = new double[ncol]; opt_prob.GetLpSol(sol); // Get the solution int num = opt_prob.MIPSols; // Get number of the solution System.Console.WriteLine("Solution {0}: Objective value: {1}",num,opt_prob.LPObjVal); XPRBvar x = bcl_prob.getVarByName("x_1"); if( x.getColNum() >= 0 ) // Test whether variable is in the matrix System.Console.WriteLine(x.getName() + ": " + sol[x.getColNum()]); } }
© 2001-2019 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.