1 | /* $Id: ClpConstraint.cpp 1665 2011-01-04 17:55:54Z lou $ */ |
2 | // Copyright (C) 2007, International Business Machines |
3 | // Corporation and others. All Rights Reserved. |
4 | // This code is licensed under the terms of the Eclipse Public License (EPL). |
5 | |
6 | #include "CoinPragma.hpp" |
7 | #include "ClpSimplex.hpp" |
8 | #include "ClpConstraint.hpp" |
9 | |
10 | //############################################################################# |
11 | // Constructors / Destructor / Assignment |
12 | //############################################################################# |
13 | |
14 | //------------------------------------------------------------------- |
15 | // Default Constructor |
16 | //------------------------------------------------------------------- |
17 | ClpConstraint::ClpConstraint () : |
18 | lastGradient_(NULL), |
19 | functionValue_(0.0), |
20 | offset_(0.0), |
21 | type_(-1), |
22 | rowNumber_(-1) |
23 | { |
24 | |
25 | } |
26 | |
27 | //------------------------------------------------------------------- |
28 | // Copy constructor |
29 | //------------------------------------------------------------------- |
30 | ClpConstraint::ClpConstraint (const ClpConstraint & source) : |
31 | lastGradient_(NULL), |
32 | functionValue_(source.functionValue_), |
33 | offset_(source.offset_), |
34 | type_(source.type_), |
35 | rowNumber_(source.rowNumber_) |
36 | { |
37 | |
38 | } |
39 | |
40 | //------------------------------------------------------------------- |
41 | // Destructor |
42 | //------------------------------------------------------------------- |
43 | ClpConstraint::~ClpConstraint () |
44 | { |
45 | delete [] lastGradient_; |
46 | |
47 | } |
48 | |
49 | //---------------------------------------------------------------- |
50 | // Assignment operator |
51 | //------------------------------------------------------------------- |
52 | ClpConstraint & |
53 | ClpConstraint::operator=(const ClpConstraint& rhs) |
54 | { |
55 | if (this != &rhs) { |
56 | functionValue_ = rhs.functionValue_; |
57 | offset_ = rhs.offset_; |
58 | type_ = rhs.type_; |
59 | rowNumber_ = rhs.rowNumber_; |
60 | delete [] lastGradient_; |
61 | lastGradient_ = NULL; |
62 | } |
63 | return *this; |
64 | } |
65 | // Constraint function value |
66 | double |
67 | ClpConstraint::functionValue (const ClpSimplex * model, |
68 | const double * solution, |
69 | bool useScaling, |
70 | bool refresh) const |
71 | { |
72 | double offset; |
73 | double value; |
74 | int n = model->numberColumns(); |
75 | double * grad = new double [n]; |
76 | gradient(model, solution, grad, value, offset, useScaling, refresh); |
77 | delete [] grad; |
78 | return value; |
79 | } |
80 | |