Collecting all solutions with the MIP solution pool
|
|
Type: | Power generation |
Rating: | 3 (intermediate) |
Description: | We take the power generation problem stored in hpw15.mps which seeks to optimise the operating pattern of a group of electricity generators. We solve the problem collecting all solutions found during the MIP search. The optimal solution's objective and solution values are printed to screen. |
File(s): | MipSolPool.cs, MipSolPool.csproj |
Data file(s): | hpw15.mps |
|
MipSolPool.cs |
/*********************************************************************** Xpress Optimizer Examples ========================= file MipSolPool.cs `````````````````` Generate all solutions with the MIP solution pool We take the power generation problem stored in hpw15.mps which seeks to optimise the operating pattern of a group of electricity generators. We solve the problem collecting all solutions found during the MIP search. The optimal solution's objective and solution values are printed to screen. (c) 2008-2024 Fair Isaac Corporation ********************************************************************/ using System; using System.IO; using Optimizer; namespace XPRSExamples { class MipSolPool { public static void Main(string[] args) { XPRS.Init(); XPRSprob prob = new XPRSprob(); prob.AddMsgHandlerCallback(Console.Out); XPRSmipsolpool msp = new XPRSmipsolpool(); msp.ProbAttach(prob); prob.MPSFormat = -1; prob.ReadProb("hpw15"); prob.MipOptimize(); int nSols = msp.Solutions; if (nSols > 0) { int iSolutionId, iSolutionIdStatus; double dObj; msp.GetDblAttribProbExtreme(prob, 0, out iSolutionId, (int)XPRSattribute.Msp_SolPrb_Obj, out dObj); Console.WriteLine("Optimal Solution ID: " + iSolutionId); Console.WriteLine("Optimal Objective : " + dObj); int nCols = msp.GetIntAttribSol(iSolutionId, out iSolutionIdStatus, (int)XPRSattribute.Msp_Sol_Cols); for (int i = 0; i < nCols; i++) { int nValuesReturned; double[] dSol = new double[1]; msp.GetSol(iSolutionId, out iSolutionIdStatus, dSol, i, i, out nValuesReturned); Console.WriteLine(i + " = " + dSol[0]); } } XPRS.Free(); } } } |
MipSolPool.csproj |
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>net5.0</TargetFramework> <IsPackable>false</IsPackable> <XpressExampleFiles Condition="'$(XpressExampleFiles)'==''">../../data</XpressExampleFiles> </PropertyGroup> <ItemGroup> <Content Include="$(XpressExampleFiles)/hpw15.mps"> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </Content> </ItemGroup> <ItemGroup> <PackageReference Include="FICO.Xpress.XPRSdn" Version="41.1.1" /> <!-- Version 41.1.1 or later --> </ItemGroup> <!-- This is for execution with "dotnet run" and friends which runs from the project directory rather than the output directory. --> <Target Name="CopyExampleData" AfterTargets="AfterBuild"> <Copy SourceFiles="$(XpressExampleFiles)/hpw15.mps" DestinationFolder="$(ProjectDir)" /> </Target> </Project> |
© 2001-2024 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.