source:trunk/Couenne/src/heuristics/CouenneFPpool.hpp@886

Last change on this file since 886 was 886, checked in by pbelotti, 19 months ago

partial unification of checkNLP. FP now take extra steps in-loop to find solutions using pool. Fixed NLPheur output

• Property svn:keywords set to `Id`
File size: 3.2 KB
Line
1/* \$Id\$
2 *
3 * Name:    CouenneFPpool.hpp
4 * Authors: Pietro Belotti
5 *          Timo Berthold, ZIB Berlin
6 * Purpose: Pool of MILP- (and why not? NLP-) feasible solutions for
7 *          restart use in the Feasibility Pump and sets of solutions
8 *          to be used as tabu list
9 *
11 */
12
13#ifndef CouenneFPpool_hpp
14#define CouenneFPpool_hpp
15
16#include <set>
17
18#include "CouenneTypes.hpp"
19#include "CoinFinite.hpp"
20
21namespace Couenne {
22
23  class CouenneProblem;
24  class CouenneFeasPump;
25
26  /// what term to compare: the sum of infeasibilities, the sum of
27  /// numbers of infeasible terms, or the objective function
28  static enum what_to_compare {SUM_NINF = 0, SUM_INF, OBJVAL, INTEGER_VARS} comparedTerm_;
29
30  /// Class containing a solution with infeasibility evaluation
31  class CouenneFPsolution {
32
33  protected:
34
35    CouNumber *x_;        ///< solution
36    int        n_;        ///< number of variables (for independence from CouenneProblem)
37    int        nNLinf_;   ///< number of NL      infeasibilities
38    int        nIinf_;    ///< number of integer infeasibilities
39    CouNumber  objVal_;   ///< objective function value
40    CouNumber  maxNLinf_; ///< maximum NL      infeasibility
41    CouNumber  maxIinf_;  ///< maximum integer infeasibility
42
43    /// This is a temporary copy, not really a solution holder. As a
44    /// result, all the above members are meaningless for copied
45    /// solutions
46
47    bool       copied_;
48
49    CouenneProblem *problem_; ///< holds pointer to problem to check
50                              ///< integrality in comparison of integer
51                              ///< variables
52
53  public:
54
55    CouenneFPsolution (CouenneProblem *p, CouNumber *x, bool copied = false); ///< CouenneProblem-aware constructor
56
57    CouenneFPsolution (const CouenneFPsolution &src); ///< copy constructor
58
59    CouenneFPsolution &operator= (const CouenneFPsolution &src); ///< assignment
60
61    ~CouenneFPsolution (); ///< destructor
62
63    /// returns size
64    const int n () const {return n_;}
65
66    /// returns vector
67    const double *x () const {return x_;}
68
69    /// basic comparison procedure -- what to compare depends on user's choice
70    bool compare (const CouenneFPsolution &other, enum what_to_compare comparedTerm) const;
71  };
72
73
74  /// compare, base version
75  inline bool operator< (const CouenneFPsolution &one,
76                         const CouenneFPsolution &two)
77  {return one.compare (two, comparedTerm_);}
78
79
80  /// class for comparing solutions (used in tabu list)
81  class compareSol {
82
83  public:
84    bool operator () (const CouenneFPsolution &one,
85                      const CouenneFPsolution &two) const;
86  };
87
88
89  /// Pool of solutions
90  class CouenneFPpool {
91
92  protected:
93
94    /// Pool
95    std::set <CouenneFPsolution> set_;
96
97  public:
98
99    /// simple constructor (empty pool)
100    CouenneFPpool (enum what_to_compare c)
101    {comparedTerm_ = c;}
102
103    /// copy constructor
104    CouenneFPpool (const CouenneFPpool &src);
105
106    /// assignment
107    CouenneFPpool &operator= (const CouenneFPpool &src);
108
109    /// return the main object in this class
110    std::set <CouenneFPsolution> &Set ()
111    {return set_;}
112
113    /// finds, in pool, solution x closest to sol; removes it from the
114    /// pool and overwrites it to sol
115    void findClosestAndReplace (double *sol, double *nSol, int nvars) ;
116  };
117}
118
119#endif
Note: See TracBrowser for help on using the repository browser.