source: trunk/include/ClpNonLinearCost.hpp @ 2

Last change on this file since 2 was 2, checked in by forrest, 18 years ago

Adding Clp to development branch

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.8 KB
Line 
1// Copyright (C) 2002, International Business Machines
2// Corporation and others.  All Rights Reserved.
3#ifndef ClpNonLinearCost_H
4#define ClpNonLinearCost_H
5
6#if defined(_MSC_VER)
7// Turn off compiler warning about long names
8#  pragma warning(disable:4786)
9#endif
10
11class ClpSimplex;
12class OsiIndexedVector;
13
14/** Trivial class to deal with non linear costs
15
16    I don't make any explicit assumptions about convexity but I am
17    sure I do make implicit ones.
18
19    One interesting idea for normal LP's will be to allow non-basic
20    variables to come into basis as infeasible i.e. if variable at
21    lower bound has very large positive reduced cost (when problem
22    is infeasible) could it reduce overall problem infeasibility more
23    by bringing it into basis below its lower bound.
24
25    Another feature would be to automatically discover when problems
26    are convex piecewise linear and re-formulate to use non-linear.
27    I did some work on this many years ago on "grade" problems, but
28    while it improved primal interior point algorithms were much better
29    for that particular problem.
30*/
31
32class ClpNonLinearCost  {
33 
34public:
35 
36public:
37
38  /**@name Constructors, destructor */
39  //@{
40  /// Default constructor.
41  ClpNonLinearCost();
42  /** Constructor from simplex.
43      This will just set up wasteful arrays for linear, but
44      later may do dual analysis and even finding duplicate columns
45  */
46  ClpNonLinearCost(ClpSimplex * model);
47  /** Constructor from simplex and list of non-linearities (columns only)
48      First lower of each column has to match real lower
49      Last lower has to be <= upper (if == then cost ignored)
50      This could obviously be changed to make more user friendly
51  */
52  ClpNonLinearCost(ClpSimplex * model,const int * starts,
53                   const double * lower, const double * cost);
54  /// Destructor
55  ~ClpNonLinearCost();
56  // Copy
57  ClpNonLinearCost(const ClpNonLinearCost&);
58  // Assignment
59  ClpNonLinearCost& operator=(const ClpNonLinearCost&);
60  //@}
61     
62
63  /**@name Actual work in primal */
64  //@{
65  /** Changes infeasible costs and computes number and cost of infeas
66      Puts all non-basic (non free) variables to bounds
67      and all free variables to zero if toNearest true*/
68  void checkInfeasibilities(bool toNearest=false);
69  /** Changes infeasible costs for each variable
70      The indices are row indices and need converting to sequences
71  */
72  void checkInfeasibilities(int numberInArray, const int * index);
73  /** Puts back correct infeasible costs for each variable
74      The input indices are row indices and need converting to sequences
75      for costs.
76      On input array is empty (but indices exist).  On exit just
77      changed costs will be stored as normal OsiIndexedVector
78  */
79  void checkChanged(int numberInArray, OsiIndexedVector * update);
80  /** Goes through one bound for each variable.
81      If multiplier*work[iRow]>0 goes down, otherwise up.
82      The indices are row indices and need converting to sequences
83      Temporary offsets may be set
84      Rhs entries are increased
85  */
86  void goThru(int numberInArray, double multiplier,
87              const int * index, const double * work,
88              double * rhs);
89  /** Takes off last iteration (i.e. offsets closer to 0)
90  */
91  void goBack(int numberInArray, const int * index, 
92              double * rhs);
93  /** Puts back correct infeasible costs for each variable
94      The input indices are row indices and need converting to sequences
95      for costs.
96      At the end of this all temporary offsets are zero
97  */
98  void goBackAll(const OsiIndexedVector * update);
99  /** Sets bounds and cost for one variable
100      Returns change in cost
101   May need to be inline for speed */
102  double setOne(int sequence, double solutionValue);
103  /// Returns nearest bound
104  double nearest(int sequence, double solutionValue);
105  /** Returns change in cost - one down if alpha >0.0, up if <0.0
106      Value is current - new
107   */
108  inline double changeInCost(int sequence, double alpha) const
109  {
110    int iRange = whichRange_[sequence]+offset_[sequence];
111    if (alpha>0.0)
112      return cost_[iRange]-cost_[iRange-1];
113    else
114      return cost_[iRange]-cost_[iRange+1];
115  }
116  /// Returns current lower bound
117  inline double lower(int sequence) const
118  { return lower_[whichRange_[sequence]+offset_[sequence]];};
119  /// Returns current upper bound
120  inline double upper(int sequence) const
121  { return lower_[whichRange_[sequence]+offset_[sequence]+1];};
122  /// Returns current cost
123  inline double cost(int sequence) const
124  { return cost_[whichRange_[sequence]+offset_[sequence]];};
125  //@}
126
127
128  /**@name Gets and sets */
129  //@{
130  /// Number of infeasibilities
131  inline int numberInfeasibilities() const
132  {return numberInfeasibilities_;};
133  /// Change in cost
134  inline double changeInCost() const
135  {return changeCost_;};
136  /// Largest infeasibility
137  inline double largestInfeasibility() const
138  {return largestInfeasibility_;};
139  inline void setChangeInCost(double value) 
140  {changeCost_ = value;};
141  //@}
142   
143private:
144  /**@name Data members */
145  //@{
146  /// Number of rows (mainly for checking and copy)
147  int numberRows_;
148  /// Number of columns (mainly for checking and copy)
149  int numberColumns_;
150  /// Starts for each entry (columns then rows)
151  int * start_;
152  /// Range for each entry (columns then rows)
153  int * whichRange_;
154  /// Temporary range offset for each entry (columns then rows)
155  int * offset_;
156  /** Lower bound for each range (upper bound is next lower).
157      For various reasons there is always an infeasible range
158      at bottom - even if lower bound is - infinity */
159  double * lower_;
160  /// Cost for each range
161  double * cost_;
162  /// Model
163  ClpSimplex * model_;
164  /// Number of infeasibilities found
165  int numberInfeasibilities_;
166  /// Change in cost because of infeasibilities
167  double changeCost_;
168  /// Largest infeasibility
169  double largestInfeasibility_;
170  /// If all non-linear costs convex
171  bool convex_;
172  //@}
173};
174
175#endif
Note: See TracBrowser for help on using the repository browser.