3
|
1 // Bounds.cc -*- C++ -*- |
|
2 /* |
|
3 |
|
4 Copyright (C) 1992, 1993 John W. Eaton |
|
5 |
|
6 This file is part of Octave. |
|
7 |
|
8 Octave is free software; you can redistribute it and/or modify it |
|
9 under the terms of the GNU General Public License as published by the |
|
10 Free Software Foundation; either version 2, or (at your option) any |
|
11 later version. |
|
12 |
|
13 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
16 for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
|
19 along with Octave; see the file COPYING. If not, write to the Free |
|
20 Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
|
21 |
|
22 */ |
|
23 |
|
24 #ifdef __GNUG__ |
|
25 #pragma implementation |
|
26 #endif |
|
27 |
|
28 #include <iostream.h> |
|
29 #include "Bounds.h" |
|
30 |
|
31 // error handling |
|
32 |
|
33 void |
|
34 Bounds::error (const char* msg) |
|
35 { |
|
36 cerr << "Fatal bounds error. " << msg << "\n"; |
|
37 exit(1); |
|
38 } |
|
39 |
|
40 Bounds::Bounds (void) |
|
41 { |
|
42 nb = 0; |
|
43 } |
|
44 |
|
45 Bounds::Bounds (int n) |
|
46 { |
|
47 nb = n; |
|
48 lb.resize (nb); |
|
49 ub.resize (nb); |
|
50 lb.fill (0.0); |
|
51 ub.fill (0.0); |
|
52 } |
|
53 |
|
54 Bounds::Bounds (const ColumnVector l, const ColumnVector u) |
|
55 { |
|
56 if (l.capacity () != u.capacity ()) |
|
57 error ("inconsistent sizes for lower and upper bounds"); |
|
58 |
|
59 nb = l.capacity (); |
|
60 lb = l; |
|
61 ub = u; |
|
62 } |
|
63 |
|
64 Bounds::Bounds (const Bounds& a) |
|
65 { |
|
66 nb = a.size (); |
|
67 lb = a.lower_bounds (); |
|
68 ub = a.upper_bounds (); |
|
69 } |
|
70 |
|
71 Bounds& |
|
72 Bounds::operator = (const Bounds& a) |
|
73 { |
|
74 nb = a.size (); |
|
75 lb = a.lower_bounds (); |
|
76 ub = a.upper_bounds (); |
|
77 |
|
78 return *this; |
|
79 } |
|
80 |
|
81 Bounds& |
|
82 Bounds::resize (int n) |
|
83 { |
|
84 nb = n; |
|
85 lb.resize (nb); |
|
86 ub.resize (nb); |
|
87 |
|
88 return *this; |
|
89 } |
|
90 |
|
91 double |
|
92 Bounds::lower_bound (int index) const |
|
93 { |
|
94 return lb.elem (index); |
|
95 } |
|
96 |
|
97 double |
|
98 Bounds::upper_bound (int index) const |
|
99 { |
|
100 return ub.elem (index); |
|
101 } |
|
102 |
|
103 ColumnVector |
|
104 Bounds::lower_bounds (void) const |
|
105 { |
|
106 return lb; |
|
107 } |
|
108 |
|
109 ColumnVector |
|
110 Bounds::upper_bounds (void) const |
|
111 { |
|
112 return ub; |
|
113 } |
|
114 |
|
115 int |
|
116 Bounds::size (void) const |
|
117 { |
|
118 return nb; |
|
119 } |
|
120 |
|
121 Bounds& |
|
122 Bounds::set_bound (int index, double low, double high) |
|
123 { |
|
124 lb.elem (index) = low; |
|
125 ub.elem (index) = high; |
|
126 |
|
127 return *this; |
|
128 } |
|
129 |
|
130 Bounds& |
|
131 Bounds::set_bounds (double low, double high) |
|
132 { |
|
133 lb.fill (low); |
|
134 ub.fill (high); |
|
135 |
|
136 return *this; |
|
137 } |
|
138 |
|
139 Bounds& |
|
140 Bounds::set_bounds (const ColumnVector l, const ColumnVector u) |
|
141 { |
|
142 if (l.capacity () != u.capacity ()) |
|
143 error ("inconsistent sizes for lower and upper bounds"); |
|
144 |
|
145 nb = l.capacity (); |
|
146 lb = l; |
|
147 ub = u; |
|
148 |
|
149 return *this; |
|
150 } |
|
151 |
|
152 Bounds& |
|
153 Bounds::set_lower_bound (int index, double low) |
|
154 { |
|
155 lb.elem (index) = low; |
|
156 |
|
157 return *this; |
|
158 } |
|
159 |
|
160 Bounds& |
|
161 Bounds::set_upper_bound (int index, double high) |
|
162 { |
|
163 ub.elem (index) = high; |
|
164 |
|
165 return *this; |
|
166 } |
|
167 |
|
168 Bounds& |
|
169 Bounds::set_lower_bounds (double low) |
|
170 { |
|
171 lb.fill (low); |
|
172 |
|
173 return *this; |
|
174 } |
|
175 |
|
176 Bounds& |
|
177 Bounds::set_upper_bounds (double high) |
|
178 { |
|
179 ub.fill (high); |
|
180 |
|
181 return *this; |
|
182 } |
|
183 |
|
184 Bounds& |
|
185 Bounds::set_lower_bounds (const ColumnVector l) |
|
186 { |
|
187 if (nb != l.capacity ()) |
|
188 error ("inconsistent size for lower bounds"); |
|
189 |
|
190 lb = l; |
|
191 |
|
192 return *this; |
|
193 } |
|
194 |
|
195 Bounds& |
|
196 Bounds::set_upper_bounds (const ColumnVector u) |
|
197 { |
|
198 if (nb != u.capacity ()) |
|
199 error ("inconsistent size for upper bounds"); |
|
200 |
|
201 ub = u; |
|
202 |
|
203 return *this; |
|
204 } |
|
205 |
|
206 ostream& |
|
207 operator << (ostream& os, const Bounds& b) |
|
208 { |
|
209 for (int i = 0; i < b.size (); i++) |
|
210 os << b.lower_bound (i) << " " << b.upper_bound (i) << "\n"; |
|
211 |
|
212 return os; |
|
213 } |
|
214 |
|
215 /* |
|
216 ;;; Local Variables: *** |
|
217 ;;; mode: C++ *** |
|
218 ;;; page-delimiter: "^/\\*" *** |
|
219 ;;; End: *** |
|
220 */ |