source: branches/devel/Cbc/examples/ClpDynamicInterface.hpp @ 403

Last change on this file since 403 was 403, checked in by forrest, 13 years ago

adding some examples

File size: 5.4 KB
Line 
1// Copyright (C) 2006, International Business Machines
2// Corporation and others.  All Rights Reserved.
3
4#ifndef ClpDynamicInterface_H
5#define ClpDynamicInterface_H
6
7#include "OsiClpSolverInterface.hpp"
8#include "CoinWarmStartBasisDynamic.hpp"
9
10//#############################################################################
11
12/**
13
14    This is to allow the user to replace initialSolve and resolve
15*/
16class CbcModel;
17class ClpDynamicInterface : public OsiClpSolverInterface {
18
19public:
20  //---------------------------------------------------------------------------
21  /**@name Solve methods */
22  //@{
23    /// Solve initial LP relaxation
24    virtual void initialSolve();
25
26    /// Resolve an LP relaxation after problem modification
27    virtual void resolve();
28
29  //@}
30
31
32  /**@name Constructors and destructors */
33  //@{
34    /// Default Constructor
35    ClpDynamicInterface ();
36   
37    /// Clone
38    virtual OsiSolverInterface * clone(bool CopyData=true) const;
39   
40    /// Copy constructor
41    ClpDynamicInterface (const ClpDynamicInterface &);
42   
43    /// Assignment operator
44    ClpDynamicInterface & operator=(const ClpDynamicInterface& rhs);
45   
46    /// Destructor
47    virtual ~ClpDynamicInterface ();
48
49  //@}
50
51
52  /**@name Sets and Gets */
53  //@{
54  /** Setup */
55  void initialize(int * rowBlock,CbcModel * model);
56  /// Model
57  inline void setCbcModel(CbcModel * model)
58  { cbcModel_=model;};
59  /** Warm start
60     
61  NOTE  artificials are treated as +1 elements so for <= rhs
62  artificial will be at lower bound if constraint is tight
63 
64  This means that Clpsimplex flips artificials as it works
65  in terms of row activities
66  */
67  CoinWarmStartBasisDynamic getBasis(ClpSimplex * model, const int * whichColumns,
68                                     int numberCommon) const;
69  /** Sets up working basis as a copy of input
70     
71  NOTE  artificials are treated as +1 elements so for <= rhs
72  artificial will be at lower bound if constraint is tight
73 
74  This means that Clpsimplex flips artificials as it works
75  in terms of row activities
76  */
77  void setBasis( const CoinWarmStartBasisDynamic & basis, ClpSimplex * model);
78
79  /// Objective value of best solution found internally
80  inline double bestObjectiveValue() const
81  { return bestObjectiveValue_;};
82  /// Best solution found internally
83  const double * bestSolution() const
84  { return bestSolution_;};
85  //@}
86
87  //---------------------------------------------------------------------------
88
89private:
90  /// Adds proposals to model (only if not there)
91  void addProposals(ClpSimplex * model, int number, const int * which,
92                    bool addEvenIfFixed);
93  /** Creates modelPtr_ solution.
94      Returns 1 if not feasible, -1 if integer solution
95      0 otherwise */
96  int setSolution(ClpSimplex * model);
97private:
98 
99  /**@name Private member data */
100  //@{
101  // Will have decomposition here
102  /// Number of blocks
103  int numberBlocks_;
104  /// Number of artificials to make problem feasible
105  int numberArtificials_;
106  /// Static part of model plus convexity rows
107  ClpSimplex * staticModel_;
108  /// Columns for each block
109  ClpSimplex * subProblem_;
110  /// Master part of each block
111  CoinPackedMatrix * masterRow_;
112  /** Proposals
113      Rows 0-masterRows-1 are elements
114      Next row is convexity row (so gives block)
115      Next (==masterRows+convexity) is cost
116      Next are weights for columns
117  */
118  CoinPackedMatrix proposals_;
119  /// Number of proposals added to current problem
120  int numberProposalsAdded_;
121  /// Maximum number of proposals added to current problem (size of list)
122  int maximumProposalsAdded_;
123  /// List of proposals added
124  int * proposalsAdded_;
125  /// Backward pointers to original for each sub-problem
126  int ** backward_;
127  /** If nonzero then says all possible columns generated -
128      and gives number */
129  int * allGenerated_;
130  /// Pointer back to model
131  CbcModel * cbcModel_;
132  /// Objective value of best solution found internally
133  double bestObjectiveValue_;
134  /// Best solution found internally
135  double * bestSolution_;
136  /** Warmstart information to be used in resolves. */
137  CoinWarmStartBasisDynamic dynamicBasis_;
138  //@}
139};
140#include "CbcHeuristic.hpp"
141/** heuristic - just picks up any good solution
142 */
143
144class CbcHeuristicDynamic : public CbcHeuristic {
145public:
146
147  // Default Constructor
148  CbcHeuristicDynamic ();
149
150  /* Constructor with model
151  */
152  CbcHeuristicDynamic (CbcModel & model);
153 
154  // Copy constructor
155  CbcHeuristicDynamic ( const CbcHeuristicDynamic &);
156   
157  // Destructor
158  ~CbcHeuristicDynamic ();
159 
160  /// Clone
161  virtual CbcHeuristic * clone() const;
162
163  /// update model
164  virtual void setModel(CbcModel * model);
165 
166  /** returns 0 if no solution, 1 if valid solution.
167      Sets solution values if good, sets objective value (only if good)
168      We leave all variables which are at one at this node of the
169      tree to that value and will
170      initially set all others to zero.  We then sort all variables in order of their cost
171      divided by the number of entries in rows which are not yet covered.  We randomize that
172      value a bit so that ties will be broken in different ways on different runs of the heuristic.
173      We then choose the best one and set it to one and repeat the exercise. 
174
175  */
176  virtual int solution(double & objectiveValue,
177                       double * newSolution);
178  /// Resets stuff if model changes
179  virtual void resetModel(CbcModel * model);
180
181protected:
182private:
183  /// Illegal Assignment operator
184  CbcHeuristicDynamic & operator=(const CbcHeuristicDynamic& rhs);
185};
186
187#endif
Note: See TracBrowser for help on using the repository browser.