Imports System Imports Microsoft.VisualBasic Imports Optimizer Imports System.IO '/***************************************************************************************\ '* Name: MipSolEnum.vb FairIsaac 13/06/2008 * '* Purpose: 10 best solutions with the MIP solution enumerator * '* Description: We take the power generation problem stored in hpw15.mat which seeks to * '* optimise the operating pattern of a group of electricity generators. We * '* run the MIP solution enumerator on the problem using the default setup * '* obtaining the best 10 solutions. The best 10 solutions are stored to a * '* MIP solution pool. The solutions' objectives and solution values are * '* printed to screen. * '* Input: hpw15.mat * '\***************************************************************************************/ Module MipSolEnum Public Sub RunMipSolEnum(ByRef Log As TextWriter) XPRS.Init("") Log.WriteLine(XPRS.GetBanner) Dim prob As New XPRSprob ' Tell Optimizer to send all messages to Log ' prob.AddMsgHandlerCallback(Log) ' Get and display the Optimizer version number Log.WriteLine( _ vbCrLf & "Xpress Optimizer Subroutine Library Release {0}" & vbCrLf & vbCrLf, _ prob.Version / 100 _ ) Dim msp As New XPRSmipsolpool Dim mse As New XPRSmipsolenum prob.ReadProb("../Data/hpw15") Dim nCols As Integer = prob.Cols ' Disable heuristics to avoid duplicate solutions being stored prob.HeurStrategy = 0 Dim iPresolveOps as Long iPresolveOps = prob.PresolveOps iPresolveOps = iPresolveOps And Not (1 << 3) ' Disable dual reduction operations iPresolveOps = iPresolveOps And Not (1 << 5) ' Disable duplicate column removal prob.PresolveOps = iPresolveOps Dim iMIPPresolve as Long iMIPPresolve = prob.MIPPresolve iMIPPresolve = iMIPPresolve And Not (1 << 4) ' Disable MIP dual reduction operations prob.MIPPresolve = iMIPPresolve ' Run the enumeration ' Dim nMaxSols As Integer = 10 mse.Minim(prob, msp, XPRSdefaultMipSolEnumHandler.GetDefaultHandlerCallback(), Nothing, nMaxSols) ' Print out the solutions found Dim nSols As Integer = mse.Solutions Log.WriteLine("Enumerated best {0} solutions", nSols) Dim i As Integer For i = 1 To nSols Dim iSolutionId(1) As Integer Dim dObj As Double Dim nSols2, nReturnedSolIds, solutionIdStatus As Integer mse.GetSolList(XPRSattribute.Mse_Metric_MipObject, i, i, iSolutionId, nReturnedSolIds, nSols2) mse.GetSolMetric(iSolutionId(0), solutionIdStatus, XPRSattribute.Mse_Metric_MipObject, dObj) Log.WriteLine("--------") Log.WriteLine("{0} = {1}", i, dObj) Dim j As Integer For j = 0 To nCols - 1 Dim dSol(1) As Double Dim nValuesReturned As Integer msp.GetSol(iSolutionId(0), solutionIdStatus, dSol, j, j, nValuesReturned) Log.WriteLine("{0} = {1}", j, dSol(0)) Next Next End Sub End Module