1 /*===========================================================================*
2 * This file is part of the Bcps Linear Solver (BLIS). *
3 * *
4 * BLIS is distributed under the Eclipse Public License as part of the *
5 * COIN-OR repository (http://www.coin-or.org). *
6 * *
7 * Authors: *
8 * *
9 * Yan Xu, Lehigh University *
10 * Ted Ralphs, Lehigh University *
11 * *
12 * Conceptual Design: *
13 * *
14 * Yan Xu, Lehigh University *
15 * Ted Ralphs, Lehigh University *
16 * Laszlo Ladanyi, IBM T.J. Watson Research Center *
17 * Matthew Saltzman, Clemson University *
18 * *
19 * *
20 * Copyright (C) 2001-2017, Lehigh University, Yan Xu, and Ted Ralphs. *
21 * All Rights Reserved. *
22 *===========================================================================*/
23
24 #include "BlisConstraint.h"
25 #include "BlisModel.h"
26
27 //#############################################################################
28
29 /* Default constructor. */
BlisConstraint()30 BlisConstraint::BlisConstraint()
31 :size_(0), indices_(NULL), values_(NULL) {}
32
33 //#############################################################################
34
35 /* Useful constructor. */
BlisConstraint(int s,const int * ind,const double * val)36 BlisConstraint::BlisConstraint(int s, const int *ind, const double *val)
37 {
38 size_ = s;
39 indices_ = new int [s];
40 values_ = new double [s];
41 memcpy(indices_, ind, s * sizeof(int));
42 memcpy(values_, val, s * sizeof(double));
43 }
44
45 //#############################################################################
46
47 /* Useful constructor. */
BlisConstraint(double lbh,double ubh,double lbs,double ubs)48 BlisConstraint::BlisConstraint(double lbh, double ubh, double lbs, double ubs)
49 :
50 BcpsConstraint(lbh, ubh, lbs, ubs),
51 size_(0), indices_(NULL), values_(NULL) {}
52
53 //#############################################################################
54
55 /* Useful constructor. */
BlisConstraint(double lbh,double ubh,double lbs,double ubs,int s,const int * ind,const double * val)56 BlisConstraint::BlisConstraint(double lbh, double ubh, double lbs, double ubs,
57 int s, const int *ind, const double *val)
58 :
59 BcpsConstraint(lbh, ubh, lbs, ubs)
60 {
61 size_ = s;
62 indices_ = new int [s];
63 values_ = new double [s];
64 memcpy(indices_, ind, s * sizeof(int));
65 memcpy(values_, val, s * sizeof(double));
66 }
67
68 //#############################################################################
69
70 /** Destructor. */
~BlisConstraint()71 BlisConstraint::~BlisConstraint()
72 {
73 delete [] indices_; indices_ = NULL;
74 delete [] values_; values_ = NULL;
75 }
76
77 //#############################################################################
78
79 /** Copy constructor. */
BlisConstraint(const BlisConstraint & rhs)80 BlisConstraint::BlisConstraint(const BlisConstraint & rhs)
81 : BcpsConstraint(rhs)
82 {
83 size_ = rhs.size_;
84
85 if (size_ <= 0) {
86 std::cout << "ERROR: size_ = " << size_ << std::endl;
87 assert(size_);
88 }
89 if (size_ > 0) {
90 indices_ = new int [size_];
91 values_ = new double [size_];
92 memcpy(indices_, rhs.indices_, size_ * sizeof(int));
93 memcpy(values_, rhs.values_, size_ * sizeof(double));
94 }
95 else {
96 indices_ = NULL;
97 values_ = NULL;
98 }
99 }
100
101 //#############################################################################
102
infeasibility(BcpsModel * m,int & preferredWay) const103 double BlisConstraint::infeasibility(BcpsModel * m,
104 int & preferredWay) const {
105 std::cerr << "Not implemented, " << std::endl
106 << "file: " << __FILE__ << std::endl
107 << "line: " << __LINE__ << std::endl;
108 throw std::exception();
109 return 0.0;
110 }
111
112 /// Encode this to an AlpsEncoded object.
encode(AlpsEncoded * encoded)113 AlpsReturnStatus BlisConstraint::encode(AlpsEncoded * encoded) {
114 std::cerr << "Not implemented, " << std::endl
115 << "file: " << __FILE__ << std::endl
116 << "line: " << __LINE__ << std::endl;
117 throw std::exception();
118 return AlpsReturnStatusOk;
119 }
120
121 /// Decode a given AlpsEncoded object to an AlpsKnowledge object and return a
122 /// pointer to it.
decode(AlpsEncoded & encoded) const123 AlpsKnowledge * BlisConstraint::decode(AlpsEncoded & encoded) const {
124 std::cerr << "Not implemented, " << std::endl
125 << "file: " << __FILE__ << std::endl
126 << "line: " << __LINE__ << std::endl;
127 throw std::exception();
128 BlisConstraint * con = new BlisConstraint();
129 return con;
130 }
131
132 /// Decode a given AlpsEncoded object into self.
decodeToSelf(AlpsEncoded & encoded)133 AlpsReturnStatus BlisConstraint::decodeToSelf(AlpsEncoded & encoded) {
134 std::cerr << "Not implemented, " << std::endl
135 << "file: " << __FILE__ << std::endl
136 << "line: " << __LINE__ << std::endl;
137 throw std::exception();
138 return AlpsReturnStatusOk;
139 }
140
141 //#############################################################################
142
143 /** Compute hash value. */
144 void
hashing(BcpsModel * model)145 BlisConstraint::hashing(BcpsModel *model)
146 {
147 assert(model != NULL);
148 BlisModel *m = dynamic_cast<BlisModel *>(model);
149
150 int k, ind;
151 const double * randoms = m->getConRandoms();
152
153 hashValue_ = 0.0;
154 for (k = 0; k < size_; ++k) {
155 ind = indices_[k];
156 hashValue_ += randoms[ind] * ind;
157 }
158 #ifdef BLIS_DEBUG_MORE
159 std::cout << "hashValue_=" << hashValue_ << std::endl;
160 #endif
161 }
162
163 //#############################################################################
164 //#############################################################################
165