1 /* _______________________________________________________________________
2
3 DAKOTA: Design Analysis Kit for Optimization and Terascale Applications
4 Copyright 2014-2020 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
5 This software is distributed under the GNU Lesser General Public License.
6 For more information, see the README file in the top Dakota directory.
7 _______________________________________________________________________ */
8
9 //- Class: Dakota::Constraints
10 //- Description: Container class of variables and bounds, each with fundamental
11 //- arrays (from specification) and derived arrays (for special
12 //- cases).
13 //- Owner: Mike Eldred
14 //- Version: $Id: DakotaConstraints.hpp 7024 2010-10-16 01:24:42Z mseldre $
15
16 #ifndef DAKOTA_CONSTRAINTS_H
17 #define DAKOTA_CONSTRAINTS_H
18
19 #include "dakota_data_types.hpp"
20 #include "dakota_global_defs.hpp" // for BaseConstructor
21 #include "SharedVariablesData.hpp"
22
23
24 namespace Dakota {
25
26 class ProblemDescDB;
27
28 enum class CONSTRAINT_TYPE { LINEAR, NONLINEAR };
29 enum class CONSTRAINT_EQUALITY_TYPE { EQUALITY, INEQUALITY };
30
31 /// Base class for the variable constraints class hierarchy.
32
33 /** The Constraints class is the base class for the class hierarchy
34 managing bound, linear, and nonlinear constraints. Using the
35 variable lower and upper bounds arrays from the input
36 specification, different derived classes define different views of
37 this data. The linear and nonlinear constraint data is consistent
38 in all views and is managed at the base class level. For memory
39 efficiency and enhanced polymorphism, the variable constraints
40 hierarchy employs the "letter/envelope idiom" (see Coplien
41 "Advanced C++", p. 133), for which the base class (Constraints)
42 serves as the envelope and one of the derived classes (selected in
43 Constraints::get_constraints()) serves as the letter. */
44
45 class Constraints
46 {
47 public:
48
49 //
50 //- Heading: Constructors, destructor, assignment operator
51 //
52
53 /// default constructor
54 Constraints();
55 /// standard constructor
56 Constraints(const ProblemDescDB& prob_db, const SharedVariablesData& svd);
57 // alternate constructor for minimal instantiations on the fly (reshape reqd)
58 //Constraints(const std::pair<short,short>& view);
59 /// alternate constructor for instantiations on the fly
60 Constraints(const SharedVariablesData& svd);
61 /// copy constructor
62 Constraints(const Constraints& con);
63
64 /// destructor
65 virtual ~Constraints();
66
67 /// assignment operator
68 Constraints operator=(const Constraints& con);
69
70 //
71 //- Heading: Virtual functions
72 //
73
74 /// write a variable constraints object to an std::ostream
75 virtual void write(std::ostream& s) const;
76 /// read a variable constraints object from an std::istream
77 virtual void read(std::istream& s);
78
79 //
80 //- Heading: Member functions
81 //
82
83 // ACTIVE VARIABLES
84
85 /// return the active continuous variable lower bounds
86 const RealVector& continuous_lower_bounds() const;
87 /// return an active continuous variable lower bound
88 Real continuous_lower_bound(size_t i) const;
89 /// set the active continuous variable lower bounds
90 void continuous_lower_bounds(const RealVector& cl_bnds);
91 /// set an active continuous variable lower bound
92 void continuous_lower_bound(Real cl_bnd, size_t i);
93 /// return the active continuous variable upper bounds
94 const RealVector& continuous_upper_bounds() const;
95 /// return an active continuous variable upper bound
96 Real continuous_upper_bound(size_t i) const;
97 /// set the active continuous variable upper bounds
98 void continuous_upper_bounds(const RealVector& cu_bnds);
99 /// set an active continuous variable upper bound
100 void continuous_upper_bound(Real cu_bnd, size_t i);
101
102 /// return the active discrete variable lower bounds
103 const IntVector& discrete_int_lower_bounds() const;
104 /// return an active discrete variable lower bound
105 int discrete_int_lower_bound(size_t i) const;
106 /// set the active discrete variable lower bounds
107 void discrete_int_lower_bounds(const IntVector& dil_bnds);
108 /// set an active discrete variable lower bound
109 void discrete_int_lower_bound(int dil_bnd, size_t i);
110 /// return the active discrete variable upper bounds
111 const IntVector& discrete_int_upper_bounds() const;
112 /// return an active discrete variable upper bound
113 int discrete_int_upper_bound(size_t i) const;
114 /// set the active discrete variable upper bounds
115 void discrete_int_upper_bounds(const IntVector& diu_bnds);
116 /// set an active discrete variable upper bound
117 void discrete_int_upper_bound(int diu_bnd, size_t i);
118
119 /// return the active discrete variable lower bounds
120 const RealVector& discrete_real_lower_bounds() const;
121 /// return an active discrete variable lower bound
122 Real discrete_real_lower_bound(size_t i) const;
123 /// set the active discrete variable lower bounds
124 void discrete_real_lower_bounds(const RealVector& drl_bnds);
125 /// set an active discrete variable lower bound
126 void discrete_real_lower_bound(Real drl_bnd, size_t i);
127 /// return the active discrete variable upper bounds
128 const RealVector& discrete_real_upper_bounds() const;
129 /// return an active discrete variable upper bound
130 Real discrete_real_upper_bound(size_t i) const;
131 /// set the active discrete variable upper bounds
132 void discrete_real_upper_bounds(const RealVector& dru_bnds);
133 /// set an active discrete variable upper bound
134 void discrete_real_upper_bound(Real dru_bnd, size_t i);
135
136 // INACTIVE VARIABLES
137
138 /// return the inactive continuous lower bounds
139 const RealVector& inactive_continuous_lower_bounds() const;
140 /// set the inactive continuous lower bounds
141 void inactive_continuous_lower_bounds(const RealVector& icl_bnds);
142 /// return the inactive continuous upper bounds
143 const RealVector& inactive_continuous_upper_bounds() const;
144 /// set the inactive continuous upper bounds
145 void inactive_continuous_upper_bounds(const RealVector& icu_bnds);
146
147 /// return the inactive discrete lower bounds
148 const IntVector& inactive_discrete_int_lower_bounds() const;
149 /// set the inactive discrete lower bounds
150 void inactive_discrete_int_lower_bounds(const IntVector& idil_bnds);
151 /// return the inactive discrete upper bounds
152 const IntVector& inactive_discrete_int_upper_bounds() const;
153 /// set the inactive discrete upper bounds
154 void inactive_discrete_int_upper_bounds(const IntVector& idiu_bnds);
155
156 /// return the inactive discrete lower bounds
157 const RealVector& inactive_discrete_real_lower_bounds() const;
158 /// set the inactive discrete lower bounds
159 void inactive_discrete_real_lower_bounds(const RealVector& idrl_bnds);
160 /// return the inactive discrete upper bounds
161 const RealVector& inactive_discrete_real_upper_bounds() const;
162 /// set the inactive discrete upper bounds
163 void inactive_discrete_real_upper_bounds(const RealVector& idru_bnds);
164
165 // ALL VARIABLES
166
167 /// returns a single array with all continuous lower bounds
168 const RealVector& all_continuous_lower_bounds() const;
169 /// sets all continuous lower bounds using a single array
170 void all_continuous_lower_bounds(const RealVector& acl_bnds);
171 /// set a lower bound within the all continuous lower bounds array
172 void all_continuous_lower_bound(Real acl_bnd, size_t i);
173 /// returns a single array with all continuous upper bounds
174 const RealVector& all_continuous_upper_bounds() const;
175 /// sets all continuous upper bounds using a single array
176 void all_continuous_upper_bounds(const RealVector& acu_bnds);
177 /// set an upper bound within the all continuous upper bounds array
178 void all_continuous_upper_bound(Real acu_bnd, size_t i);
179
180 /// returns a single array with all discrete lower bounds
181 const IntVector& all_discrete_int_lower_bounds() const;
182 /// sets all discrete lower bounds using a single array
183 void all_discrete_int_lower_bounds(const IntVector& adil_bnds);
184 /// set a lower bound within the all discrete lower bounds array
185 void all_discrete_int_lower_bound(int adil_bnd, size_t i);
186 /// returns a single array with all discrete upper bounds
187 const IntVector& all_discrete_int_upper_bounds() const;
188 /// sets all discrete upper bounds using a single array
189 void all_discrete_int_upper_bounds(const IntVector& adiu_bnds);
190 /// set an upper bound within the all discrete upper bounds array
191 void all_discrete_int_upper_bound(int adiu_bnd, size_t i);
192
193 /// returns a single array with all discrete lower bounds
194 const RealVector& all_discrete_real_lower_bounds() const;
195 /// sets all discrete lower bounds using a single array
196 void all_discrete_real_lower_bounds(const RealVector& adrl_bnds);
197 /// set a lower bound within the all discrete lower bounds array
198 void all_discrete_real_lower_bound(Real adrl_bnd, size_t i);
199 /// returns a single array with all discrete upper bounds
200 const RealVector& all_discrete_real_upper_bounds() const;
201 /// sets all discrete upper bounds using a single array
202 void all_discrete_real_upper_bounds(const RealVector& adru_bnds);
203 /// set an upper bound within the all discrete upper bounds array
204 void all_discrete_real_upper_bound(Real adru_bnd, size_t i);
205
206 // LINEAR CONSTRAINTS
207
208 /// return the number of linear inequality constraints
209 size_t num_linear_ineq_constraints() const;
210 /// return the number of linear equality constraints
211 size_t num_linear_eq_constraints() const;
212
213 /// return the linear inequality constraint coefficients
214 const RealMatrix& linear_ineq_constraint_coeffs() const;
215 /// set the linear inequality constraint coefficients
216 void linear_ineq_constraint_coeffs(const RealMatrix& lin_ineq_coeffs);
217 /// return the linear inequality constraint lower bounds
218 const RealVector& linear_ineq_constraint_lower_bounds() const;
219 /// set the linear inequality constraint lower bounds
220 void linear_ineq_constraint_lower_bounds(
221 const RealVector& lin_ineq_l_bnds);
222 /// return the linear inequality constraint upper bounds
223 const RealVector& linear_ineq_constraint_upper_bounds() const;
224 /// set the linear inequality constraint upper bounds
225 void linear_ineq_constraint_upper_bounds(
226 const RealVector& lin_ineq_u_bnds);
227 /// return the linear equality constraint coefficients
228 const RealMatrix& linear_eq_constraint_coeffs() const;
229 /// set the linear equality constraint coefficients
230 void linear_eq_constraint_coeffs(const RealMatrix& lin_eq_coeffs);
231 /// return the linear equality constraint targets
232 const RealVector& linear_eq_constraint_targets() const;
233 /// set the linear equality constraint targets
234 void linear_eq_constraint_targets(const RealVector& lin_eq_targets);
235
236 // NONLINEAR CONSTRAINTS
237
238 /// return the number of nonlinear inequality constraints
239 size_t num_nonlinear_ineq_constraints() const;
240 /// return the number of nonlinear equality constraints
241 size_t num_nonlinear_eq_constraints() const;
242
243 /// return the nonlinear inequality constraint lower bounds
244 const RealVector& nonlinear_ineq_constraint_lower_bounds() const;
245 /// set the nonlinear inequality constraint lower bounds
246 void nonlinear_ineq_constraint_lower_bounds(
247 const RealVector& nln_ineq_l_bnds);
248 /// return the nonlinear inequality constraint upper bounds
249 const RealVector& nonlinear_ineq_constraint_upper_bounds() const;
250 /// set the nonlinear inequality constraint upper bounds
251 void nonlinear_ineq_constraint_upper_bounds(
252 const RealVector& nln_ineq_u_bnds);
253 /// return the nonlinear equality constraint targets
254 const RealVector& nonlinear_eq_constraint_targets() const;
255 /// set the nonlinear equality constraint targets
256 void nonlinear_eq_constraint_targets(const RealVector& nln_eq_targets);
257
258 /// for use when a deep copy is needed (the representation is _not_ shared)
259 Constraints copy() const;
260
261 /// shape the lower/upper bound arrays based on sharedVarsData
262 void shape();
263 /// reshape the linear/nonlinear/bound constraint arrays arrays and
264 /// the lower/upper bound arrays
265 void reshape(size_t num_nln_ineq_cons, size_t num_nln_eq_cons,
266 size_t num_lin_ineq_cons, size_t num_lin_eq_cons,
267 const SharedVariablesData& svd);
268 /// reshape the lower/upper bound arrays based on sharedVarsData
269 void reshape();
270 /// reshape the linear/nonlinear constraint arrays
271 void reshape(size_t num_nln_ineq_cons, size_t num_nln_eq_cons,
272 size_t num_lin_ineq_cons, size_t num_lin_eq_cons);
273
274 /// sets the inactive view based on higher level (nested) context
275 void inactive_view(short view2);
276
277 /// function to check constraintsRep (does this envelope contain a letter)
278 bool is_null() const;
279
280 protected:
281
282 //
283 //- Heading: Constructors
284 //
285
286 /// constructor initializes the base class part of letter classes
287 /// (BaseConstructor overloading avoids infinite recursion in the
288 /// derived class constructors - Coplien, p. 139)
289 Constraints(BaseConstructor, const ProblemDescDB& problem_db,
290 const SharedVariablesData& svd);
291 /// constructor initializes the base class part of letter classes
292 /// (BaseConstructor overloading avoids infinite recursion in the
293 /// derived class constructors - Coplien, p. 139)
294 Constraints(BaseConstructor, const SharedVariablesData& svd);
295
296 //
297 //- Heading: Member functions
298 //
299
300 /// construct active/inactive views of all variables arrays
301 void build_views();
302 /// construct active views of all variables bounds arrays
303 void build_active_views();
304 /// construct inactive views of all variables bounds arrays
305 void build_inactive_views();
306
307 /// perform checks on user input, convert linear constraint
308 /// coefficient input to matrices, and assign defaults
309 void manage_linear_constraints(const ProblemDescDB& problem_db);
310
311 //
312 //- Heading: Data
313 //
314
315 /// configuration data shared from a Variables instance
316 SharedVariablesData sharedVarsData;
317
318 /// a continuous lower bounds array combining continuous design,
319 /// uncertain, and continuous state variable types (all view).
320 RealVector allContinuousLowerBnds;
321 /// a continuous upper bounds array combining continuous design,
322 /// uncertain, and continuous state variable types (all view).
323 RealVector allContinuousUpperBnds;
324 /// a discrete lower bounds array combining discrete design and
325 /// discrete state variable types (all view).
326 IntVector allDiscreteIntLowerBnds;
327 /// a discrete upper bounds array combining discrete design and
328 /// discrete state variable types (all view).
329 IntVector allDiscreteIntUpperBnds;
330 /// a discrete lower bounds array combining discrete design and
331 /// discrete state variable types (all view).
332 RealVector allDiscreteRealLowerBnds;
333 /// a discrete upper bounds array combining discrete design and
334 /// discrete state variable types (all view).
335 RealVector allDiscreteRealUpperBnds;
336
337 /// number of nonlinear inequality constraints
338 size_t numNonlinearIneqCons;
339 /// number of nonlinear equality constraints
340 size_t numNonlinearEqCons;
341 /// nonlinear inequality constraint lower bounds
342 RealVector nonlinearIneqConLowerBnds;
343 /// nonlinear inequality constraint upper bounds
344 RealVector nonlinearIneqConUpperBnds;
345 /// nonlinear equality constraint targets
346 RealVector nonlinearEqConTargets;
347
348 /// number of linear inequality constraints
349 size_t numLinearIneqCons;
350 /// number of linear equality constraints
351 size_t numLinearEqCons;
352 /// linear inequality constraint coefficients
353 RealMatrix linearIneqConCoeffs;
354 /// linear equality constraint coefficients
355 RealMatrix linearEqConCoeffs;
356 /// linear inequality constraint lower bounds
357 RealVector linearIneqConLowerBnds;
358 /// linear inequality constraint upper bounds
359 RealVector linearIneqConUpperBnds;
360 /// linear equality constraint targets
361 RealVector linearEqConTargets;
362
363 //
364 //- Heading: Data views
365 //
366
367 /// the active continuous lower bounds array view
368 RealVector continuousLowerBnds;
369 /// the active continuous upper bounds array view
370 RealVector continuousUpperBnds;
371 /// the active discrete lower bounds array view
372 IntVector discreteIntLowerBnds;
373 /// the active discrete upper bounds array view
374 IntVector discreteIntUpperBnds;
375 /// the active discrete lower bounds array view
376 RealVector discreteRealLowerBnds;
377 /// the active discrete upper bounds array view
378 RealVector discreteRealUpperBnds;
379
380 /// the inactive continuous lower bounds array view
381 RealVector inactiveContinuousLowerBnds;
382 /// the inactive continuous upper bounds array view
383 RealVector inactiveContinuousUpperBnds;
384 /// the inactive discrete lower bounds array view
385 IntVector inactiveDiscreteIntLowerBnds;
386 /// the inactive discrete upper bounds array view
387 IntVector inactiveDiscreteIntUpperBnds;
388 /// the inactive discrete lower bounds array view
389 RealVector inactiveDiscreteRealLowerBnds;
390 /// the inactive discrete upper bounds array view
391 RealVector inactiveDiscreteRealUpperBnds;
392
393 private:
394
395 //
396 //- Heading: Member functions
397 //
398
399 /// Used only by the constructor to initialize constraintsRep to the
400 /// appropriate derived type.
401 std::shared_ptr<Constraints>
402 get_constraints(const ProblemDescDB& problem_db,
403 const SharedVariablesData& svd);
404 /// Used by copy() to initialize constraintsRep to the appropriate
405 /// derived type.
406 std::shared_ptr<Constraints>
407 get_constraints(const SharedVariablesData& svd) const;
408
409 //
410 //- Heading: Data
411 //
412
413 /// pointer to the letter (initialized only for the envelope)
414 std::shared_ptr<Constraints> constraintsRep;
415 };
416
417
continuous_lower_bounds() const418 inline const RealVector& Constraints::continuous_lower_bounds() const
419 {
420 return (constraintsRep) ?
421 constraintsRep->continuousLowerBnds : continuousLowerBnds;
422 }
423
424
continuous_lower_bound(size_t i) const425 inline Real Constraints::continuous_lower_bound(size_t i) const
426 {
427 return (constraintsRep) ?
428 constraintsRep->continuousLowerBnds[i] : continuousLowerBnds[i];
429 }
430
431
continuous_lower_bounds(const RealVector & cl_bnds)432 inline void Constraints::continuous_lower_bounds(const RealVector& cl_bnds)
433 {
434 if (constraintsRep) constraintsRep->continuousLowerBnds.assign(cl_bnds);
435 else continuousLowerBnds.assign(cl_bnds);
436 }
437
438
continuous_lower_bound(Real cl_bnd,size_t i)439 inline void Constraints::continuous_lower_bound(Real cl_bnd, size_t i)
440 {
441 if (constraintsRep) constraintsRep->continuousLowerBnds[i] = cl_bnd;
442 else continuousLowerBnds[i] = cl_bnd;
443 }
444
445
continuous_upper_bounds() const446 inline const RealVector& Constraints::continuous_upper_bounds() const
447 {
448 return (constraintsRep) ?
449 constraintsRep->continuousUpperBnds : continuousUpperBnds;
450 }
451
452
continuous_upper_bound(size_t i) const453 inline Real Constraints::continuous_upper_bound(size_t i) const
454 {
455 return (constraintsRep) ?
456 constraintsRep->continuousUpperBnds[i] : continuousUpperBnds[i];
457 }
458
459
continuous_upper_bounds(const RealVector & cu_bnds)460 inline void Constraints::continuous_upper_bounds(const RealVector& cu_bnds)
461 {
462 if (constraintsRep) constraintsRep->continuousUpperBnds.assign(cu_bnds);
463 else continuousUpperBnds.assign(cu_bnds);
464 }
465
466
continuous_upper_bound(Real cu_bnd,size_t i)467 inline void Constraints::continuous_upper_bound(Real cu_bnd, size_t i)
468 {
469 if (constraintsRep) constraintsRep->continuousUpperBnds[i] = cu_bnd;
470 else continuousUpperBnds[i] = cu_bnd;
471 }
472
473
discrete_int_lower_bounds() const474 inline const IntVector& Constraints::discrete_int_lower_bounds() const
475 {
476 return (constraintsRep) ?
477 constraintsRep->discreteIntLowerBnds : discreteIntLowerBnds;
478 }
479
480
discrete_int_lower_bound(size_t i) const481 inline int Constraints::discrete_int_lower_bound(size_t i) const
482 {
483 return (constraintsRep) ?
484 constraintsRep->discreteIntLowerBnds[i] : discreteIntLowerBnds[i];
485 }
486
487
discrete_int_lower_bounds(const IntVector & dil_bnds)488 inline void Constraints::discrete_int_lower_bounds(const IntVector& dil_bnds)
489 {
490 if (constraintsRep) constraintsRep->discreteIntLowerBnds.assign(dil_bnds);
491 else discreteIntLowerBnds.assign(dil_bnds);
492 }
493
494
discrete_int_lower_bound(int dil_bnd,size_t i)495 inline void Constraints::discrete_int_lower_bound(int dil_bnd, size_t i)
496 {
497 if (constraintsRep) constraintsRep->discreteIntLowerBnds[i] = dil_bnd;
498 else discreteIntLowerBnds[i] = dil_bnd;
499 }
500
501
discrete_int_upper_bounds() const502 inline const IntVector& Constraints::discrete_int_upper_bounds() const
503 {
504 return (constraintsRep) ?
505 constraintsRep->discreteIntUpperBnds : discreteIntUpperBnds;
506 }
507
508
discrete_int_upper_bound(size_t i) const509 inline int Constraints::discrete_int_upper_bound(size_t i) const
510 {
511 return (constraintsRep) ?
512 constraintsRep->discreteIntUpperBnds[i] : discreteIntUpperBnds[i];
513 }
514
515
discrete_int_upper_bounds(const IntVector & diu_bnds)516 inline void Constraints::discrete_int_upper_bounds(const IntVector& diu_bnds)
517 {
518 if (constraintsRep) constraintsRep->discreteIntUpperBnds.assign(diu_bnds);
519 else discreteIntUpperBnds.assign(diu_bnds);
520 }
521
522
discrete_int_upper_bound(int diu_bnd,size_t i)523 inline void Constraints::discrete_int_upper_bound(int diu_bnd, size_t i)
524 {
525 if (constraintsRep) constraintsRep->discreteIntUpperBnds[i] = diu_bnd;
526 else discreteIntUpperBnds[i] = diu_bnd;
527 }
528
529
discrete_real_lower_bounds() const530 inline const RealVector& Constraints::discrete_real_lower_bounds() const
531 {
532 return (constraintsRep) ?
533 constraintsRep->discreteRealLowerBnds : discreteRealLowerBnds;
534 }
535
536
discrete_real_lower_bound(size_t i) const537 inline Real Constraints::discrete_real_lower_bound(size_t i) const
538 {
539 return (constraintsRep) ?
540 constraintsRep->discreteRealLowerBnds[i] : discreteRealLowerBnds[i];
541 }
542
543
discrete_real_lower_bounds(const RealVector & drl_bnds)544 inline void Constraints::discrete_real_lower_bounds(const RealVector& drl_bnds)
545 {
546 if (constraintsRep) constraintsRep->discreteRealLowerBnds.assign(drl_bnds);
547 else discreteRealLowerBnds.assign(drl_bnds);
548 }
549
550
discrete_real_lower_bound(Real drl_bnd,size_t i)551 inline void Constraints::discrete_real_lower_bound(Real drl_bnd, size_t i)
552 {
553 if (constraintsRep) constraintsRep->discreteRealLowerBnds[i] = drl_bnd;
554 else discreteRealLowerBnds[i] = drl_bnd;
555 }
556
557
discrete_real_upper_bounds() const558 inline const RealVector& Constraints::discrete_real_upper_bounds() const
559 {
560 return (constraintsRep) ?
561 constraintsRep->discreteRealUpperBnds : discreteRealUpperBnds;
562 }
563
564
discrete_real_upper_bound(size_t i) const565 inline Real Constraints::discrete_real_upper_bound(size_t i) const
566 {
567 return (constraintsRep) ?
568 constraintsRep->discreteRealUpperBnds[i] : discreteRealUpperBnds[i];
569 }
570
571
discrete_real_upper_bounds(const RealVector & dru_bnds)572 inline void Constraints::discrete_real_upper_bounds(const RealVector& dru_bnds)
573 {
574 if (constraintsRep) constraintsRep->discreteRealUpperBnds.assign(dru_bnds);
575 else discreteRealUpperBnds.assign(dru_bnds);
576 }
577
578
discrete_real_upper_bound(Real dru_bnd,size_t i)579 inline void Constraints::discrete_real_upper_bound(Real dru_bnd, size_t i)
580 {
581 if (constraintsRep) constraintsRep->discreteRealUpperBnds[i] = dru_bnd;
582 else discreteRealUpperBnds[i] = dru_bnd;
583 }
584
585
inactive_continuous_lower_bounds() const586 inline const RealVector& Constraints::inactive_continuous_lower_bounds() const
587 {
588 return (constraintsRep) ?
589 constraintsRep->inactiveContinuousLowerBnds : inactiveContinuousLowerBnds;
590 }
591
592
593 inline void Constraints::
inactive_continuous_lower_bounds(const RealVector & icl_bnds)594 inactive_continuous_lower_bounds(const RealVector& icl_bnds)
595 {
596 if (constraintsRep)
597 constraintsRep->inactiveContinuousLowerBnds.assign(icl_bnds);
598 else
599 inactiveContinuousLowerBnds.assign(icl_bnds);
600 }
601
602
inactive_continuous_upper_bounds() const603 inline const RealVector& Constraints::inactive_continuous_upper_bounds() const
604 {
605 return (constraintsRep) ?
606 constraintsRep->inactiveContinuousUpperBnds : inactiveContinuousUpperBnds;
607 }
608
609
610 inline void Constraints::
inactive_continuous_upper_bounds(const RealVector & icu_bnds)611 inactive_continuous_upper_bounds(const RealVector& icu_bnds)
612 {
613 if (constraintsRep)
614 constraintsRep->inactiveContinuousUpperBnds.assign(icu_bnds);
615 else
616 inactiveContinuousUpperBnds.assign(icu_bnds);
617 }
618
619
inactive_discrete_int_lower_bounds() const620 inline const IntVector& Constraints::inactive_discrete_int_lower_bounds() const
621 {
622 return (constraintsRep) ?
623 constraintsRep->inactiveDiscreteIntLowerBnds : inactiveDiscreteIntLowerBnds;
624 }
625
626
627 inline void Constraints::
inactive_discrete_int_lower_bounds(const IntVector & idil_bnds)628 inactive_discrete_int_lower_bounds(const IntVector& idil_bnds)
629 {
630 if (constraintsRep)
631 constraintsRep->inactiveDiscreteIntLowerBnds.assign(idil_bnds);
632 else
633 inactiveDiscreteIntLowerBnds.assign(idil_bnds);
634 }
635
636
inactive_discrete_int_upper_bounds() const637 inline const IntVector& Constraints::inactive_discrete_int_upper_bounds() const
638 {
639 return(constraintsRep) ?
640 constraintsRep->inactiveDiscreteIntUpperBnds : inactiveDiscreteIntUpperBnds;
641 }
642
643
644 inline void Constraints::
inactive_discrete_int_upper_bounds(const IntVector & idiu_bnds)645 inactive_discrete_int_upper_bounds(const IntVector& idiu_bnds)
646 {
647 if (constraintsRep)
648 constraintsRep->inactiveDiscreteIntUpperBnds.assign(idiu_bnds);
649 else
650 inactiveDiscreteIntUpperBnds.assign(idiu_bnds);
651 }
652
653
654 inline const RealVector& Constraints::
inactive_discrete_real_lower_bounds() const655 inactive_discrete_real_lower_bounds() const
656 {
657 return (constraintsRep) ? constraintsRep->inactiveDiscreteRealLowerBnds :
658 inactiveDiscreteRealLowerBnds;
659 }
660
661
662 inline void Constraints::
inactive_discrete_real_lower_bounds(const RealVector & idrl_bnds)663 inactive_discrete_real_lower_bounds(const RealVector& idrl_bnds)
664 {
665 if (constraintsRep)
666 constraintsRep->inactiveDiscreteRealLowerBnds.assign(idrl_bnds);
667 else
668 inactiveDiscreteRealLowerBnds.assign(idrl_bnds);
669 }
670
671
672 inline const RealVector& Constraints::
inactive_discrete_real_upper_bounds() const673 inactive_discrete_real_upper_bounds() const
674 {
675 return(constraintsRep) ? constraintsRep-> inactiveDiscreteRealUpperBnds :
676 inactiveDiscreteRealUpperBnds;
677 }
678
679
680 inline void Constraints::
inactive_discrete_real_upper_bounds(const RealVector & idru_bnds)681 inactive_discrete_real_upper_bounds(const RealVector& idru_bnds)
682 {
683 if (constraintsRep)
684 constraintsRep->inactiveDiscreteRealUpperBnds.assign(idru_bnds);
685 else
686 inactiveDiscreteRealUpperBnds.assign(idru_bnds);
687 }
688
689
all_continuous_lower_bounds() const690 inline const RealVector& Constraints::all_continuous_lower_bounds() const
691 {
692 return (constraintsRep) ?
693 constraintsRep->allContinuousLowerBnds : allContinuousLowerBnds;
694 }
695
696
697 inline void Constraints::
all_continuous_lower_bounds(const RealVector & acl_bnds)698 all_continuous_lower_bounds(const RealVector& acl_bnds)
699 {
700 if (constraintsRep) constraintsRep->allContinuousLowerBnds.assign(acl_bnds);
701 else allContinuousLowerBnds.assign(acl_bnds);
702 }
703
704
all_continuous_lower_bound(Real acl_bnd,size_t i)705 inline void Constraints::all_continuous_lower_bound(Real acl_bnd, size_t i)
706 {
707 if (constraintsRep) constraintsRep->allContinuousLowerBnds[i] = acl_bnd;
708 else allContinuousLowerBnds[i] = acl_bnd;
709 }
710
711
all_continuous_upper_bounds() const712 inline const RealVector& Constraints::all_continuous_upper_bounds() const
713 {
714 return (constraintsRep) ?
715 constraintsRep->allContinuousUpperBnds : allContinuousUpperBnds;
716 }
717
718
all_continuous_upper_bounds(const RealVector & acu_bnds)719 inline void Constraints::all_continuous_upper_bounds(const RealVector& acu_bnds)
720 {
721 if (constraintsRep) constraintsRep->allContinuousUpperBnds.assign(acu_bnds);
722 else allContinuousUpperBnds.assign(acu_bnds);
723 }
724
725
all_continuous_upper_bound(Real acu_bnd,size_t i)726 inline void Constraints::all_continuous_upper_bound(Real acu_bnd, size_t i)
727 {
728 if (constraintsRep) constraintsRep->allContinuousUpperBnds[i] = acu_bnd;
729 else allContinuousUpperBnds[i] = acu_bnd;
730 }
731
732
all_discrete_int_lower_bounds() const733 inline const IntVector& Constraints::all_discrete_int_lower_bounds() const
734 {
735 return (constraintsRep) ?
736 constraintsRep->allDiscreteIntLowerBnds : allDiscreteIntLowerBnds;
737 }
738
739
740 inline void Constraints::
all_discrete_int_lower_bounds(const IntVector & adil_bnds)741 all_discrete_int_lower_bounds(const IntVector& adil_bnds)
742 {
743 if (constraintsRep) constraintsRep->allDiscreteIntLowerBnds.assign(adil_bnds);
744 else allDiscreteIntLowerBnds.assign(adil_bnds);
745 }
746
747
all_discrete_int_lower_bound(int adil_bnd,size_t i)748 inline void Constraints::all_discrete_int_lower_bound(int adil_bnd, size_t i)
749 {
750 if (constraintsRep) constraintsRep->allDiscreteIntLowerBnds[i] = adil_bnd;
751 else allDiscreteIntLowerBnds[i] = adil_bnd;
752 }
753
754
all_discrete_int_upper_bounds() const755 inline const IntVector& Constraints::all_discrete_int_upper_bounds() const
756 {
757 return (constraintsRep) ?
758 constraintsRep->allDiscreteIntUpperBnds : allDiscreteIntUpperBnds;
759 }
760
761
762 inline void Constraints::
all_discrete_int_upper_bounds(const IntVector & adiu_bnds)763 all_discrete_int_upper_bounds(const IntVector& adiu_bnds)
764 {
765 if (constraintsRep)
766 constraintsRep->allDiscreteIntUpperBnds.assign(adiu_bnds);
767 else
768 allDiscreteIntUpperBnds.assign(adiu_bnds);
769 }
770
771
all_discrete_int_upper_bound(int adiu_bnd,size_t i)772 inline void Constraints::all_discrete_int_upper_bound(int adiu_bnd, size_t i)
773 {
774 if (constraintsRep) constraintsRep->allDiscreteIntUpperBnds[i] = adiu_bnd;
775 else allDiscreteIntUpperBnds[i] = adiu_bnd;
776 }
777
778
all_discrete_real_lower_bounds() const779 inline const RealVector& Constraints::all_discrete_real_lower_bounds() const
780 {
781 return (constraintsRep) ?
782 constraintsRep->allDiscreteRealLowerBnds : allDiscreteRealLowerBnds;
783 }
784
785
786 inline void Constraints::
all_discrete_real_lower_bounds(const RealVector & adrl_bnds)787 all_discrete_real_lower_bounds(const RealVector& adrl_bnds)
788 {
789 if (constraintsRep)
790 constraintsRep->allDiscreteRealLowerBnds.assign(adrl_bnds);
791 else
792 allDiscreteRealLowerBnds.assign(adrl_bnds);
793 }
794
795
all_discrete_real_lower_bound(Real adrl_bnd,size_t i)796 inline void Constraints::all_discrete_real_lower_bound(Real adrl_bnd, size_t i)
797 {
798 if (constraintsRep) constraintsRep->allDiscreteRealLowerBnds[i] = adrl_bnd;
799 else allDiscreteRealLowerBnds[i] = adrl_bnd;
800 }
801
802
all_discrete_real_upper_bounds() const803 inline const RealVector& Constraints::all_discrete_real_upper_bounds() const
804 {
805 return (constraintsRep) ?
806 constraintsRep->allDiscreteRealUpperBnds : allDiscreteRealUpperBnds;
807 }
808
809
810 inline void Constraints::
all_discrete_real_upper_bounds(const RealVector & adru_bnds)811 all_discrete_real_upper_bounds(const RealVector& adru_bnds)
812 {
813 if (constraintsRep)
814 constraintsRep->allDiscreteRealUpperBnds.assign(adru_bnds);
815 else
816 allDiscreteRealUpperBnds.assign(adru_bnds);
817 }
818
819
all_discrete_real_upper_bound(Real adru_bnd,size_t i)820 inline void Constraints::all_discrete_real_upper_bound(Real adru_bnd, size_t i)
821 {
822 if (constraintsRep) constraintsRep->allDiscreteRealUpperBnds[i] = adru_bnd;
823 else allDiscreteRealUpperBnds[i] = adru_bnd;
824 }
825
826
827 // nonvirtual functions can access letter attributes directly (only need to fwd
828 // member function call when the function could be redefined).
num_linear_ineq_constraints() const829 inline size_t Constraints::num_linear_ineq_constraints() const
830 {
831 return (constraintsRep) ?
832 constraintsRep->numLinearIneqCons : numLinearIneqCons;
833 }
834
835
num_linear_eq_constraints() const836 inline size_t Constraints::num_linear_eq_constraints() const
837 { return (constraintsRep) ? constraintsRep->numLinearEqCons : numLinearEqCons; }
838
839
linear_ineq_constraint_coeffs() const840 inline const RealMatrix& Constraints::linear_ineq_constraint_coeffs() const
841 {
842 return (constraintsRep) ?
843 constraintsRep->linearIneqConCoeffs : linearIneqConCoeffs;
844 }
845
846
847 inline void Constraints::
linear_ineq_constraint_coeffs(const RealMatrix & lin_ineq_coeffs)848 linear_ineq_constraint_coeffs(const RealMatrix& lin_ineq_coeffs)
849 {
850 if (constraintsRep) constraintsRep->linearIneqConCoeffs = lin_ineq_coeffs;
851 else linearIneqConCoeffs = lin_ineq_coeffs;
852 }
853
854
855 inline const RealVector& Constraints::
linear_ineq_constraint_lower_bounds() const856 linear_ineq_constraint_lower_bounds() const
857 {
858 return (constraintsRep) ?
859 constraintsRep->linearIneqConLowerBnds : linearIneqConLowerBnds;
860 }
861
862
863 inline void Constraints::
linear_ineq_constraint_lower_bounds(const RealVector & lin_ineq_l_bnds)864 linear_ineq_constraint_lower_bounds(const RealVector& lin_ineq_l_bnds)
865 {
866 if (constraintsRep) constraintsRep->linearIneqConLowerBnds = lin_ineq_l_bnds;
867 else linearIneqConLowerBnds = lin_ineq_l_bnds;
868 }
869
870
871 inline const RealVector& Constraints::
linear_ineq_constraint_upper_bounds() const872 linear_ineq_constraint_upper_bounds() const
873 {
874 return (constraintsRep) ?
875 constraintsRep->linearIneqConUpperBnds : linearIneqConUpperBnds;
876 }
877
878
879 inline void Constraints::
linear_ineq_constraint_upper_bounds(const RealVector & lin_ineq_u_bnds)880 linear_ineq_constraint_upper_bounds(const RealVector& lin_ineq_u_bnds)
881 {
882 if (constraintsRep) constraintsRep->linearIneqConUpperBnds = lin_ineq_u_bnds;
883 else linearIneqConUpperBnds = lin_ineq_u_bnds;
884 }
885
886
linear_eq_constraint_coeffs() const887 inline const RealMatrix& Constraints::linear_eq_constraint_coeffs() const
888 {
889 return (constraintsRep) ?
890 constraintsRep->linearEqConCoeffs : linearEqConCoeffs;
891 }
892
893
894 inline void Constraints::
linear_eq_constraint_coeffs(const RealMatrix & lin_eq_coeffs)895 linear_eq_constraint_coeffs(const RealMatrix& lin_eq_coeffs)
896 {
897 if (constraintsRep) constraintsRep->linearEqConCoeffs = lin_eq_coeffs;
898 else linearEqConCoeffs = lin_eq_coeffs;
899 }
900
901
linear_eq_constraint_targets() const902 inline const RealVector& Constraints::linear_eq_constraint_targets() const
903 {
904 return (constraintsRep) ?
905 constraintsRep->linearEqConTargets : linearEqConTargets;
906 }
907
908
909 inline void Constraints::
linear_eq_constraint_targets(const RealVector & lin_eq_targets)910 linear_eq_constraint_targets(const RealVector& lin_eq_targets)
911 {
912 if (constraintsRep) constraintsRep->linearEqConTargets = lin_eq_targets;
913 else linearEqConTargets = lin_eq_targets;
914 }
915
916
num_nonlinear_ineq_constraints() const917 inline size_t Constraints::num_nonlinear_ineq_constraints() const
918 {
919 return (constraintsRep) ?
920 constraintsRep->numNonlinearIneqCons : numNonlinearIneqCons;
921 }
922
923
num_nonlinear_eq_constraints() const924 inline size_t Constraints::num_nonlinear_eq_constraints() const
925 {
926 return (constraintsRep) ?
927 constraintsRep->numNonlinearEqCons : numNonlinearEqCons;
928 }
929
930
931 inline const RealVector& Constraints::
nonlinear_ineq_constraint_lower_bounds() const932 nonlinear_ineq_constraint_lower_bounds() const
933 {
934 return (constraintsRep) ?
935 constraintsRep->nonlinearIneqConLowerBnds : nonlinearIneqConLowerBnds;
936 }
937
938
939 inline void Constraints::
nonlinear_ineq_constraint_lower_bounds(const RealVector & nln_ineq_l_bnds)940 nonlinear_ineq_constraint_lower_bounds(const RealVector& nln_ineq_l_bnds)
941 {
942 if (constraintsRep)
943 constraintsRep->nonlinearIneqConLowerBnds = nln_ineq_l_bnds;
944 else
945 nonlinearIneqConLowerBnds = nln_ineq_l_bnds;
946 }
947
948
949 inline const RealVector& Constraints::
nonlinear_ineq_constraint_upper_bounds() const950 nonlinear_ineq_constraint_upper_bounds() const
951 {
952 return (constraintsRep) ?
953 constraintsRep->nonlinearIneqConUpperBnds : nonlinearIneqConUpperBnds;
954 }
955
956
957 inline void Constraints::
nonlinear_ineq_constraint_upper_bounds(const RealVector & nln_ineq_u_bnds)958 nonlinear_ineq_constraint_upper_bounds(const RealVector& nln_ineq_u_bnds)
959 {
960 if (constraintsRep)
961 constraintsRep->nonlinearIneqConUpperBnds = nln_ineq_u_bnds;
962 else
963 nonlinearIneqConUpperBnds = nln_ineq_u_bnds;
964 }
965
966
967 inline const RealVector& Constraints::
nonlinear_eq_constraint_targets() const968 nonlinear_eq_constraint_targets() const
969 {
970 return (constraintsRep) ?
971 constraintsRep->nonlinearEqConTargets : nonlinearEqConTargets;
972 }
973
974
975 inline void Constraints::
nonlinear_eq_constraint_targets(const RealVector & nln_eq_targets)976 nonlinear_eq_constraint_targets(const RealVector& nln_eq_targets)
977 {
978 if (constraintsRep) constraintsRep->nonlinearEqConTargets = nln_eq_targets;
979 else nonlinearEqConTargets = nln_eq_targets;
980 }
981
982
is_null() const983 inline bool Constraints::is_null() const
984 { return (constraintsRep) ? false : true; }
985
986
build_views()987 inline void Constraints::build_views()
988 {
989 // called only from letters
990 const std::pair<short,short>& view = sharedVarsData.view();
991 if (view.first != EMPTY_VIEW)
992 build_active_views();
993 if (view.second != EMPTY_VIEW)
994 build_inactive_views();
995 }
996
997
998 // Having overloaded operators call read/write means that the operators need
999 // not be a friend to private data because read/write functions are public.
1000
1001 /// std::istream extraction operator for Constraints
operator >>(std::istream & s,Constraints & con)1002 inline std::istream& operator>>(std::istream& s, Constraints& con)
1003 { con.read(s); return s; }
1004
1005
1006 /// std::ostream insertion operator for Constraints
operator <<(std::ostream & s,const Constraints & con)1007 inline std::ostream& operator<<(std::ostream& s, const Constraints& con)
1008 { con.write(s); return s; }
1009
1010 } // namespace Dakota
1011
1012 #endif
1013