CglLandPValidator.hpp 3.73 KB
Newer Older
Valentin Platzgummer's avatar
Valentin Platzgummer committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
// Copyright (C) 2005-2009, Pierre Bonami and others.  All Rights Reserved.
// Author:   Pierre Bonami
//           Tepper School of Business
//           Carnegie Mellon University, Pittsburgh, PA 15213
// Date:     11/22/05
//
// $Id$
//
// This code is licensed under the terms of the Eclipse Public License (EPL).
//---------------------------------------------------------------------------

#ifndef CglLandPValidator_H
#define CglLandPValidator_H
#include "OsiSolverInterface.hpp"
#include "CglParam.hpp"
#include <vector>

/** constants describing rejection codes*/
//[5] = {"Accepted", "violation too small", "small coefficient too small", "big dynamic","too dense"}


namespace LAP
{

/** Class to validate or reject a cut */
class Validator
{
public:
    /** Reasons for rejecting a cut */
    enum RejectionsReasons
    {
        NoneAccepted=0 /**Cut was accepted*/,
        SmallViolation /** Violation of the cut is too small */,
        SmallCoefficient /** There is a small coefficient we can not get rid off.*/,
        BigDynamic /** Dynamic of coefficinet is too important. */,
        DenseCut/**cut is too dense */,
        EmptyCut/**After cleaning cut has become empty*/,
        DummyEnd/** dummy*/
    };

    /** Constructor with default values */
    Validator(double maxFillIn = 1.,
              double maxRatio = 1e8,
              double minViolation = 0,
              bool scale = false,
              double rhsScale = 1);

    /** Clean an OsiCut */
    int cleanCut(OsiRowCut & aCut, const double * solCut,const OsiSolverInterface &si, const CglParam & par,
                 const double * colLower, const double * colUpper);
    /** Clean an OsiCut by another method */
    int cleanCut2(OsiRowCut & aCut, const double * solCut, const OsiSolverInterface &si, const CglParam & par,
                  const double * colLower, const double * colUpper);
    /** Call the cut cleaner */
    int operator()(OsiRowCut & aCut, const double * solCut,const OsiSolverInterface &si, const CglParam & par,
                   const double * colLower, const double * colUpper)
    {
        return cleanCut(aCut, solCut, si, par, colLower, colUpper);
    }
    /** @name set functions */
    /** @{ */
    void setMaxFillIn(double value)
    {
        maxFillIn_ = value;
    }
    void setMaxRatio(double value)
    {
        maxRatio_ = value;
    }
    void setMinViolation(double value)
    {
        minViolation_ = value;
    }

    void setRhsScale(double v)
    {
        rhsScale_ = v;
    }
    /** @} */
    /** @name get functions */
    /** @{ */
    double getMaxFillIn()
    {
        return maxFillIn_;
    }
    double getMaxRatio()
    {
        return maxRatio_;
    }
    double getMinViolation()
    {
        return minViolation_;
    }
    /** @} */

    const char* failureString(RejectionsReasons code) const
    {
        return rejections_[static_cast<int> (code)];
    }
    const char* failureString(int code) const
    {
        return rejections_[ code];
    }
    int numRejected(RejectionsReasons code)const
    {
        return numRejected_[static_cast<int> (code)];
    }
    int numRejected(int code)const
    {
        return numRejected_[ code];
    }
private:
    /** max percentage of given formulation fillIn should be accepted for cut fillin.*/
    double maxFillIn_;
    /** max ratio between smallest and biggest coefficient */
    double maxRatio_;
    /** minimum violation for accepting a cut */
    double minViolation_;
    /** Do we do scaling? */
    bool scale_;
    /** Scale of right-hand-side.*/
    double rhsScale_;
    /** Strings explaining reason for rejections */
    static const char* rejections_[DummyEnd];
    /** Number of cut rejected for each of the reasons.*/
    std::vector<int> numRejected_;
};

}/* Ends namespace LAP.*/
#endif