LetchfordLodiCut.java

  1. package org.drip.linearprogram.cuttingplane;

  2. /*
  3.  * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  4.  */

  5. /*!
  6.  * Copyright (C) 2020 Lakshmi Krishnamurthy
  7.  *
  8.  *  This file is part of DROP, an open-source library targeting analytics/risk, transaction cost analytics,
  9.  *      asset liability management analytics, capital, exposure, and margin analytics, valuation adjustment
  10.  *      analytics, and portfolio construction analytics within and across fixed income, credit, commodity,
  11.  *      equity, FX, and structured products. It also includes auxiliary libraries for algorithm support,
  12.  *      numerical analysis, numerical optimization, spline builder, model validation, statistical learning,
  13.  *      and computational support.
  14.  *  
  15.  *      https://lakshmidrip.github.io/DROP/
  16.  *  
  17.  *  DROP is composed of three modules:
  18.  *  
  19.  *  - DROP Product Core - https://lakshmidrip.github.io/DROP-Product-Core/
  20.  *  - DROP Portfolio Core - https://lakshmidrip.github.io/DROP-Portfolio-Core/
  21.  *  - DROP Computational Core - https://lakshmidrip.github.io/DROP-Computational-Core/
  22.  *
  23.  *  DROP Product Core implements libraries for the following:
  24.  *  - Fixed Income Analytics
  25.  *  - Loan Analytics
  26.  *  - Transaction Cost Analytics
  27.  *
  28.  *  DROP Portfolio Core implements libraries for the following:
  29.  *  - Asset Allocation Analytics
  30.  *  - Asset Liability Management Analytics
  31.  *  - Capital Estimation Analytics
  32.  *  - Exposure Analytics
  33.  *  - Margin Analytics
  34.  *  - XVA Analytics
  35.  *
  36.  *  DROP Computational Core implements libraries for the following:
  37.  *  - Algorithm Support
  38.  *  - Computation Support
  39.  *  - Function Analysis
  40.  *  - Model Validation
  41.  *  - Numerical Analysis
  42.  *  - Numerical Optimizer
  43.  *  - Spline Builder
  44.  *  - Statistical Learning
  45.  *
  46.  *  Documentation for DROP is Spread Over:
  47.  *
  48.  *  - Main                     => https://lakshmidrip.github.io/DROP/
  49.  *  - Wiki                     => https://github.com/lakshmiDRIP/DROP/wiki
  50.  *  - GitHub                   => https://github.com/lakshmiDRIP/DROP
  51.  *  - Repo Layout Taxonomy     => https://github.com/lakshmiDRIP/DROP/blob/master/Taxonomy.md
  52.  *  - Javadoc                  => https://lakshmidrip.github.io/DROP/Javadoc/index.html
  53.  *  - Technical Specifications => https://github.com/lakshmiDRIP/DROP/tree/master/Docs/Internal
  54.  *  - Release Versions         => https://lakshmidrip.github.io/DROP/version.html
  55.  *  - Community Credits        => https://lakshmidrip.github.io/DROP/credits.html
  56.  *  - Issues Catalog           => https://github.com/lakshmiDRIP/DROP/issues
  57.  *  - JUnit                    => https://lakshmidrip.github.io/DROP/junit/index.html
  58.  *  - Jacoco                   => https://lakshmidrip.github.io/DROP/jacoco/index.html
  59.  *
  60.  *  Licensed under the Apache License, Version 2.0 (the "License");
  61.  *      you may not use this file except in compliance with the License.
  62.  *  
  63.  *  You may obtain a copy of the License at
  64.  *      http://www.apache.org/licenses/LICENSE-2.0
  65.  *  
  66.  *  Unless required by applicable law or agreed to in writing, software
  67.  *      distributed under the License is distributed on an "AS IS" BASIS,
  68.  *      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  69.  *  
  70.  *  See the License for the specific language governing permissions and
  71.  *      limitations under the License.
  72.  */

  73. /**
  74.  * <i>LetchfordLodiCut</i> implements the Letchford-Lodi Cut. The References are:
  75.  *
  76.  * <br><br>
  77.  *  <ul>
  78.  *      <li>
  79.  *          Burdet, C. A., and E. L. Johnson (1977): A Sub-additive Approach to Solve Linear Integer Programs
  80.  *              <i>Annals of Discrete Mathematics</i> <b>1</b> 117-143
  81.  *      </li>
  82.  *      <li>
  83.  *          Chvatal, V. (1973): Edmonds Polytopes in a Hierarchy of Combinatorial Problems <i>Discrete
  84.  *              Mathematics</i> <b>4 (4)</b> 305-337
  85.  *      </li>
  86.  *      <li>
  87.  *          Gomory, R. E. (1958): Outline of an Algorithm for Integer Solutions to Linear Programs
  88.  *              <i>Bulletin of the American Mathematical Society</i> <b>64 (5)</b> 275-278
  89.  *      </li>
  90.  *      <li>
  91.  *          Kelley, J. E. (1960): The Cutting Plane Method for Solving Convex Problems <i>Journal for the
  92.  *              Society of the Industrial and Applied Mathematics</i> <b>8 (4)</b> 703-712
  93.  *      </li>
  94.  *      <li>
  95.  *          Letchford, A. N. and A. Lodi (2002): Strengthening Chvatal-Gomory Cuts and Gomory Fractional Cuts
  96.  *              <i>Operations Research Letters</i> <b>30 (2)</b> 74-82
  97.  *      </li>
  98.  *  </ul>
  99.  *
  100.  *  <br><br>
  101.  *  <ul>
  102.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/PortfolioCore.md">Portfolio Core Module</a></li>
  103.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/AssetAllocationAnalyticsLibrary.md">Asset Allocation Analytics</a></li>
  104.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/linearprogram/README.md">Linear Programming Solution Suite</a></li>
  105.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/linearprogram/cuttingplane/README.md">Polyhedral Cutting Plane Generation Schemes</a></li>
  106.  *  </ul>
  107.  *
  108.  * @author Lakshmi Krishnamurthy
  109.  */

  110. public class LetchfordLodiCut
  111.     extends org.drip.linearprogram.cuttingplane.ChvatalGomoryCut
  112. {

  113.     private static final java.util.Set<java.lang.Integer> Partition (
  114.         final double[] coefficientFractionArray)
  115.     {
  116.         java.util.Set<java.lang.Integer> partitionSet = new java.util.TreeSet<java.lang.Integer>();

  117.         int coefficientCount = coefficientFractionArray.length;
  118.         double a0Fraction = coefficientFractionArray[0];

  119.         for (int coefficientIndex = 1;
  120.             coefficientIndex < coefficientCount;
  121.             ++coefficientIndex)
  122.         {
  123.             if (a0Fraction >= coefficientFractionArray[coefficientIndex])
  124.             {
  125.                 partitionSet.add (
  126.                     coefficientIndex
  127.                 );
  128.             }
  129.         }

  130.         return partitionSet;
  131.     }

  132.     private static final java.util.Set<java.lang.Integer> Partition (
  133.         final double[] coefficientFractionArray,
  134.         final int k,
  135.         final int p)
  136.     {
  137.         java.util.Set<java.lang.Integer> partitionSet = new java.util.TreeSet<java.lang.Integer>();

  138.         int coefficientCount = coefficientFractionArray.length;
  139.         double oneMinusA0FractionOverK = (1. - coefficientFractionArray[0]) / k;
  140.         double upperBound = coefficientFractionArray[0] + oneMinusA0FractionOverK * p;
  141.         double lowerBound = coefficientFractionArray[0] + oneMinusA0FractionOverK * (p - 1);

  142.         for (int coefficientIndex = 1;
  143.             coefficientIndex < coefficientCount;
  144.             ++coefficientIndex)
  145.         {
  146.             if (lowerBound < coefficientFractionArray[coefficientIndex] &&
  147.                 upperBound >= coefficientFractionArray[coefficientIndex])
  148.             {
  149.                 partitionSet.add (
  150.                     coefficientIndex
  151.                 );
  152.             }
  153.         }

  154.         return partitionSet;
  155.     }

  156.     /**
  157.      * LetchfordLodiCut Constructor
  158.      *
  159.      * @param aGrid "A" Constraint Grid
  160.      * @param bArray "b" Constraint Array
  161.      * @param lambdaArray The Lambda Array
  162.      *
  163.      * @throws java.lang.Exception Thrown if the Inputs are Invalid
  164.      */

  165.     public LetchfordLodiCut (
  166.         final int[][] aGrid,
  167.         final int[] bArray,
  168.         final double[] lambdaArray)
  169.         throws java.lang.Exception
  170.     {
  171.         super (
  172.             aGrid,
  173.             bArray,
  174.             lambdaArray
  175.         );
  176.     }

  177.     /**
  178.      * Generate the Partition Map
  179.      *
  180.      * @return The Partition Map
  181.      */

  182.     public org.drip.linearprogram.cuttingplane.LetchfordLodiPartitionMap partitionMap()
  183.     {
  184.         double[] unadjustedCoefficientArray = unadjustedCoefficientArray();

  185.         if (null == unadjustedCoefficientArray)
  186.         {
  187.             return null;
  188.         }

  189.         int coefficientCount = unadjustedCoefficientArray.length;
  190.         double[] coefficientFractionArray = new double[coefficientCount];

  191.         if (0 == coefficientCount)
  192.         {
  193.             return null;
  194.         }

  195.         java.util.TreeMap<java.lang.Integer, java.util.Set<java.lang.Integer>> partitionMap =
  196.             new java.util.TreeMap<java.lang.Integer, java.util.Set<java.lang.Integer>>();

  197.         try
  198.         {
  199.             for (int coefficientIndex = 0;
  200.                 coefficientIndex < coefficientCount;
  201.                 ++coefficientIndex)
  202.             {
  203.                 coefficientFractionArray[coefficientIndex] =
  204.                     org.drip.numerical.common.NumberUtil.Fractional (
  205.                         unadjustedCoefficientArray[0]
  206.                     );
  207.             }

  208.             partitionMap.put (
  209.                 0,
  210.                 Partition (
  211.                     unadjustedCoefficientArray
  212.                 )
  213.             );

  214.             int k = org.drip.numerical.common.NumberUtil.ReciprocalIntegerFloor (
  215.                 coefficientFractionArray[0]
  216.             );

  217.             for (int p = 1;
  218.                 p <= k;
  219.                 ++p)
  220.             {
  221.                 partitionMap.put (
  222.                     p,
  223.                     Partition (
  224.                         unadjustedCoefficientArray,
  225.                         k,
  226.                         p
  227.                     )
  228.                 );
  229.             }

  230.             return new org.drip.linearprogram.cuttingplane.LetchfordLodiPartitionMap (
  231.                 k,
  232.                 unadjustedCoefficientArray,
  233.                 partitionMap
  234.             );
  235.         }
  236.         catch (java.lang.Exception e)
  237.         {
  238.             e.printStackTrace();
  239.         }

  240.         return null;
  241.     }

  242.     @Override public double[] adjustedCoefficientArray()
  243.     {
  244.         org.drip.linearprogram.cuttingplane.LetchfordLodiPartitionMap letchfordLodiPartitionMap =
  245.             partitionMap();

  246.         if (null == letchfordLodiPartitionMap)
  247.         {
  248.             return null;
  249.         }

  250.         java.util.TreeMap<java.lang.Integer, java.util.Set<java.lang.Integer>> partitionMap =
  251.             letchfordLodiPartitionMap.partitionMap();

  252.         double[] unadjustedCoefficientArray = letchfordLodiPartitionMap.unadjustedCoefficientArray();

  253.         int k = letchfordLodiPartitionMap.k();

  254.         int coefficientCount = unadjustedCoefficientArray.length;
  255.         double[] adjustedCoefficientArray = new double[coefficientCount];

  256.         for (int coefficientIndex = 0;
  257.             coefficientIndex < coefficientCount;
  258.             ++coefficientIndex)
  259.         {
  260.             adjustedCoefficientArray[coefficientIndex] = 0.;
  261.         }

  262.         try
  263.         {
  264.             for (int p = 0;
  265.                 p <= k;
  266.                 ++p)
  267.             {
  268.                 for (int listEntry : partitionMap.get (
  269.                     p
  270.                 ))
  271.                 {
  272.                     adjustedCoefficientArray[listEntry] += p +
  273.                         (k + 1) * ((int) unadjustedCoefficientArray[listEntry]);
  274.                 }
  275.             }
  276.         }
  277.         catch (java.lang.Exception e)
  278.         {
  279.             e.printStackTrace();

  280.             return null;
  281.         }

  282.         adjustedCoefficientArray[0] = (k + 1) * ((int) unadjustedCoefficientArray[0]);
  283.         return adjustedCoefficientArray;
  284.     }
  285. }