3
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
3
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
7016
|
9 Free Software Foundation; either version 3 of the License, or (at your |
|
10 option) any later version. |
3
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
7016
|
18 along with Octave; see the file COPYING. If not, see |
|
19 <http://www.gnu.org/licenses/>. |
3
|
20 |
|
21 */ |
|
22 |
382
|
23 #if !defined (octave_Bounds_h) |
|
24 #define octave_Bounds_h 1 |
|
25 |
3503
|
26 #include <iostream> |
461
|
27 |
|
28 #include "dColVector.h" |
384
|
29 |
1869
|
30 class |
|
31 Bounds |
3
|
32 { |
|
33 public: |
|
34 |
1869
|
35 Bounds (void) |
|
36 : lb (), ub () { } |
|
37 |
5275
|
38 Bounds (octave_idx_type n) |
1869
|
39 : lb (n, 0.0), ub (n, 0.0) { } |
1528
|
40 |
1869
|
41 Bounds (const ColumnVector l, const ColumnVector u) |
|
42 : lb (l), ub (u) |
|
43 { |
|
44 if (lb.capacity () != ub.capacity ()) |
|
45 { |
|
46 error ("inconsistent sizes for lower and upper bounds"); |
|
47 return; |
|
48 } |
|
49 } |
3
|
50 |
1528
|
51 Bounds (const Bounds& a) |
1869
|
52 : lb (a.lb), ub (a.ub) { } |
1528
|
53 |
|
54 Bounds& operator = (const Bounds& a) |
|
55 { |
1869
|
56 if (this != &a) |
|
57 { |
|
58 lb = a.lower_bounds (); |
|
59 ub = a.upper_bounds (); |
|
60 } |
1528
|
61 return *this; |
|
62 } |
|
63 |
1869
|
64 ~Bounds (void) { } |
|
65 |
5275
|
66 Bounds& resize (octave_idx_type n) |
1528
|
67 { |
1869
|
68 lb.resize (n); |
|
69 ub.resize (n); |
3
|
70 |
1528
|
71 return *this; |
|
72 } |
3
|
73 |
5275
|
74 double lower_bound (octave_idx_type index) const { return lb.elem (index); } |
|
75 double upper_bound (octave_idx_type index) const { return ub.elem (index); } |
1528
|
76 |
|
77 ColumnVector lower_bounds (void) const { return lb; } |
|
78 ColumnVector upper_bounds (void) const { return ub; } |
|
79 |
5275
|
80 octave_idx_type size (void) const { return lb.capacity (); } |
3
|
81 |
5275
|
82 Bounds& set_bound (octave_idx_type index, double low, double high) |
1528
|
83 { |
|
84 lb.elem (index) = low; |
|
85 ub.elem (index) = high; |
|
86 return *this; |
|
87 } |
3
|
88 |
1528
|
89 Bounds& set_bounds (double low, double high) |
|
90 { |
|
91 lb.fill (low); |
|
92 ub.fill (high); |
|
93 return *this; |
|
94 } |
3
|
95 |
1528
|
96 Bounds& set_bounds (const ColumnVector lb, const ColumnVector ub); |
3
|
97 |
5275
|
98 Bounds& set_lower_bound (octave_idx_type index, double low) |
1528
|
99 { |
|
100 lb.elem (index) = low; |
|
101 return *this; |
|
102 } |
|
103 |
5275
|
104 Bounds& set_upper_bound (octave_idx_type index, double high) |
1528
|
105 { |
|
106 ub.elem (index) = high; |
|
107 return *this; |
|
108 } |
3
|
109 |
1528
|
110 Bounds& set_lower_bounds (double low) |
|
111 { |
|
112 lb.fill (low); |
|
113 return *this; |
|
114 } |
3
|
115 |
1528
|
116 Bounds& set_upper_bounds (double high) |
|
117 { |
|
118 ub.fill (high); |
|
119 return *this; |
|
120 } |
|
121 |
|
122 Bounds& set_lower_bounds (const ColumnVector lb); |
|
123 Bounds& set_upper_bounds (const ColumnVector ub); |
3
|
124 |
3504
|
125 friend std::ostream& operator << (std::ostream& os, const Bounds& b); |
3
|
126 |
|
127 protected: |
|
128 |
1528
|
129 ColumnVector lb; |
|
130 ColumnVector ub; |
3
|
131 |
|
132 private: |
|
133 |
|
134 void error (const char *msg); |
|
135 }; |
|
136 |
|
137 #endif |
|
138 |
|
139 /* |
|
140 ;;; Local Variables: *** |
|
141 ;;; mode: C++ *** |
|
142 ;;; End: *** |
|
143 */ |