3
|
1 /* |
|
2 |
7017
|
3 Copyright (C) 1993, 1994, 1995, 1996, 1997, 2000, 2002, 2004, 2005, |
|
4 2007 John W. Eaton |
3
|
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 |
7016
|
10 Free Software Foundation; either version 3 of the License, or (at your |
|
11 option) any later version. |
3
|
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 |
7016
|
19 along with Octave; see the file COPYING. If not, see |
|
20 <http://www.gnu.org/licenses/>. |
3
|
21 |
|
22 */ |
|
23 |
382
|
24 #if !defined (octave_Bounds_h) |
|
25 #define octave_Bounds_h 1 |
|
26 |
3503
|
27 #include <iostream> |
461
|
28 |
|
29 #include "dColVector.h" |
384
|
30 |
1869
|
31 class |
|
32 Bounds |
3
|
33 { |
|
34 public: |
|
35 |
1869
|
36 Bounds (void) |
|
37 : lb (), ub () { } |
|
38 |
5275
|
39 Bounds (octave_idx_type n) |
1869
|
40 : lb (n, 0.0), ub (n, 0.0) { } |
1528
|
41 |
1869
|
42 Bounds (const ColumnVector l, const ColumnVector u) |
|
43 : lb (l), ub (u) |
|
44 { |
|
45 if (lb.capacity () != ub.capacity ()) |
|
46 { |
|
47 error ("inconsistent sizes for lower and upper bounds"); |
|
48 return; |
|
49 } |
|
50 } |
3
|
51 |
1528
|
52 Bounds (const Bounds& a) |
1869
|
53 : lb (a.lb), ub (a.ub) { } |
1528
|
54 |
|
55 Bounds& operator = (const Bounds& a) |
|
56 { |
1869
|
57 if (this != &a) |
|
58 { |
|
59 lb = a.lower_bounds (); |
|
60 ub = a.upper_bounds (); |
|
61 } |
1528
|
62 return *this; |
|
63 } |
|
64 |
1869
|
65 ~Bounds (void) { } |
|
66 |
5275
|
67 Bounds& resize (octave_idx_type n) |
1528
|
68 { |
1869
|
69 lb.resize (n); |
|
70 ub.resize (n); |
3
|
71 |
1528
|
72 return *this; |
|
73 } |
3
|
74 |
5275
|
75 double lower_bound (octave_idx_type index) const { return lb.elem (index); } |
|
76 double upper_bound (octave_idx_type index) const { return ub.elem (index); } |
1528
|
77 |
|
78 ColumnVector lower_bounds (void) const { return lb; } |
|
79 ColumnVector upper_bounds (void) const { return ub; } |
|
80 |
5275
|
81 octave_idx_type size (void) const { return lb.capacity (); } |
3
|
82 |
5275
|
83 Bounds& set_bound (octave_idx_type index, double low, double high) |
1528
|
84 { |
|
85 lb.elem (index) = low; |
|
86 ub.elem (index) = high; |
|
87 return *this; |
|
88 } |
3
|
89 |
1528
|
90 Bounds& set_bounds (double low, double high) |
|
91 { |
|
92 lb.fill (low); |
|
93 ub.fill (high); |
|
94 return *this; |
|
95 } |
3
|
96 |
1528
|
97 Bounds& set_bounds (const ColumnVector lb, const ColumnVector ub); |
3
|
98 |
5275
|
99 Bounds& set_lower_bound (octave_idx_type index, double low) |
1528
|
100 { |
|
101 lb.elem (index) = low; |
|
102 return *this; |
|
103 } |
|
104 |
5275
|
105 Bounds& set_upper_bound (octave_idx_type index, double high) |
1528
|
106 { |
|
107 ub.elem (index) = high; |
|
108 return *this; |
|
109 } |
3
|
110 |
1528
|
111 Bounds& set_lower_bounds (double low) |
|
112 { |
|
113 lb.fill (low); |
|
114 return *this; |
|
115 } |
3
|
116 |
1528
|
117 Bounds& set_upper_bounds (double high) |
|
118 { |
|
119 ub.fill (high); |
|
120 return *this; |
|
121 } |
|
122 |
|
123 Bounds& set_lower_bounds (const ColumnVector lb); |
|
124 Bounds& set_upper_bounds (const ColumnVector ub); |
3
|
125 |
3504
|
126 friend std::ostream& operator << (std::ostream& os, const Bounds& b); |
3
|
127 |
|
128 protected: |
|
129 |
1528
|
130 ColumnVector lb; |
|
131 ColumnVector ub; |
3
|
132 |
|
133 private: |
|
134 |
|
135 void error (const char *msg); |
|
136 }; |
|
137 |
|
138 #endif |
|
139 |
|
140 /* |
|
141 ;;; Local Variables: *** |
|
142 ;;; mode: C++ *** |
|
143 ;;; End: *** |
|
144 */ |