source: trunk/ClpLinearObjective.cpp @ 124

Last change on this file since 124 was 124, checked in by forrest, 17 years ago

Hopefully this will fix tag problem

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.0 KB
Line 
1// Copyright (C) 2003, International Business Machines
2// Corporation and others.  All Rights Reserved.
3
4#include "CoinPragma.hpp"
5#include "ClpModel.hpp"
6#include "ClpLinearObjective.hpp"
7
8//#############################################################################
9// Constructors / Destructor / Assignment
10//#############################################################################
11
12//-------------------------------------------------------------------
13// Default Constructor
14//-------------------------------------------------------------------
15ClpLinearObjective::ClpLinearObjective () 
16: ClpObjective()
17{
18  type_=1;
19  objective_=NULL;
20  numberColumns_=0;
21}
22
23//-------------------------------------------------------------------
24// Useful Constructor
25//-------------------------------------------------------------------
26ClpLinearObjective::ClpLinearObjective (const double * objective , 
27                                        int numberColumns) 
28  : ClpObjective()
29{
30  type_=1;
31  numberColumns_=numberColumns;
32  if (objective) {
33    objective_ = new double [numberColumns_];
34    memcpy(objective_,objective,numberColumns_*sizeof(double));
35  } else {
36    objective_ = new double [numberColumns_];
37    memset(objective_,0,numberColumns_*sizeof(double));
38  }
39}
40
41//-------------------------------------------------------------------
42// Copy constructor
43//-------------------------------------------------------------------
44ClpLinearObjective::ClpLinearObjective (const ClpLinearObjective & rhs) 
45: ClpObjective(rhs)
46{ 
47  numberColumns_=rhs.numberColumns_;
48  if (rhs.objective_) {
49    objective_ = new double [numberColumns_];
50    memcpy(objective_,rhs.objective_,numberColumns_*sizeof(double));
51  } else {
52    objective_=NULL;
53  }
54}
55
56//-------------------------------------------------------------------
57// Destructor
58//-------------------------------------------------------------------
59ClpLinearObjective::~ClpLinearObjective ()
60{
61  delete [] objective_;
62}
63
64//----------------------------------------------------------------
65// Assignment operator
66//-------------------------------------------------------------------
67ClpLinearObjective &
68ClpLinearObjective::operator=(const ClpLinearObjective& rhs)
69{
70  if (this != &rhs) {
71    ClpObjective::operator=(rhs);
72    numberColumns_=rhs.numberColumns_;
73    if (rhs.objective_) {
74      objective_ = new double [numberColumns_];
75      memcpy(objective_,rhs.objective_,numberColumns_*sizeof(double));
76    } else {
77      objective_=NULL;
78    }
79  }
80  return *this;
81}
82
83// Returns gradient
84double * 
85ClpLinearObjective::gradient(const double * solution, double & offset)
86{
87  offset=0.0;
88  return objective_;
89}
90 
91//-------------------------------------------------------------------
92// Clone
93//-------------------------------------------------------------------
94ClpObjective * ClpLinearObjective::clone() const
95{
96  return new ClpLinearObjective(*this);
97}
98// Resize objective
99void 
100ClpLinearObjective::resize(int newNumberColumns)
101{
102  if (numberColumns_!=newNumberColumns) {
103    int i;
104    double * newArray = new double[newNumberColumns];
105    if (objective_)
106      memcpy(newArray,objective_,
107             min(newNumberColumns,numberColumns_)*sizeof(double));
108    delete [] objective_;
109    objective_ = newArray;
110    for (i=numberColumns_;i<newNumberColumns;i++) 
111      objective_[i]=0.0;
112    numberColumns_ = newNumberColumns;
113  } 
114 
115}
116// Delete columns in  objective
117void 
118ClpLinearObjective::deleteSome(int numberToDelete, const int * which) 
119{
120  if (objective_) {
121    int i ;
122    char * deleted = new char[numberColumns_];
123    int numberDeleted=0;
124    memset(deleted,0,numberColumns_*sizeof(char));
125    for (i=0;i<numberToDelete;i++) {
126      int j = which[i];
127      if (j>=0&&j<numberColumns_&&!deleted[j]) {
128        numberDeleted++;
129        deleted[j]=1;
130      }
131    }
132    int newNumberColumns = numberColumns_-numberDeleted;
133    double * newArray = new double[newNumberColumns];
134    int put=0;
135    for (i=0;i<numberColumns_;i++) {
136      if (!deleted[i]) {
137        newArray[put++]=objective_[i];
138      }
139    }
140    delete [] objective_;
141    objective_ = newArray;
142    delete [] deleted;
143    numberColumns_ = newNumberColumns;
144  }
145}
146
Note: See TracBrowser for help on using the repository browser.