FICO
FICO Xpress Optimization Examples Repository
FICO Optimization Community FICO Xpress Optimization Home
Back to examples browserPrevious exampleNext example

Apply a primal heuristic to a knapsack problem

Description

The program demonstrates the use of the MIP log callback.

We take the knapsack problem stored in burglar.mps and initiate a tree search. At each node, so long as the current solution is both LP optimal and integer infeasible, we truncate the solution values to create a feasible integer solution. We then update the cutoff, if the new objective value has improved it, and continue the search.


knapsack_dnet.zip[download all files]

Source Files
By clicking on a file name, a preview is opened at the bottom of this page.
Knapsack.cs[download]
Knapsack.csproj[download]

Data Files





Knapsack.csproj

<?xml version="1.0" encoding="UTF-8" standalone="no"?><Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net8.0</TargetFramework>

    <IsPackable>false</IsPackable>
    <XpressExampleFiles Condition="'$(XpressExampleFiles)'==''">../../data</XpressExampleFiles>
  </PropertyGroup>

  <ItemGroup>
    <Content Include="$(XpressExampleFiles)/burglar.mps">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="FICO.Xpress.XPRSdn" Version="45.1.1"/> <!-- Version 45.01.01 or later -->
  </ItemGroup>
  
  <!-- This is for execution with "dotnet run" and friends which runs from the project directory rather than the output directory. -->
  <Target AfterTargets="AfterBuild" Name="CopyExampleData">
    <Copy DestinationFolder="$(ProjectDir)" SourceFiles="$(XpressExampleFiles)/burglar.mps"/>
  </Target>

</Project>
Back to examples browserPrevious exampleNext example