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:        SharedVariablesData
10 //- Description:  Class implementation
11 //- Owner:        Mike Eldred
12 
13 #include "SharedVariablesData.hpp"
14 #include "ProblemDescDB.hpp"
15 #include "dakota_data_util.hpp"
16 #include "dakota_data_io.hpp" // to serialize BitArray and StringMultiArray
17 #include <boost/archive/binary_oarchive.hpp>
18 #include <boost/archive/binary_iarchive.hpp>
19 #include <boost/serialization/export.hpp>
20 #include <boost/serialization/utility.hpp>  // for std::pair
21 #include <boost/serialization/vector.hpp>
22 #include <boost/serialization/shared_ptr.hpp>
23 
24 static const char rcsId[]="@(#) $Id: SharedVariablesData.cpp 6886 2010-08-02 19:13:01Z mseldre $";
25 
26 BOOST_CLASS_EXPORT(Dakota::SharedVariablesDataRep)
27 BOOST_CLASS_EXPORT(Dakota::SharedVariablesData)
28 
29 namespace Dakota {
30 
31 
32 /** This constructor is the one which must build the base class data for all
33     derived classes.  get_variables() instantiates a derived class letter
34     and the derived constructor selects this base class constructor in its
35     initialization list (to avoid the recursion of the base class constructor
36     calling get_variables() again).  Since the letter IS the representation,
37     its representation pointer is set to NULL (an uninitialized pointer causes
38     problems in ~Variables). */
39 SharedVariablesDataRep::
SharedVariablesDataRep(const ProblemDescDB & problem_db,const std::pair<short,short> & view)40 SharedVariablesDataRep(const ProblemDescDB& problem_db,
41 		       const std::pair<short,short>& view):
42   variablesId(problem_db.get_string("variables.id")),
43   variablesCompsTotals(NUM_VC_TOTALS, 0), variablesView(view), cvStart(0),
44   divStart(0), dsvStart(0), drvStart(0), icvStart(0), idivStart(0),
45   idsvStart(0), idrvStart(0), numCV(0), numDIV(0), numDSV(0), numDRV(0),
46   numICV(0), numIDIV(0), numIDSV(0), numIDRV(0)
47 {
48   initialize_components_totals(problem_db);
49   relax_noncategorical(problem_db); // defines allRelaxedDiscrete{Int,Real}
50 
51   initialize_all_labels(problem_db);
52   initialize_all_types();
53   initialize_all_ids();
54 }
55 
56 
57 SharedVariablesDataRep::
SharedVariablesDataRep(const std::pair<short,short> & view,const SizetArray & vars_comps_totals,const BitArray & all_relax_di,const BitArray & all_relax_dr)58 SharedVariablesDataRep(const std::pair<short,short>& view,
59 		       const SizetArray& vars_comps_totals,
60 		       const BitArray& all_relax_di,
61 		       const BitArray& all_relax_dr):
62   variablesCompsTotals(vars_comps_totals), variablesView(view), cvStart(0),
63   divStart(0), dsvStart(0), drvStart(0), icvStart(0), idivStart(0),
64   idsvStart(0), idrvStart(0), numCV(0), numDIV(0), numDSV(0), numDRV(0),
65   numICV(0), numIDIV(0), numIDSV(0), numIDRV(0),
66   allRelaxedDiscreteInt(all_relax_di), allRelaxedDiscreteReal(all_relax_dr)
67 {
68   size_all_labels();    // lacking DB, can only size labels
69   size_all_types();     // lacking detailed vars_comps, can only size types
70   initialize_all_ids(); // vars_comps_totals sufficient for forming ids
71 }
72 
73 
74 SharedVariablesDataRep::
SharedVariablesDataRep(const std::pair<short,short> & view,const std::map<unsigned short,size_t> & vars_comps,const BitArray & all_relax_di,const BitArray & all_relax_dr)75 SharedVariablesDataRep(const std::pair<short,short>& view,
76 		       const std::map<unsigned short, size_t>& vars_comps,
77 		       const BitArray& all_relax_di,
78 		       const BitArray& all_relax_dr):
79   variablesComponents(vars_comps), variablesView(view), cvStart(0),
80   divStart(0), dsvStart(0), drvStart(0), icvStart(0), idivStart(0),
81   idsvStart(0), idrvStart(0), numCV(0), numDIV(0), numDSV(0), numDRV(0),
82   numICV(0), numIDIV(0), numIDSV(0), numIDRV(0),
83   allRelaxedDiscreteInt(all_relax_di), allRelaxedDiscreteReal(all_relax_dr)
84 {
85   components_to_totals();
86 
87   size_all_labels();      // lacking DB, can only size labels
88   initialize_all_types(); // vars_comps required for defining types
89   initialize_all_ids();   // vars_comps_totals sufficient for defining ids
90 }
91 
92 
93 void SharedVariablesDataRep::
initialize_components_totals(const ProblemDescDB & problem_db)94 initialize_components_totals(const ProblemDescDB& problem_db)
95 {
96   size_t count;
97   // continuous design
98   if (count = problem_db.get_sizet("variables.continuous_design")) {
99     variablesComponents[CONTINUOUS_DESIGN] = count;
100     variablesCompsTotals[TOTAL_CDV] += count;
101   }
102   // discrete integer design
103   if (count = problem_db.get_sizet("variables.discrete_design_range")) {
104     variablesComponents[DISCRETE_DESIGN_RANGE] = count;
105     variablesCompsTotals[TOTAL_DDIV] += count;
106   }
107   if (count = problem_db.get_sizet("variables.discrete_design_set_int")) {
108     variablesComponents[DISCRETE_DESIGN_SET_INT] = count;
109     variablesCompsTotals[TOTAL_DDIV] += count;
110   }
111   // discrete string design
112   if (count = problem_db.get_sizet("variables.discrete_design_set_string")){
113     variablesComponents[DISCRETE_DESIGN_SET_STRING] = count;
114     variablesCompsTotals[TOTAL_DDSV] += count;
115   }
116   // discrete real design
117   if (count = problem_db.get_sizet("variables.discrete_design_set_real")) {
118     variablesComponents[DISCRETE_DESIGN_SET_REAL] = count;
119     variablesCompsTotals[TOTAL_DDRV] += count;
120   }
121   // continuous aleatory uncertain
122   if (count = problem_db.get_sizet("variables.normal_uncertain")) {
123     variablesComponents[NORMAL_UNCERTAIN] = count;
124     variablesCompsTotals[TOTAL_CAUV] += count;
125   }
126   if (count = problem_db.get_sizet("variables.lognormal_uncertain")) {
127     variablesComponents[LOGNORMAL_UNCERTAIN] = count;
128     variablesCompsTotals[TOTAL_CAUV] += count;
129   }
130   if (count = problem_db.get_sizet("variables.uniform_uncertain")) {
131     variablesComponents[UNIFORM_UNCERTAIN] = count;
132     variablesCompsTotals[TOTAL_CAUV] += count;
133   }
134   if (count = problem_db.get_sizet("variables.loguniform_uncertain")) {
135     variablesComponents[LOGUNIFORM_UNCERTAIN] = count;
136     variablesCompsTotals[TOTAL_CAUV] += count;
137   }
138   if (count = problem_db.get_sizet("variables.triangular_uncertain")) {
139     variablesComponents[TRIANGULAR_UNCERTAIN] = count;
140     variablesCompsTotals[TOTAL_CAUV] += count;
141   }
142   if (count = problem_db.get_sizet("variables.exponential_uncertain")) {
143     variablesComponents[EXPONENTIAL_UNCERTAIN] = count;
144     variablesCompsTotals[TOTAL_CAUV] += count;
145   }
146   if (count = problem_db.get_sizet("variables.beta_uncertain")) {
147     variablesComponents[BETA_UNCERTAIN] = count;
148     variablesCompsTotals[TOTAL_CAUV] += count;
149   }
150   if (count = problem_db.get_sizet("variables.gamma_uncertain")) {
151     variablesComponents[GAMMA_UNCERTAIN] = count;
152     variablesCompsTotals[TOTAL_CAUV] += count;
153   }
154   if (count = problem_db.get_sizet("variables.gumbel_uncertain")) {
155     variablesComponents[GUMBEL_UNCERTAIN] = count;
156     variablesCompsTotals[TOTAL_CAUV] += count;
157   }
158   if (count = problem_db.get_sizet("variables.frechet_uncertain")) {
159     variablesComponents[FRECHET_UNCERTAIN] = count;
160     variablesCompsTotals[TOTAL_CAUV] += count;
161   }
162   if (count = problem_db.get_sizet("variables.weibull_uncertain")) {
163     variablesComponents[WEIBULL_UNCERTAIN] = count;
164     variablesCompsTotals[TOTAL_CAUV] += count;
165   }
166   if (count = problem_db.get_sizet("variables.histogram_uncertain.bin")) {
167     variablesComponents[HISTOGRAM_BIN_UNCERTAIN] = count;
168     variablesCompsTotals[TOTAL_CAUV] += count;
169   }
170   // discrete integer aleatory uncertain
171   if (count = problem_db.get_sizet("variables.poisson_uncertain")) {
172     variablesComponents[POISSON_UNCERTAIN] = count;
173     variablesCompsTotals[TOTAL_DAUIV] += count;
174   }
175   if (count = problem_db.get_sizet("variables.binomial_uncertain")) {
176     variablesComponents[BINOMIAL_UNCERTAIN] = count;
177     variablesCompsTotals[TOTAL_DAUIV] += count;
178   }
179   if (count = problem_db.get_sizet("variables.negative_binomial_uncertain")){
180     variablesComponents[NEGATIVE_BINOMIAL_UNCERTAIN] = count;
181     variablesCompsTotals[TOTAL_DAUIV] += count;
182   }
183   if (count = problem_db.get_sizet("variables.geometric_uncertain")) {
184     variablesComponents[GEOMETRIC_UNCERTAIN] = count;
185     variablesCompsTotals[TOTAL_DAUIV] += count;
186   }
187   if (count = problem_db.get_sizet("variables.hypergeometric_uncertain")) {
188     variablesComponents[HYPERGEOMETRIC_UNCERTAIN] = count;
189     variablesCompsTotals[TOTAL_DAUIV] += count;
190   }
191   if (count = problem_db.get_sizet("variables.histogram_uncertain.point_int")) {
192     variablesComponents[HISTOGRAM_POINT_UNCERTAIN_INT] = count;
193     variablesCompsTotals[TOTAL_DAUIV] += count;
194   }
195   // discrete string aleatory uncertain
196   if (count =
197       problem_db.get_sizet("variables.histogram_uncertain.point_string")) {
198     variablesComponents[HISTOGRAM_POINT_UNCERTAIN_STRING] = count;
199     variablesCompsTotals[TOTAL_DAUSV] += count;
200   }
201   // discrete real aleatory uncertain
202   if (count = problem_db.get_sizet("variables.histogram_uncertain.point_real")){
203     variablesComponents[HISTOGRAM_POINT_UNCERTAIN_REAL] = count;
204     variablesCompsTotals[TOTAL_DAURV] += count;
205   }
206   // continuous epistemic uncertain
207   if (count = problem_db.get_sizet("variables.continuous_interval_uncertain")) {
208     variablesComponents[CONTINUOUS_INTERVAL_UNCERTAIN] = count;
209     variablesCompsTotals[TOTAL_CEUV] += count;
210   }
211   // discrete integer epistemic uncertain
212   if (count = problem_db.get_sizet("variables.discrete_interval_uncertain")){
213     variablesComponents[DISCRETE_INTERVAL_UNCERTAIN] = count;
214     variablesCompsTotals[TOTAL_DEUIV] += count;
215   }
216   if (count = problem_db.get_sizet("variables.discrete_uncertain_set_int")){
217     variablesComponents[DISCRETE_UNCERTAIN_SET_INT] = count;
218     variablesCompsTotals[TOTAL_DEUIV] += count;
219   }
220   // discrete string epistemic uncertain
221   if (count = problem_db.get_sizet("variables.discrete_uncertain_set_string")) {
222     variablesComponents[DISCRETE_UNCERTAIN_SET_STRING] = count;
223     variablesCompsTotals[TOTAL_DEUSV] += count;
224   }
225   // discrete real epistemic uncertain
226   if (count = problem_db.get_sizet("variables.discrete_uncertain_set_real")) {
227     variablesComponents[DISCRETE_UNCERTAIN_SET_REAL] = count;
228     variablesCompsTotals[TOTAL_DEURV] += count;
229   }
230   // continuous state
231   if (count = problem_db.get_sizet("variables.continuous_state")) {
232     variablesComponents[CONTINUOUS_STATE] = count;
233     variablesCompsTotals[TOTAL_CSV] += count;
234   }
235   // discrete integer state
236   if (count = problem_db.get_sizet("variables.discrete_state_range")) {
237     variablesComponents[DISCRETE_STATE_RANGE] = count;
238     variablesCompsTotals[TOTAL_DSIV] += count;
239   }
240   if (count = problem_db.get_sizet("variables.discrete_state_set_int")) {
241     variablesComponents[DISCRETE_STATE_SET_INT] = count;
242     variablesCompsTotals[TOTAL_DSIV] += count;
243   }
244   // discrete string state
245   if (count = problem_db.get_sizet("variables.discrete_state_set_string")) {
246     variablesComponents[DISCRETE_STATE_SET_STRING] = count;
247     variablesCompsTotals[TOTAL_DSSV] += count;
248   }
249   // discrete real state
250   if (count = problem_db.get_sizet("variables.discrete_state_set_real")) {
251     variablesComponents[DISCRETE_STATE_SET_REAL] = count;
252     variablesCompsTotals[TOTAL_DSRV] += count;
253   }
254 }
255 
256 
components_to_totals()257 void SharedVariablesDataRep::components_to_totals()
258 {
259   variablesCompsTotals.resize(NUM_VC_TOTALS);
260 
261   // continuous design
262   variablesCompsTotals[TOTAL_CDV] = vc_lookup(CONTINUOUS_DESIGN);
263   // discrete design integer
264   variablesCompsTotals[TOTAL_DDIV] = vc_lookup(DISCRETE_DESIGN_RANGE)
265     + vc_lookup(DISCRETE_DESIGN_SET_INT);
266   // discrete design string
267   variablesCompsTotals[TOTAL_DDSV] = vc_lookup(DISCRETE_DESIGN_SET_STRING);
268   // discrete design real
269   variablesCompsTotals[TOTAL_DDRV] = vc_lookup(DISCRETE_DESIGN_SET_REAL);
270   // continuous aleatory uncertain
271   variablesCompsTotals[TOTAL_CAUV]     = vc_lookup(NORMAL_UNCERTAIN)
272     + vc_lookup(LOGNORMAL_UNCERTAIN)   + vc_lookup(UNIFORM_UNCERTAIN)
273     + vc_lookup(LOGUNIFORM_UNCERTAIN)  + vc_lookup(TRIANGULAR_UNCERTAIN)
274     + vc_lookup(EXPONENTIAL_UNCERTAIN) + vc_lookup(BETA_UNCERTAIN)
275     + vc_lookup(GAMMA_UNCERTAIN)       + vc_lookup(GUMBEL_UNCERTAIN)
276     + vc_lookup(FRECHET_UNCERTAIN)     + vc_lookup(WEIBULL_UNCERTAIN)
277     + vc_lookup(HISTOGRAM_BIN_UNCERTAIN);
278   // discrete aleatory uncertain integer
279   variablesCompsTotals[TOTAL_DAUIV]  = vc_lookup(POISSON_UNCERTAIN)
280     + vc_lookup(BINOMIAL_UNCERTAIN)  + vc_lookup(NEGATIVE_BINOMIAL_UNCERTAIN)
281     + vc_lookup(GEOMETRIC_UNCERTAIN) + vc_lookup(HYPERGEOMETRIC_UNCERTAIN)
282     + vc_lookup(HISTOGRAM_POINT_UNCERTAIN_INT);
283   // discrete aleatory uncertain string
284   variablesCompsTotals[TOTAL_DAUSV]
285     = vc_lookup(HISTOGRAM_POINT_UNCERTAIN_STRING);
286   // discrete aleatory uncertain real
287   variablesCompsTotals[TOTAL_DAURV] = vc_lookup(HISTOGRAM_POINT_UNCERTAIN_REAL);
288   // continuous epistemic uncertain
289   variablesCompsTotals[TOTAL_CEUV] = vc_lookup(CONTINUOUS_INTERVAL_UNCERTAIN);
290   // discrete epistemic uncertain integer
291   variablesCompsTotals[TOTAL_DEUIV] = vc_lookup(DISCRETE_INTERVAL_UNCERTAIN)
292     + vc_lookup(DISCRETE_UNCERTAIN_SET_INT);
293   // discrete epistemic uncertain string
294   variablesCompsTotals[TOTAL_DEUSV] = vc_lookup(DISCRETE_UNCERTAIN_SET_STRING);
295   // discrete epistemic uncertain real
296   variablesCompsTotals[TOTAL_DEURV] = vc_lookup(DISCRETE_UNCERTAIN_SET_REAL);
297   // continuous state
298   variablesCompsTotals[TOTAL_CSV] = vc_lookup(CONTINUOUS_STATE);
299   // discrete state integer
300   variablesCompsTotals[TOTAL_DSIV] = vc_lookup(DISCRETE_STATE_RANGE)
301     + vc_lookup(DISCRETE_STATE_SET_INT);
302   // discrete state string
303   variablesCompsTotals[TOTAL_DSSV] = vc_lookup(DISCRETE_STATE_SET_STRING);
304   // discrete state real
305   variablesCompsTotals[TOTAL_DSRV] = vc_lookup(DISCRETE_STATE_SET_REAL);
306 }
307 
308 
309 void SharedVariablesDataRep::
relax_noncategorical(const ProblemDescDB & problem_db)310 relax_noncategorical(const ProblemDescDB& problem_db)
311 {
312   // use of RELAXED domain is independent of active view
313   bool relax = ( variablesView.first == RELAXED_ALL ||
314 		 ( variablesView.first >= RELAXED_DESIGN &&
315 		   variablesView.first <= RELAXED_STATE ) );
316   if (relax) {
317     // full length keys, init to false
318     allRelaxedDiscreteInt.resize(
319       variablesCompsTotals[TOTAL_DDIV] + variablesCompsTotals[TOTAL_DAUIV] +
320       variablesCompsTotals[TOTAL_DEUIV] + variablesCompsTotals[TOTAL_DSIV]);
321     allRelaxedDiscreteReal.resize(
322       variablesCompsTotals[TOTAL_DDRV]  + variablesCompsTotals[TOTAL_DAURV] +
323       variablesCompsTotals[TOTAL_DEURV] + variablesCompsTotals[TOTAL_DSRV]);
324     allRelaxedDiscreteInt.reset(); allRelaxedDiscreteReal.reset();
325   }
326   else { // use of any() allows Mixed case to employ empty arrays
327     allRelaxedDiscreteInt.clear(); allRelaxedDiscreteReal.clear();
328     return;
329   }
330 
331   // Note: NIDR ensures BitArray is empty or sized by number of variables
332 
333   const BitArray& ddrv_cat = problem_db.get_ba(
334     "variables.discrete_design_range.categorical");
335   const BitArray& ddsiv_cat = problem_db.get_ba(
336     "variables.discrete_design_set_int.categorical");
337   const BitArray& ddsrv_cat = problem_db.get_ba(
338     "variables.discrete_design_set_real.categorical");
339 
340   const BitArray& puv_cat = problem_db.get_ba(
341     "variables.poisson_uncertain.categorical");
342   const BitArray& biuv_cat = problem_db.get_ba(
343     "variables.binomial_uncertain.categorical");
344   const BitArray& nbuv_cat = problem_db.get_ba(
345     "variables.negative_binomial_uncertain.categorical");
346   const BitArray& geuv_cat = problem_db.get_ba(
347     "variables.geometric_uncertain.categorical");
348   const BitArray& hguv_cat = problem_db.get_ba(
349     "variables.hypergeometric_uncertain.categorical");
350   const BitArray& hupiv_cat = problem_db.get_ba(
351     "variables.histogram_uncertain.point_int.categorical");
352   const BitArray& huprv_cat = problem_db.get_ba(
353     "variables.histogram_uncertain.point_real.categorical");
354 
355   const BitArray& diuv_cat = problem_db.get_ba(
356     "variables.discrete_interval_uncertain.categorical");
357   const BitArray& dusiv_cat = problem_db.get_ba(
358     "variables.discrete_uncertain_set_int.categorical");
359   const BitArray& dusrv_cat = problem_db.get_ba(
360     "variables.discrete_uncertain_set_real.categorical");
361 
362   const BitArray& dsrv_cat = problem_db.get_ba(
363     "variables.discrete_state_range.categorical");
364   const BitArray& dssiv_cat = problem_db.get_ba(
365     "variables.discrete_state_set_int.categorical");
366   const BitArray& dssrv_cat = problem_db.get_ba(
367     "variables.discrete_state_set_real.categorical");
368 
369   /* Would require negation!
370   size_t offset_di = 0, offset_dr = 0;
371   copy_data_partial(ddrv_cat,  allRelaxedDiscreteInt, offset_di);
372   offset_di += ddrv_cat.size();
373   copy_data_partial(ddsiv_cat, allRelaxedDiscreteInt, offset_di);
374   offset_di += ddsiv_cat.size();
375   copy_data_partial(ddsrv_cat, allRelaxedDiscreteReal);
376   offset_dr += ddsrv_cat.size();
377   */
378 
379   size_t i, ardi_cntr = 0, ardr_cntr = 0,
380     num_ddrv  = vc_lookup(DISCRETE_DESIGN_RANGE),
381     num_ddsiv = vc_lookup(DISCRETE_DESIGN_SET_INT),
382     num_ddsrv = vc_lookup(DISCRETE_DESIGN_SET_REAL),
383     num_puv   = vc_lookup(POISSON_UNCERTAIN),
384     num_biuv  = vc_lookup(BINOMIAL_UNCERTAIN),
385     num_nbuv  = vc_lookup(NEGATIVE_BINOMIAL_UNCERTAIN),
386     num_geuv  = vc_lookup(GEOMETRIC_UNCERTAIN),
387     num_hguv  = vc_lookup(HYPERGEOMETRIC_UNCERTAIN),
388     num_hpuiv = vc_lookup(HISTOGRAM_POINT_UNCERTAIN_INT),
389     num_hpurv = vc_lookup(HISTOGRAM_POINT_UNCERTAIN_REAL),
390     num_diuv  = vc_lookup(DISCRETE_INTERVAL_UNCERTAIN),
391     num_dusiv = vc_lookup(DISCRETE_UNCERTAIN_SET_INT),
392     num_dusrv = vc_lookup(DISCRETE_UNCERTAIN_SET_REAL),
393     num_dsrv  = vc_lookup(DISCRETE_STATE_RANGE),
394     num_dssiv = vc_lookup(DISCRETE_STATE_SET_INT),
395     num_dssrv = vc_lookup(DISCRETE_STATE_SET_REAL);
396 
397   // discrete design
398   for (i=0; i<num_ddrv; ++i, ++ardi_cntr)
399     // Note: input spec doesn't allow user to override interval relaxation
400     set_relax(ddrv_cat, i, ardi_cntr, allRelaxedDiscreteInt);
401 
402   for (i=0; i<num_ddsiv; ++i, ++ardi_cntr)
403     set_relax(ddsiv_cat, i, ardi_cntr, allRelaxedDiscreteInt);
404 
405   for (i=0; i<num_ddsrv; ++i, ++ardr_cntr)
406     set_relax(ddsrv_cat, i, ardr_cntr, allRelaxedDiscreteReal);
407 
408   // discrete aleatory uncertain
409   for (i=0; i<num_puv; ++i, ++ardi_cntr)
410     set_relax(puv_cat, i, ardi_cntr, allRelaxedDiscreteInt);
411 
412   for (i=0; i<num_biuv; ++i, ++ardi_cntr)
413     set_relax(biuv_cat, i, ardi_cntr, allRelaxedDiscreteInt);
414 
415   for (i=0; i<num_nbuv; ++i, ++ardi_cntr)
416     set_relax(nbuv_cat, i, ardi_cntr, allRelaxedDiscreteInt);
417 
418   for (i=0; i<num_geuv; ++i, ++ardi_cntr)
419     set_relax(geuv_cat, i, ardi_cntr, allRelaxedDiscreteInt);
420 
421   for (i=0; i<num_hguv; ++i, ++ardi_cntr)
422     set_relax(hguv_cat, i, ardi_cntr, allRelaxedDiscreteInt);
423 
424   for (i=0; i<num_hpuiv; ++i, ++ardi_cntr)
425     set_relax(hupiv_cat, i, ardi_cntr, allRelaxedDiscreteInt);
426 
427   for (i=0; i<num_hpurv; ++i, ++ardr_cntr)
428     set_relax(huprv_cat, i, ardr_cntr, allRelaxedDiscreteReal);
429 
430   // discrete epistemic uncertain
431   for (i=0; i<num_diuv; ++i, ++ardi_cntr)
432     // Note: input spec doesn't allow user to override interval relaxation
433     set_relax(diuv_cat, i, ardi_cntr, allRelaxedDiscreteInt);
434 
435   for (i=0; i<num_dusiv; ++i, ++ardi_cntr)
436     set_relax(dusiv_cat, i, ardi_cntr, allRelaxedDiscreteInt);
437 
438   for (i=0; i<num_dusrv; ++i, ++ardr_cntr)
439     set_relax(dusrv_cat, i, ardr_cntr, allRelaxedDiscreteReal);
440 
441   // discrete state
442   for (i=0; i<num_dsrv; ++i, ++ardi_cntr)
443     // Note: input spec doesn't allow user to override interval relaxation
444     set_relax(dsrv_cat, i, ardi_cntr, allRelaxedDiscreteInt);
445 
446   for (i=0; i<num_dssiv; ++i, ++ardi_cntr)
447     set_relax(dssiv_cat, i, ardi_cntr, allRelaxedDiscreteInt);
448 
449   for (i=0; i<num_dssrv; ++i, ++ardr_cntr)
450     set_relax(dssrv_cat, i, ardr_cntr, allRelaxedDiscreteReal);
451 }
452 
453 
454 void SharedVariablesDataRep::
set_relax(const BitArray & user_cat_spec,size_t ucs_index,size_t ard_cntr,BitArray & ard_container)455 set_relax(const BitArray& user_cat_spec, size_t ucs_index,
456 	  size_t ard_cntr, BitArray& ard_container)
457 {
458   if (user_cat_spec.empty() || !user_cat_spec[ucs_index])
459     ard_container.set(ard_cntr);
460 }
461 
462 
463 void SharedVariablesDataRep::
initialize_all_labels(const ProblemDescDB & problem_db)464 initialize_all_labels(const ProblemDescDB& problem_db)
465 {
466   size_all_labels();
467 
468   size_t i, ardi_cntr = 0, ardr_cntr = 0,
469     acv_offset = 0, adiv_offset = 0, adsv_offset = 0, adrv_offset = 0;
470   bool relax = (allRelaxedDiscreteInt.any() || allRelaxedDiscreteReal.any());
471 
472   // design
473   const StringArray& cdv_labels
474     = problem_db.get_sa("variables.continuous_design.labels");
475   const StringArray& ddrv_labels
476     = problem_db.get_sa("variables.discrete_design_range.labels");
477   const StringArray& ddsiv_labels
478     = problem_db.get_sa("variables.discrete_design_set_int.labels");
479   const StringArray& ddssv_labels
480     = problem_db.get_sa("variables.discrete_design_set_string.labels");
481   const StringArray& ddsrv_labels
482     = problem_db.get_sa("variables.discrete_design_set_real.labels");
483   copy_data_partial(cdv_labels, allContinuousLabels, acv_offset);
484   acv_offset += cdv_labels.size();
485   copy_data_partial(ddssv_labels, allDiscreteStringLabels, adsv_offset);
486   adsv_offset += ddssv_labels.size();
487   if (relax) {
488     size_t num_ddrv  = ddrv_labels.size(), num_ddsiv = ddsiv_labels.size(),
489            num_ddsrv = ddsrv_labels.size();
490     for (i=0; i<num_ddrv; ++i, ++ardi_cntr)
491       if (allRelaxedDiscreteInt[ardi_cntr])
492 	allContinuousLabels[acv_offset++]    = ddrv_labels[i];
493       else
494 	allDiscreteIntLabels[adiv_offset++]  = ddrv_labels[i];
495     for (i=0; i<num_ddsiv; ++i, ++ardi_cntr)
496       if (allRelaxedDiscreteInt[ardi_cntr])
497 	allContinuousLabels[acv_offset++]    = ddsiv_labels[i];
498       else
499 	allDiscreteIntLabels[adiv_offset++]  = ddsiv_labels[i];
500     for (i=0; i<num_ddsrv; ++i, ++ardr_cntr)
501       if (allRelaxedDiscreteReal[ardr_cntr])
502 	allContinuousLabels[acv_offset++]    = ddsrv_labels[i];
503       else
504 	allDiscreteRealLabels[adrv_offset++] = ddsrv_labels[i];
505   }
506   else {
507     copy_data_partial(ddrv_labels, allDiscreteIntLabels, adiv_offset);
508     adiv_offset += ddrv_labels.size();
509     copy_data_partial(ddsiv_labels, allDiscreteIntLabels, adiv_offset);
510     adiv_offset += ddsiv_labels.size();
511     copy_data_partial(ddsrv_labels, allDiscreteRealLabels, adrv_offset);
512     adrv_offset += ddsrv_labels.size();
513   }
514 
515   // aleatory uncertain
516   const StringArray& cauv_labels
517     = problem_db.get_sa("variables.continuous_aleatory_uncertain.labels");
518   const StringArray& dauiv_labels
519     = problem_db.get_sa("variables.discrete_aleatory_uncertain_int.labels");
520   const StringArray& dausv_labels
521     = problem_db.get_sa("variables.discrete_aleatory_uncertain_string.labels");
522   const StringArray& daurv_labels
523     = problem_db.get_sa("variables.discrete_aleatory_uncertain_real.labels");
524   copy_data_partial(cauv_labels, allContinuousLabels, acv_offset);
525   acv_offset += cauv_labels.size();
526   copy_data_partial(dausv_labels, allDiscreteStringLabels, adsv_offset);
527   adsv_offset += dausv_labels.size();
528   if (relax) {
529     // Note: for generality/consistency, we also support {,non}categorical for
530     // all discrete aleatory random variables, even though continuous relaxation
531     // is a logical stretch for poisson,{,negative_}binominal,{,hyper}geometric
532     size_t num_dauiv = dauiv_labels.size(), num_daurv = daurv_labels.size();
533     for (i=0; i<num_dauiv; ++i, ++ardi_cntr)
534       if (allRelaxedDiscreteInt[ardi_cntr])
535 	allContinuousLabels[acv_offset++]    = dauiv_labels[i];
536       else
537 	allDiscreteIntLabels[adiv_offset++]  = dauiv_labels[i];
538     for (i=0; i<num_daurv; ++i, ++ardr_cntr)
539       if (allRelaxedDiscreteReal[ardr_cntr])
540 	allContinuousLabels[acv_offset++]    = daurv_labels[i];
541       else
542 	allDiscreteRealLabels[adrv_offset++] = daurv_labels[i];
543   }
544   else {
545     copy_data_partial(dauiv_labels, allDiscreteIntLabels, adiv_offset);
546     adiv_offset += dauiv_labels.size();
547     copy_data_partial(daurv_labels, allDiscreteRealLabels, adrv_offset);
548     adrv_offset += daurv_labels.size();
549   }
550 
551   // epistemic uncertain
552   const StringArray& ceuv_labels
553     = problem_db.get_sa("variables.continuous_epistemic_uncertain.labels");
554   const StringArray& deuiv_labels
555     = problem_db.get_sa("variables.discrete_epistemic_uncertain_int.labels");
556   const StringArray& deusv_labels
557     = problem_db.get_sa("variables.discrete_epistemic_uncertain_string.labels");
558   const StringArray& deurv_labels
559     = problem_db.get_sa("variables.discrete_epistemic_uncertain_real.labels");
560   copy_data_partial(ceuv_labels, allContinuousLabels, acv_offset);
561   acv_offset += ceuv_labels.size();
562   copy_data_partial(deusv_labels, allDiscreteStringLabels, adsv_offset);
563   adsv_offset += deusv_labels.size();
564   if (relax) {
565     size_t num_deuiv = deuiv_labels.size(), num_deurv = deurv_labels.size();
566     for (i=0; i<num_deuiv; ++i, ++ardi_cntr)
567       if (allRelaxedDiscreteInt[ardi_cntr])
568 	allContinuousLabels[acv_offset++]    = deuiv_labels[i];
569       else
570 	allDiscreteIntLabels[adiv_offset++]  = deuiv_labels[i];
571     for (i=0; i<num_deurv; ++i, ++ardr_cntr)
572       if (allRelaxedDiscreteReal[ardr_cntr])
573 	allContinuousLabels[acv_offset++]    = deurv_labels[i];
574       else
575 	allDiscreteRealLabels[adrv_offset++] = deurv_labels[i];
576   }
577   else {
578     copy_data_partial(deuiv_labels, allDiscreteIntLabels,  adiv_offset);
579     adiv_offset += deuiv_labels.size();
580     copy_data_partial(deurv_labels, allDiscreteRealLabels, adrv_offset);
581     adrv_offset += deurv_labels.size();
582   }
583 
584   // state
585   const StringArray& csv_labels
586     = problem_db.get_sa("variables.continuous_state.labels");
587   const StringArray& dsrv_labels
588     = problem_db.get_sa("variables.discrete_state_range.labels");
589   const StringArray& dssiv_labels
590     = problem_db.get_sa("variables.discrete_state_set_int.labels");
591   const StringArray& dsssv_labels
592     = problem_db.get_sa("variables.discrete_state_set_string.labels");
593   const StringArray& dssrv_labels
594     = problem_db.get_sa("variables.discrete_state_set_real.labels");
595   copy_data_partial(csv_labels, allContinuousLabels, acv_offset);
596   acv_offset += csv_labels.size();
597   copy_data_partial(dsssv_labels, allDiscreteStringLabels, adsv_offset);
598   adsv_offset += dsssv_labels.size();
599   if (relax) {
600     size_t num_dsrv  = dsrv_labels.size(), num_dssiv = dssiv_labels.size(),
601            num_dssrv = dssrv_labels.size();
602     for (i=0; i<num_dsrv; ++i, ++ardi_cntr)
603       if (allRelaxedDiscreteInt[ardi_cntr])
604 	allContinuousLabels[acv_offset++]    = dsrv_labels[i];
605       else
606 	allDiscreteIntLabels[adiv_offset++]  = dsrv_labels[i];
607     for (i=0; i<num_dssiv; ++i, ++ardi_cntr)
608       if (allRelaxedDiscreteInt[ardi_cntr])
609 	allContinuousLabels[acv_offset++]    = dssiv_labels[i];
610       else
611 	allDiscreteIntLabels[adiv_offset++]  = dssiv_labels[i];
612     for (i=0; i<num_dssrv; ++i, ++ardr_cntr)
613       if (allRelaxedDiscreteReal[ardr_cntr])
614 	allContinuousLabels[acv_offset++]    = dssrv_labels[i];
615       else
616 	allDiscreteRealLabels[adrv_offset++] = dssrv_labels[i];
617   }
618   else {
619     copy_data_partial(dsrv_labels, allDiscreteIntLabels, adiv_offset);
620     adiv_offset += dsrv_labels.size();
621     copy_data_partial(dssiv_labels, allDiscreteIntLabels, adiv_offset);
622     adiv_offset += dssiv_labels.size();
623     copy_data_partial(dssrv_labels, allDiscreteRealLabels, adrv_offset);
624     adrv_offset += dssrv_labels.size();
625   }
626 }
627 
628 
initialize_all_types()629 void SharedVariablesDataRep::initialize_all_types()
630 {
631   size_all_types();
632   bool relax = (allRelaxedDiscreteInt.any() || allRelaxedDiscreteReal.any());
633 
634   // DESIGN
635   size_t i, act_cntr = 0, adit_cntr = 0, adst_cntr = 0, adrt_cntr = 0,
636     ardi_cntr = 0, ardr_cntr = 0,
637     num_cdv   = vc_lookup(CONTINUOUS_DESIGN),
638     num_ddrv  = vc_lookup(DISCRETE_DESIGN_RANGE),
639     num_ddsiv = vc_lookup(DISCRETE_DESIGN_SET_INT),
640     num_ddssv = vc_lookup(DISCRETE_DESIGN_SET_STRING),
641     num_ddsrv = vc_lookup(DISCRETE_DESIGN_SET_REAL);
642   for (i=0; i<num_cdv; ++i, ++act_cntr)
643     allContinuousTypes[act_cntr] = CONTINUOUS_DESIGN;
644   for (i=0; i<num_ddssv; ++i, ++adst_cntr)
645     allDiscreteStringTypes[adst_cntr] = DISCRETE_DESIGN_SET_STRING;
646   if (relax) {
647     for (i=0; i<num_ddrv; ++i, ++ardi_cntr)
648       if (allRelaxedDiscreteInt[ardi_cntr])
649 	allContinuousTypes[act_cntr++] = DISCRETE_DESIGN_RANGE;
650       else
651 	allDiscreteIntTypes[adit_cntr++] = DISCRETE_DESIGN_RANGE;
652     for (i=0; i<num_ddsiv; ++i, ++ardi_cntr)
653       if (allRelaxedDiscreteInt[ardi_cntr])
654 	allContinuousTypes[act_cntr++] = DISCRETE_DESIGN_SET_INT;
655       else
656 	allDiscreteIntTypes[adit_cntr++] = DISCRETE_DESIGN_SET_INT;
657     for (i=0; i<num_ddsrv; ++i, ++ardr_cntr)
658       if (allRelaxedDiscreteReal[ardr_cntr])
659 	allContinuousTypes[act_cntr++] = DISCRETE_DESIGN_SET_REAL;
660       else
661 	allDiscreteRealTypes[adrt_cntr++] = DISCRETE_DESIGN_SET_REAL;
662   }
663   else {
664     for (i=0; i<num_ddrv; ++i, ++adit_cntr)
665       allDiscreteIntTypes[adit_cntr] = DISCRETE_DESIGN_RANGE;
666     for (i=0; i<num_ddsiv; ++i, ++adit_cntr)
667       allDiscreteIntTypes[adit_cntr] = DISCRETE_DESIGN_SET_INT;
668     for (i=0; i<num_ddsrv; ++i, ++adrt_cntr)
669       allDiscreteRealTypes[adrt_cntr] = DISCRETE_DESIGN_SET_REAL;
670   }
671 
672   // ALEATORY UNCERTAIN
673   size_t num_nuv  = vc_lookup(NORMAL_UNCERTAIN),
674     num_lnuv = vc_lookup(LOGNORMAL_UNCERTAIN),
675     num_uuv  = vc_lookup(UNIFORM_UNCERTAIN),
676     num_luuv = vc_lookup(LOGUNIFORM_UNCERTAIN),
677     num_tuv  = vc_lookup(TRIANGULAR_UNCERTAIN),
678     num_exuv = vc_lookup(EXPONENTIAL_UNCERTAIN),
679     num_beuv = vc_lookup(BETA_UNCERTAIN),
680     num_gauv = vc_lookup(GAMMA_UNCERTAIN),
681     num_guuv = vc_lookup(GUMBEL_UNCERTAIN),
682     num_fuv  = vc_lookup(FRECHET_UNCERTAIN),
683     num_wuv  = vc_lookup(WEIBULL_UNCERTAIN),
684     num_hbuv = vc_lookup(HISTOGRAM_BIN_UNCERTAIN),
685     num_puv   = vc_lookup(POISSON_UNCERTAIN),
686     num_biuv  = vc_lookup(BINOMIAL_UNCERTAIN),
687     num_nbuv  = vc_lookup(NEGATIVE_BINOMIAL_UNCERTAIN),
688     num_geuv  = vc_lookup(GEOMETRIC_UNCERTAIN),
689     num_hguv  = vc_lookup(HYPERGEOMETRIC_UNCERTAIN),
690     num_hpuiv = vc_lookup(HISTOGRAM_POINT_UNCERTAIN_INT),
691     num_hpusv = vc_lookup(HISTOGRAM_POINT_UNCERTAIN_STRING),
692     num_hpurv = vc_lookup(HISTOGRAM_POINT_UNCERTAIN_REAL);
693   for (i=0; i<num_nuv; ++i, ++act_cntr)
694     allContinuousTypes[act_cntr] = NORMAL_UNCERTAIN;
695   for (i=0; i<num_lnuv; ++i, ++act_cntr)
696     allContinuousTypes[act_cntr] = LOGNORMAL_UNCERTAIN;
697   for (i=0; i<num_uuv; ++i, ++act_cntr)
698     allContinuousTypes[act_cntr] = UNIFORM_UNCERTAIN;
699   for (i=0; i<num_luuv; ++i, ++act_cntr)
700     allContinuousTypes[act_cntr] = LOGUNIFORM_UNCERTAIN;
701   for (i=0; i<num_tuv; ++i, ++act_cntr)
702     allContinuousTypes[act_cntr] = TRIANGULAR_UNCERTAIN;
703   for (i=0; i<num_exuv; ++i, ++act_cntr)
704     allContinuousTypes[act_cntr] = EXPONENTIAL_UNCERTAIN;
705   for (i=0; i<num_beuv; ++i, ++act_cntr)
706     allContinuousTypes[act_cntr] = BETA_UNCERTAIN;
707   for (i=0; i<num_gauv; ++i, ++act_cntr)
708     allContinuousTypes[act_cntr] = GAMMA_UNCERTAIN;
709   for (i=0; i<num_guuv; ++i, ++act_cntr)
710     allContinuousTypes[act_cntr] = GUMBEL_UNCERTAIN;
711   for (i=0; i<num_fuv; ++i, ++act_cntr)
712     allContinuousTypes[act_cntr] = FRECHET_UNCERTAIN;
713   for (i=0; i<num_wuv; ++i, ++act_cntr)
714     allContinuousTypes[act_cntr] = WEIBULL_UNCERTAIN;
715   for (i=0; i<num_hbuv; ++i, ++act_cntr)
716     allContinuousTypes[act_cntr] = HISTOGRAM_BIN_UNCERTAIN;
717   for (i=0; i<num_hpusv; ++i, ++adst_cntr)
718     allDiscreteStringTypes[adst_cntr] = HISTOGRAM_POINT_UNCERTAIN_STRING;
719   if (relax) {
720     for (i=0; i<num_puv; ++i, ++ardi_cntr)
721       if (allRelaxedDiscreteInt[ardi_cntr])
722 	allContinuousTypes[act_cntr++] = POISSON_UNCERTAIN;
723       else
724 	allDiscreteIntTypes[adit_cntr++] = POISSON_UNCERTAIN;
725     for (i=0; i<num_biuv; ++i, ++ardi_cntr)
726       if (allRelaxedDiscreteInt[ardi_cntr])
727 	allContinuousTypes[act_cntr++] = BINOMIAL_UNCERTAIN;
728       else
729 	allDiscreteIntTypes[adit_cntr++] = BINOMIAL_UNCERTAIN;
730     for (i=0; i<num_nbuv; ++i, ++ardi_cntr)
731       if (allRelaxedDiscreteInt[ardi_cntr])
732 	allContinuousTypes[act_cntr++] = NEGATIVE_BINOMIAL_UNCERTAIN;
733       else
734 	allDiscreteIntTypes[adit_cntr++] = NEGATIVE_BINOMIAL_UNCERTAIN;
735     for (i=0; i<num_geuv; ++i, ++ardi_cntr)
736       if (allRelaxedDiscreteInt[ardi_cntr])
737 	allContinuousTypes[act_cntr++] = GEOMETRIC_UNCERTAIN;
738       else
739 	allDiscreteIntTypes[adit_cntr++] = GEOMETRIC_UNCERTAIN;
740     for (i=0; i<num_hguv; ++i, ++ardi_cntr)
741       if (allRelaxedDiscreteInt[ardi_cntr])
742 	allContinuousTypes[act_cntr++] = HYPERGEOMETRIC_UNCERTAIN;
743       else
744 	allDiscreteIntTypes[adit_cntr++] = HYPERGEOMETRIC_UNCERTAIN;
745     for (i=0; i<num_hpuiv; ++i, ++ardi_cntr)
746       if (allRelaxedDiscreteInt[ardi_cntr])
747 	allContinuousTypes[act_cntr++] = HISTOGRAM_POINT_UNCERTAIN_INT;
748       else
749 	allDiscreteIntTypes[adit_cntr++] = HISTOGRAM_POINT_UNCERTAIN_INT;
750     for (i=0; i<num_hpurv; ++i, ++ardr_cntr)
751       if (allRelaxedDiscreteReal[ardr_cntr])
752 	allContinuousTypes[act_cntr++] = HISTOGRAM_POINT_UNCERTAIN_REAL;
753       else
754 	allDiscreteRealTypes[adrt_cntr++] = HISTOGRAM_POINT_UNCERTAIN_REAL;
755   }
756   else {
757     for (i=0; i<num_puv; ++i, ++adit_cntr)
758       allDiscreteIntTypes[adit_cntr] = POISSON_UNCERTAIN;
759     for (i=0; i<num_biuv; ++i, ++adit_cntr)
760       allDiscreteIntTypes[adit_cntr] = BINOMIAL_UNCERTAIN;
761     for (i=0; i<num_nbuv; ++i, ++adit_cntr)
762       allDiscreteIntTypes[adit_cntr] = NEGATIVE_BINOMIAL_UNCERTAIN;
763     for (i=0; i<num_geuv; ++i, ++adit_cntr)
764       allDiscreteIntTypes[adit_cntr] = GEOMETRIC_UNCERTAIN;
765     for (i=0; i<num_hguv; ++i, ++adit_cntr)
766       allDiscreteIntTypes[adit_cntr] = HYPERGEOMETRIC_UNCERTAIN;
767     for (i=0; i<num_hpuiv; ++i, ++adit_cntr)
768       allDiscreteIntTypes[adit_cntr] = HISTOGRAM_POINT_UNCERTAIN_INT;
769     for (i=0; i<num_hpurv; ++i, ++adrt_cntr)
770       allDiscreteRealTypes[adrt_cntr] = HISTOGRAM_POINT_UNCERTAIN_REAL;
771   }
772 
773   // EPISTEMIC UNCERTAIN
774   size_t num_ciuv = vc_lookup(CONTINUOUS_INTERVAL_UNCERTAIN),
775     num_diuv  = vc_lookup(DISCRETE_INTERVAL_UNCERTAIN),
776     num_dusiv = vc_lookup(DISCRETE_UNCERTAIN_SET_INT),
777     num_dussv = vc_lookup(DISCRETE_UNCERTAIN_SET_STRING),
778     num_dusrv = vc_lookup(DISCRETE_UNCERTAIN_SET_REAL);
779   for (i=0; i<num_ciuv; ++i, ++act_cntr)
780     allContinuousTypes[act_cntr] = CONTINUOUS_INTERVAL_UNCERTAIN;
781   for (i=0; i<num_dussv; ++i, ++adst_cntr)
782     allDiscreteStringTypes[adst_cntr] = DISCRETE_UNCERTAIN_SET_STRING;
783   if (relax) {
784     for (i=0; i<num_diuv; ++i, ++ardi_cntr)
785       if (allRelaxedDiscreteInt[ardi_cntr])
786 	allContinuousTypes[act_cntr++] = DISCRETE_INTERVAL_UNCERTAIN;
787       else
788 	allDiscreteIntTypes[adit_cntr++] = DISCRETE_INTERVAL_UNCERTAIN;
789     for (i=0; i<num_dusiv; ++i, ++ardi_cntr)
790       if (allRelaxedDiscreteInt[ardi_cntr])
791 	allContinuousTypes[act_cntr++] = DISCRETE_UNCERTAIN_SET_INT;
792       else
793 	allDiscreteIntTypes[adit_cntr++] = DISCRETE_UNCERTAIN_SET_INT;
794     for (i=0; i<num_dusrv; ++i, ++ardr_cntr)
795       if (allRelaxedDiscreteReal[ardr_cntr])
796 	allContinuousTypes[act_cntr++] = DISCRETE_UNCERTAIN_SET_REAL;
797       else
798 	allDiscreteRealTypes[adrt_cntr++] = DISCRETE_UNCERTAIN_SET_REAL;
799   }
800   else {
801     for (i=0; i<num_diuv; ++i, ++adit_cntr)
802       allDiscreteIntTypes[adit_cntr] = DISCRETE_INTERVAL_UNCERTAIN;
803     for (i=0; i<num_dusiv; ++i, ++adit_cntr)
804       allDiscreteIntTypes[adit_cntr] = DISCRETE_UNCERTAIN_SET_INT;
805     for (i=0; i<num_dusrv; ++i, ++adrt_cntr)
806       allDiscreteRealTypes[adrt_cntr] = DISCRETE_UNCERTAIN_SET_REAL;
807   }
808 
809   // STATE
810   size_t num_csv = vc_lookup(CONTINUOUS_STATE),
811     num_dsrv  = vc_lookup(DISCRETE_STATE_RANGE),
812     num_dssiv = vc_lookup(DISCRETE_STATE_SET_INT),
813     num_dsssv = vc_lookup(DISCRETE_STATE_SET_STRING),
814     num_dssrv = vc_lookup(DISCRETE_STATE_SET_REAL);
815   for (i=0; i<num_csv; ++i, ++act_cntr)
816     allContinuousTypes[act_cntr] = CONTINUOUS_STATE;
817   for (i=0; i<num_dsssv; ++i, ++adst_cntr)
818     allDiscreteStringTypes[adst_cntr] = DISCRETE_STATE_SET_STRING;
819   if (relax) {
820     for (i=0; i<num_dsrv; ++i, ++ardi_cntr)
821       if (allRelaxedDiscreteInt[ardi_cntr])
822 	allContinuousTypes[act_cntr++] = DISCRETE_STATE_RANGE;
823       else
824 	allDiscreteIntTypes[adit_cntr++] = DISCRETE_STATE_RANGE;
825     for (i=0; i<num_dssiv; ++i, ++ardi_cntr)
826       if (allRelaxedDiscreteInt[ardi_cntr])
827 	allContinuousTypes[act_cntr++] = DISCRETE_STATE_SET_INT;
828       else
829 	allDiscreteIntTypes[adit_cntr++] = DISCRETE_STATE_SET_INT;
830     for (i=0; i<num_dssrv; ++i, ++ardr_cntr)
831       if (allRelaxedDiscreteReal[ardr_cntr])
832 	allContinuousTypes[act_cntr++] = DISCRETE_STATE_SET_REAL;
833       else
834 	allDiscreteRealTypes[adrt_cntr++] = DISCRETE_STATE_SET_REAL;
835   }
836   else {
837     for (i=0; i<num_dsrv; ++i, ++adit_cntr)
838       allDiscreteIntTypes[adit_cntr] = DISCRETE_STATE_RANGE;
839     for (i=0; i<num_dssiv; ++i, ++adit_cntr)
840       allDiscreteIntTypes[adit_cntr] = DISCRETE_STATE_SET_INT;
841     for (i=0; i<num_dssrv; ++i, ++adrt_cntr)
842       allDiscreteRealTypes[adrt_cntr] = DISCRETE_STATE_SET_REAL;
843   }
844 }
845 
846 
initialize_all_ids()847 void SharedVariablesDataRep::initialize_all_ids()
848 {
849   size_t i = 0, id = 1, // identifiers are 1-based (indices are 0-based)
850     // counters for id insertion
851     acv_cntr = 0, adiv_cntr = 0, adsv_cntr = 0, adrv_cntr = 0,
852     // counters for relax BitArrays
853     relax_int_cntr = 0, relax_real_cntr = 0,
854 
855     num_cdv   = variablesCompsTotals[TOTAL_CDV],
856     num_ddiv  = variablesCompsTotals[TOTAL_DDIV],
857     num_ddsv  = variablesCompsTotals[TOTAL_DDSV],
858     num_ddrv  = variablesCompsTotals[TOTAL_DDRV],
859 
860     num_cauv  = variablesCompsTotals[TOTAL_CAUV],
861     num_dauiv = variablesCompsTotals[TOTAL_DAUIV],
862     num_dausv = variablesCompsTotals[TOTAL_DAUSV],
863     num_daurv = variablesCompsTotals[TOTAL_DAURV],
864 
865     num_ceuv  = variablesCompsTotals[TOTAL_CEUV],
866     num_deuiv = variablesCompsTotals[TOTAL_DEUIV],
867     num_deusv = variablesCompsTotals[TOTAL_DEUSV],
868     num_deurv = variablesCompsTotals[TOTAL_DEURV],
869 
870     num_csv   = variablesCompsTotals[TOTAL_CSV],
871     num_dsiv  = variablesCompsTotals[TOTAL_DSIV],
872     num_dssv  = variablesCompsTotals[TOTAL_DSSV],
873     num_dsrv  = variablesCompsTotals[TOTAL_DSRV],
874 
875     num_acv    = num_cdv  + num_cauv  + num_ceuv  + num_csv,
876     num_adiv   = num_ddiv + num_dauiv + num_deuiv + num_dsiv,
877     num_adsv   = num_ddsv + num_dausv + num_deusv + num_dssv,
878     num_adrv   = num_ddrv + num_daurv + num_deurv + num_dsrv;
879 
880   // aggregateBitArrays defined over all discrete int,real
881   bool relax = (allRelaxedDiscreteInt.any() || allRelaxedDiscreteReal.any());
882   if (relax) {
883     // include relaxed discrete int/real design/uncertain/state in continuous
884     num_acv += allRelaxedDiscreteInt.count() + allRelaxedDiscreteReal.count();
885     // omit relaxed discrete int/real design/uncertain/state from discrete counts
886     num_adiv -= allRelaxedDiscreteInt.count();
887     num_adrv -= allRelaxedDiscreteReal.count();
888   }
889 
890   allContinuousIds.resize(boost::extents[num_acv]);
891   allDiscreteIntIds.resize(boost::extents[num_adiv]);
892   allDiscreteStringIds.resize(boost::extents[num_adsv]);
893   allDiscreteRealIds.resize(boost::extents[num_adrv]);
894 
895   // DESIGN
896   for (i=0; i<num_cdv; ++i, ++id)
897     allContinuousIds[acv_cntr++] = id;
898 
899   for (i=0; i<num_ddiv; ++i, ++relax_int_cntr, ++id)
900     if (allRelaxedDiscreteInt.any() && allRelaxedDiscreteInt[relax_int_cntr])
901       allContinuousIds[acv_cntr++] = id;
902     else
903       allDiscreteIntIds[adiv_cntr++] = id;
904 
905   for (i=0; i<num_ddsv; ++i, ++id)
906       allDiscreteStringIds[adsv_cntr++] = id;
907 
908   for (i=0; i<num_ddrv; ++i, ++relax_real_cntr, ++id)
909     if (allRelaxedDiscreteReal.any() && allRelaxedDiscreteReal[relax_real_cntr])
910       allContinuousIds[acv_cntr++] = id;
911     else
912       allDiscreteRealIds[adrv_cntr++] = id;
913 
914   // ALEATORY UNCERTAIN
915   for (i=0; i<num_cauv; ++i, ++id)
916     allContinuousIds[acv_cntr++] = id;
917 
918   for (i=0; i<num_dauiv; ++i, ++relax_int_cntr, ++id)
919     if (allRelaxedDiscreteInt.any() && allRelaxedDiscreteInt[relax_int_cntr])
920       allContinuousIds[acv_cntr++] = id;
921     else
922       allDiscreteIntIds[adiv_cntr++] = id;
923 
924   for (i=0; i<num_dausv; ++i, ++id)
925       allDiscreteStringIds[adsv_cntr++] = id;
926 
927   for (i=0; i<num_daurv; ++i, ++relax_real_cntr, ++id)
928     if (allRelaxedDiscreteReal.any() && allRelaxedDiscreteReal[relax_real_cntr])
929       allContinuousIds[acv_cntr++] = id;
930     else
931       allDiscreteRealIds[adrv_cntr++] = id;
932 
933   // EPISTEMIC UNCERTAIN
934   for (i=0; i<num_ceuv; ++i, ++id)
935     allContinuousIds[acv_cntr++] = id;
936 
937   for (i=0; i<num_deuiv; ++i, ++relax_int_cntr, ++id)
938     if (allRelaxedDiscreteInt.any() && allRelaxedDiscreteInt[relax_int_cntr])
939       allContinuousIds[acv_cntr++] = id;
940     else
941       allDiscreteIntIds[adiv_cntr++] = id;
942 
943   for (i=0; i<num_deusv; ++i, ++id)
944       allDiscreteStringIds[adsv_cntr++] = id;
945 
946   for (i=0; i<num_deurv; ++i, ++relax_real_cntr, ++id)
947     if (allRelaxedDiscreteReal.any() && allRelaxedDiscreteReal[relax_real_cntr])
948       allContinuousIds[acv_cntr++] = id;
949     else
950       allDiscreteRealIds[adrv_cntr++] = id;
951 
952   // STATE
953   for (i=0; i<num_csv; ++i, ++id)
954     allContinuousIds[acv_cntr++] = id;
955 
956   for (i=0; i<num_dsiv; ++i, ++relax_int_cntr, ++id)
957     if (allRelaxedDiscreteInt.any() && allRelaxedDiscreteInt[relax_int_cntr])
958       allContinuousIds[acv_cntr++] = id;
959     else
960       allDiscreteIntIds[adiv_cntr++] = id;
961 
962   for (i=0; i<num_dssv; ++i, ++id)
963       allDiscreteStringIds[adsv_cntr++] = id;
964 
965   for (i=0; i<num_dsrv; ++i, ++relax_real_cntr, ++id)
966     if (allRelaxedDiscreteReal.any() && allRelaxedDiscreteReal[relax_real_cntr])
967       allContinuousIds[acv_cntr++] = id;
968     else
969       allDiscreteRealIds[adrv_cntr++] = id;
970 }
971 
972 
973 void SharedVariablesDataRep::
view_start_counts(short view,size_t & cv_start,size_t & div_start,size_t & dsv_start,size_t & drv_start,size_t & num_cv,size_t & num_div,size_t & num_dsv,size_t & num_drv) const974 view_start_counts(short view, size_t& cv_start, size_t& div_start,
975 		  size_t& dsv_start, size_t& drv_start, size_t& num_cv,
976 		  size_t& num_div, size_t& num_dsv, size_t& num_drv) const
977 {
978   size_t i, offset, start_relax_di = 0, start_relax_dr = 0,
979     count_relax_di = 0, count_relax_dr = 0,
980     num_cdv   = variablesCompsTotals[TOTAL_CDV],
981     num_ddiv  = variablesCompsTotals[TOTAL_DDIV],
982     num_ddsv  = variablesCompsTotals[TOTAL_DDSV],
983     num_ddrv  = variablesCompsTotals[TOTAL_DDRV],
984     num_cauv  = variablesCompsTotals[TOTAL_CAUV],
985     num_dauiv = variablesCompsTotals[TOTAL_DAUIV],
986     num_dausv = variablesCompsTotals[TOTAL_DAUSV],
987     num_daurv = variablesCompsTotals[TOTAL_DAURV],
988     num_ceuv  = variablesCompsTotals[TOTAL_CEUV],
989     num_deuiv = variablesCompsTotals[TOTAL_DEUIV],
990     num_deusv = variablesCompsTotals[TOTAL_DEUSV],
991     num_deurv = variablesCompsTotals[TOTAL_DEURV],
992     num_csv   = variablesCompsTotals[TOTAL_CSV],
993     num_dsiv  = variablesCompsTotals[TOTAL_DSIV],
994     num_dssv  = variablesCompsTotals[TOTAL_DSSV],
995     num_dsrv  = variablesCompsTotals[TOTAL_DSRV];
996 
997   switch (view) {
998   case EMPTY_VIEW: // should only happen for inactive views
999     cv_start = div_start = dsv_start = drv_start =
1000       num_cv = num_div = num_dsv = num_drv = 0;
1001     break;
1002   case MIXED_ALL: // should only happen for active views
1003     // start at the beginning
1004     cv_start = div_start = dsv_start = drv_start = 0;
1005     num_cv  = num_cdv  + num_cauv  + num_ceuv  + num_csv;
1006     num_div = num_ddiv + num_dauiv + num_deuiv + num_dsiv;
1007     num_dsv = num_ddsv + num_dausv + num_deusv + num_dssv;
1008     num_drv = num_ddrv + num_daurv + num_deurv + num_dsrv;            break;
1009   case MIXED_DESIGN:
1010     // start at the beginning
1011     cv_start = div_start = dsv_start = drv_start = 0;
1012     num_cv  = num_cdv;  num_div = num_ddiv;
1013     num_dsv = num_ddsv; num_drv = num_ddrv;                           break;
1014   case MIXED_ALEATORY_UNCERTAIN:
1015     // skip over the design variables
1016     cv_start  = num_cdv;  num_cv  = num_cauv;
1017     div_start = num_ddiv; num_div = num_dauiv;
1018     dsv_start = num_ddsv; num_dsv = num_dausv;
1019     drv_start = num_ddrv; num_drv = num_daurv;                        break;
1020   case MIXED_EPISTEMIC_UNCERTAIN:
1021     // skip over the design and aleatory uncertain variables
1022     cv_start  = num_cdv  + num_cauv;  num_cv  = num_ceuv;
1023     div_start = num_ddiv + num_dauiv; num_div = num_deuiv;
1024     dsv_start = num_ddsv + num_dausv; num_dsv = num_deusv;
1025     drv_start = num_ddrv + num_daurv; num_drv = num_deurv;            break;
1026   case MIXED_UNCERTAIN:
1027     // skip over the design variables
1028     cv_start  = num_cdv;  num_cv  = num_cauv  + num_ceuv;
1029     div_start = num_ddiv; num_div = num_dauiv + num_deuiv;
1030     dsv_start = num_ddsv; num_dsv = num_dausv + num_deusv;
1031     drv_start = num_ddrv; num_drv = num_daurv + num_deurv;            break;
1032   case MIXED_STATE:
1033     // skip over all the design and uncertain variables
1034     cv_start  = num_cdv  + num_cauv  + num_ceuv;  num_cv  = num_csv;
1035     div_start = num_ddiv + num_dauiv + num_deuiv; num_div = num_dsiv;
1036     dsv_start = num_ddsv + num_dausv + num_deusv; num_dsv = num_dssv;
1037     drv_start = num_ddrv + num_daurv + num_deurv; num_drv = num_dsrv; break;
1038   case RELAXED_ALL:
1039     // from head to tail
1040     for (i=0; i<num_ddiv; ++i)
1041       if (allRelaxedDiscreteInt[i])  ++count_relax_di;
1042     for (i=0; i<num_ddrv; ++i)
1043       if (allRelaxedDiscreteReal[i]) ++count_relax_dr;
1044     cv_start = div_start = dsv_start = drv_start = 0;
1045     num_cv  = num_cdv  + num_cauv  + num_ceuv  + num_csv
1046             + count_relax_di + count_relax_dr;
1047     num_div = num_ddiv + num_dauiv + num_deuiv + num_dsiv - count_relax_di;
1048     num_dsv = num_ddsv + num_dausv + num_deusv + num_dssv;
1049     num_drv = num_ddrv + num_daurv + num_deurv + num_dsrv - count_relax_dr;
1050     break;
1051   case RELAXED_DESIGN:
1052     // start at head
1053     for (i=0; i<num_ddiv; ++i)
1054       if (allRelaxedDiscreteInt[i])  ++count_relax_di;
1055     for (i=0; i<num_ddrv; ++i)
1056       if (allRelaxedDiscreteReal[i]) ++count_relax_dr;
1057     cv_start  = 0; num_cv  = num_cdv  + count_relax_di + count_relax_dr;
1058     div_start = 0; num_div = num_ddiv - count_relax_di;
1059     dsv_start = 0; num_dsv = num_ddsv;
1060     drv_start = 0; num_drv = num_ddrv - count_relax_dr;
1061     break;
1062   case RELAXED_ALEATORY_UNCERTAIN:
1063     // skip over the design variables
1064     offset = num_ddiv;
1065     for (i=0; i<offset; ++i)
1066       if (allRelaxedDiscreteInt[i])        ++start_relax_di;
1067     for (i=0; i<num_dauiv; ++i)
1068       if (allRelaxedDiscreteInt[offset+i]) ++count_relax_di;
1069     offset = num_ddrv;
1070     for (i=0; i<offset; ++i)
1071       if (allRelaxedDiscreteReal[i])        ++start_relax_dr;
1072     for (i=0; i<num_daurv; ++i)
1073       if (allRelaxedDiscreteReal[offset+i]) ++count_relax_dr;
1074     cv_start  = num_cdv   + start_relax_di + start_relax_dr;
1075     div_start = num_ddiv  - start_relax_di;
1076     dsv_start = num_ddsv;
1077     drv_start = num_ddrv  - start_relax_dr;
1078     num_cv    = num_cauv  + count_relax_di + count_relax_dr;
1079     num_div   = num_dauiv - count_relax_di;
1080     num_dsv   = num_dausv;
1081     num_drv   = num_daurv - count_relax_dr;
1082     break;
1083   case RELAXED_EPISTEMIC_UNCERTAIN:
1084     // skip over the design and aleatory variables
1085     offset = num_ddiv + num_dauiv;
1086     for (i=0; i<offset; ++i)
1087       if (allRelaxedDiscreteInt[i])        ++start_relax_di;
1088     for (i=0; i<num_deuiv; ++i)
1089       if (allRelaxedDiscreteInt[offset+i]) ++count_relax_di;
1090     offset = num_ddrv + num_daurv;
1091     for (i=0; i<offset; ++i)
1092       if (allRelaxedDiscreteReal[i])        ++start_relax_dr;
1093     for (i=0; i<num_deurv; ++i)
1094       if (allRelaxedDiscreteReal[offset+i]) ++count_relax_dr;
1095     cv_start  = num_cdv   + num_cauv  + start_relax_di + start_relax_dr;
1096     div_start = num_ddiv  + num_dauiv - start_relax_di;
1097     dsv_start = num_ddsv  + num_dausv;
1098     drv_start = num_ddrv  + num_daurv - start_relax_dr;
1099     num_cv    = num_ceuv  + count_relax_di + count_relax_dr;
1100     num_div   = num_deuiv - count_relax_di;
1101     num_dsv   = num_deusv;
1102     num_drv   = num_deurv - count_relax_dr;
1103     break;
1104   case RELAXED_UNCERTAIN:
1105     // skip over the design variables
1106     offset = num_ddiv;
1107     for (i=0; i<offset; ++i)
1108       if (allRelaxedDiscreteInt[i])        ++start_relax_di;
1109     for (i=0; i<num_dauiv+num_deuiv; ++i)
1110       if (allRelaxedDiscreteInt[offset+i]) ++count_relax_di;
1111     offset = num_ddrv;
1112     for (i=0; i<offset; ++i)
1113       if (allRelaxedDiscreteReal[i])        ++start_relax_dr;
1114     for (i=0; i<num_daurv+num_deurv; ++i)
1115       if (allRelaxedDiscreteReal[offset+i]) ++count_relax_dr;
1116     cv_start  = num_cdv   + start_relax_di + start_relax_dr;
1117     div_start = num_ddiv  - start_relax_di;
1118     dsv_start = num_ddsv;
1119     drv_start = num_ddrv  - start_relax_dr;
1120     num_cv    = num_cauv  + num_ceuv  + count_relax_di + count_relax_dr;
1121     num_div   = num_dauiv + num_deuiv - count_relax_di;
1122     num_dsv   = num_dausv + num_deusv;
1123     num_drv   = num_daurv + num_deurv - count_relax_dr;
1124     break;
1125   case RELAXED_STATE:
1126     // skip over the design and uncertain variables
1127     offset = num_ddiv + num_dauiv + num_deuiv;
1128     for (i=0; i<offset; ++i)
1129       if (allRelaxedDiscreteInt[i])        ++start_relax_di;
1130     for (i=0; i<num_dsiv; ++i)
1131       if (allRelaxedDiscreteInt[offset+i]) ++count_relax_di;
1132     offset = num_ddrv + num_daurv + num_deurv;
1133     for (i=0; i<offset; ++i)
1134       if (allRelaxedDiscreteReal[i])        ++start_relax_dr;
1135     for (i=0; i<num_dsrv; ++i)
1136       if (allRelaxedDiscreteReal[offset+i]) ++count_relax_dr;
1137     cv_start  = num_cdv + num_cauv + num_ceuv + start_relax_di + start_relax_dr;
1138     div_start = num_ddiv + num_dauiv + num_deuiv - start_relax_di;
1139     dsv_start = num_ddsv + num_dausv + num_deusv;
1140     drv_start = num_ddrv + num_daurv + num_deurv - start_relax_dr;
1141     num_cv    = num_csv  + count_relax_di + count_relax_dr;
1142     num_div   = num_dsiv - count_relax_di;
1143     num_dsv   = num_dssv;
1144     num_drv   = num_dsrv - count_relax_dr;
1145     break;
1146   }
1147 }
1148 
1149 
initialize_active_components()1150 void SharedVariablesDataRep::initialize_active_components()
1151 {
1152   switch (variablesView.first) {
1153   case MIXED_ALL:                 case RELAXED_ALL:
1154     activeVarsCompsTotals = variablesCompsTotals; break;
1155   case MIXED_DESIGN:              case RELAXED_DESIGN:
1156     activeVarsCompsTotals.assign(NUM_VC_TOTALS, 0);
1157     activeVarsCompsTotals[TOTAL_CDV]  = variablesCompsTotals[TOTAL_CDV];
1158     activeVarsCompsTotals[TOTAL_DDIV] = variablesCompsTotals[TOTAL_DDIV];
1159     activeVarsCompsTotals[TOTAL_DDSV] = variablesCompsTotals[TOTAL_DDSV];
1160     activeVarsCompsTotals[TOTAL_DDRV] = variablesCompsTotals[TOTAL_DDRV];
1161     break;
1162   case MIXED_ALEATORY_UNCERTAIN:  case RELAXED_ALEATORY_UNCERTAIN:
1163     activeVarsCompsTotals.assign(NUM_VC_TOTALS, 0);
1164     activeVarsCompsTotals[TOTAL_CAUV]  = variablesCompsTotals[TOTAL_CAUV];
1165     activeVarsCompsTotals[TOTAL_DAUIV] = variablesCompsTotals[TOTAL_DAUIV];
1166     activeVarsCompsTotals[TOTAL_DAUSV] = variablesCompsTotals[TOTAL_DAUSV];
1167     activeVarsCompsTotals[TOTAL_DAURV] = variablesCompsTotals[TOTAL_DAURV];
1168     break;
1169   case MIXED_EPISTEMIC_UNCERTAIN: case RELAXED_EPISTEMIC_UNCERTAIN:
1170     activeVarsCompsTotals.assign(NUM_VC_TOTALS, 0);
1171     activeVarsCompsTotals[TOTAL_CEUV]  = variablesCompsTotals[TOTAL_CEUV];
1172     activeVarsCompsTotals[TOTAL_DEUIV] = variablesCompsTotals[TOTAL_DEUIV];
1173     activeVarsCompsTotals[TOTAL_DEUSV] = variablesCompsTotals[TOTAL_DEUSV];
1174     activeVarsCompsTotals[TOTAL_DEURV] = variablesCompsTotals[TOTAL_DEURV];
1175     break;
1176   case MIXED_UNCERTAIN:           case RELAXED_UNCERTAIN:
1177     activeVarsCompsTotals.assign(NUM_VC_TOTALS, 0);
1178     activeVarsCompsTotals[TOTAL_CAUV]  = variablesCompsTotals[TOTAL_CAUV];
1179     activeVarsCompsTotals[TOTAL_DAUIV] = variablesCompsTotals[TOTAL_DAUIV];
1180     activeVarsCompsTotals[TOTAL_DAUSV] = variablesCompsTotals[TOTAL_DAUSV];
1181     activeVarsCompsTotals[TOTAL_DAURV] = variablesCompsTotals[TOTAL_DAURV];
1182     activeVarsCompsTotals[TOTAL_CEUV]  = variablesCompsTotals[TOTAL_CEUV];
1183     activeVarsCompsTotals[TOTAL_DEUIV] = variablesCompsTotals[TOTAL_DEUIV];
1184     activeVarsCompsTotals[TOTAL_DEUSV] = variablesCompsTotals[TOTAL_DEUSV];
1185     activeVarsCompsTotals[TOTAL_DEURV] = variablesCompsTotals[TOTAL_DEURV];
1186     break;
1187   case MIXED_STATE:               case RELAXED_STATE:
1188     activeVarsCompsTotals.assign(NUM_VC_TOTALS, 0);
1189     activeVarsCompsTotals[TOTAL_CSV]  = variablesCompsTotals[TOTAL_CSV];
1190     activeVarsCompsTotals[TOTAL_DSIV] = variablesCompsTotals[TOTAL_DSIV];
1191     activeVarsCompsTotals[TOTAL_DSSV] = variablesCompsTotals[TOTAL_DSSV];
1192     activeVarsCompsTotals[TOTAL_DSRV] = variablesCompsTotals[TOTAL_DSRV];
1193     break;
1194   default:
1195     // if active view unassigned, error
1196     Cerr << "Error: missing active view in SharedVariablesDataRep::"
1197 	 << "initialize_active_components()" << std::endl;
1198     abort_handler(-1);
1199     break;
1200   }
1201 
1202   /* This logic is insufficient for RelaxedVariables
1203 
1204   size_t i, j,
1205     cv_end    = cvStart  + numCV,  div_end = divStart + numDIV,
1206     dsv_end   = dsvStart + numDSV, drv_end = drvStart + numDRV,
1207     acv_cntr = 0, adiv_cntr = 0, adsv_cntr = 0, adrv_cntr = 0;
1208 
1209   // design
1210   activeVarsCompsTotals[TOTAL_CDV]
1211     = (acv_cntr  >=  cvStart &&  acv_cntr <  cv_end) ? num_cdv  : 0;
1212   activeVarsCompsTotals[TOTAL_DDIV]
1213     = (adiv_cntr >= divStart && adiv_cntr < div_end) ? num_ddiv : 0;
1214   activeVarsCompsTotals[TOTAL_DDSV]
1215     = (adsv_cntr >= dsvStart && adsv_cntr < dsv_end) ? num_ddsv : 0;
1216   activeVarsCompsTotals[TOTAL_DDRV]
1217     = (adrv_cntr >= drvStart && adrv_cntr < drv_end) ? num_ddrv : 0;
1218   acv_cntr  += num_cdv;  adiv_cntr += num_ddiv;
1219   adsv_cntr += num_ddsv; adrv_cntr += num_ddrv;
1220   // aleatory uncertain
1221   activeVarsCompsTotals[TOTAL_CAUV]
1222     = (acv_cntr  >=  cvStart &&  acv_cntr <  cv_end) ? num_cauv  : 0;
1223   activeVarsCompsTotals[TOTAL_DAUIV]
1224     = (adiv_cntr >= divStart && adiv_cntr < div_end) ? num_dauiv : 0;
1225   activeVarsCompsTotals[TOTAL_DAUSV]
1226     = (adsv_cntr >= dsvStart && adsv_cntr < dsv_end) ? num_dausv : 0;
1227   activeVarsCompsTotals[TOTAL_DAURV]
1228     = (adrv_cntr >= drvStart && adrv_cntr < drv_end) ? num_daurv : 0;
1229   acv_cntr  += num_cauv;  adiv_cntr += num_dauiv;
1230   adsv_cntr += num_dausv; adrv_cntr += num_daurv;
1231   // epistemic uncertain
1232   activeVarsCompsTotals[TOTAL_CEUV]
1233     = (acv_cntr  >=  cvStart &&  acv_cntr <  cv_end) ? num_ceuv  : 0;
1234   activeVarsCompsTotals[TOTAL_DEUIV]
1235     = (adiv_cntr >= divStart && adiv_cntr < div_end) ? num_deuiv : 0;
1236   activeVarsCompsTotals[TOTAL_DEUSV]
1237     = (adsv_cntr >= dsvStart && adsv_cntr < dsv_end) ? num_deusv : 0;
1238   activeVarsCompsTotals[TOTAL_DEURV]
1239     = (adrv_cntr >= drvStart && adrv_cntr < drv_end) ? num_deurv : 0;
1240   acv_cntr  += num_ceuv;  adiv_cntr += num_deuiv;
1241   adsv_cntr += num_deusv; adrv_cntr += num_deurv;
1242   // state
1243   activeVarsCompsTotals[TOTAL_CSV]
1244     = (acv_cntr  >=  cvStart &&  acv_cntr <  cv_end) ? num_csv  : 0;
1245   activeVarsCompsTotals[TOTAL_DSIV]
1246     = (adiv_cntr >= divStart && adiv_cntr < div_end) ? num_dsiv : 0;
1247   activeVarsCompsTotals[TOTAL_DSSV]
1248     = (adsv_cntr >= dsvStart && adsv_cntr < dsv_end) ? num_dssv : 0;
1249   activeVarsCompsTotals[TOTAL_DSRV]
1250     = (adrv_cntr >= drvStart && adrv_cntr < drv_end) ? num_dsrv : 0;
1251   //acv_cntr  += num_csv;  adiv_cntr += num_dsiv;
1252   //adsv_cntr += num_dssv; adrv_cntr += num_dsrv;
1253   */
1254 }
1255 
1256 
initialize_inactive_components()1257 void SharedVariablesDataRep::initialize_inactive_components()
1258 {
1259   inactiveVarsCompsTotals.assign(NUM_VC_TOTALS, 0);
1260 
1261   switch (variablesView.second) {
1262   case MIXED_ALL:                 case RELAXED_ALL:
1263     Cerr << "Error: inactive view cannot be ALL in SharedVariablesDataRep::"
1264 	 << "initialize_inactive_components()" << std::endl;
1265     abort_handler(-1);
1266     //inactiveVarsCompsTotals = variablesCompsTotals;
1267     break;
1268   case MIXED_DESIGN:              case RELAXED_DESIGN:
1269     inactiveVarsCompsTotals[TOTAL_CDV]  = variablesCompsTotals[TOTAL_CDV];
1270     inactiveVarsCompsTotals[TOTAL_DDIV] = variablesCompsTotals[TOTAL_DDIV];
1271     inactiveVarsCompsTotals[TOTAL_DDSV] = variablesCompsTotals[TOTAL_DDSV];
1272     inactiveVarsCompsTotals[TOTAL_DDRV] = variablesCompsTotals[TOTAL_DDRV];
1273     break;
1274   case MIXED_ALEATORY_UNCERTAIN:  case RELAXED_ALEATORY_UNCERTAIN:
1275     inactiveVarsCompsTotals[TOTAL_CAUV]  = variablesCompsTotals[TOTAL_CAUV];
1276     inactiveVarsCompsTotals[TOTAL_DAUIV] = variablesCompsTotals[TOTAL_DAUIV];
1277     inactiveVarsCompsTotals[TOTAL_DAUSV] = variablesCompsTotals[TOTAL_DAUSV];
1278     inactiveVarsCompsTotals[TOTAL_DAURV] = variablesCompsTotals[TOTAL_DAURV];
1279     break;
1280   case MIXED_EPISTEMIC_UNCERTAIN: case RELAXED_EPISTEMIC_UNCERTAIN:
1281     inactiveVarsCompsTotals[TOTAL_CEUV]  = variablesCompsTotals[TOTAL_CEUV];
1282     inactiveVarsCompsTotals[TOTAL_DEUIV] = variablesCompsTotals[TOTAL_DEUIV];
1283     inactiveVarsCompsTotals[TOTAL_DEUSV] = variablesCompsTotals[TOTAL_DEUSV];
1284     inactiveVarsCompsTotals[TOTAL_DEURV] = variablesCompsTotals[TOTAL_DEURV];
1285     break;
1286   case MIXED_UNCERTAIN:           case RELAXED_UNCERTAIN:
1287     inactiveVarsCompsTotals[TOTAL_CAUV]  = variablesCompsTotals[TOTAL_CAUV];
1288     inactiveVarsCompsTotals[TOTAL_DAUIV] = variablesCompsTotals[TOTAL_DAUIV];
1289     inactiveVarsCompsTotals[TOTAL_DAUSV] = variablesCompsTotals[TOTAL_DAUSV];
1290     inactiveVarsCompsTotals[TOTAL_DAURV] = variablesCompsTotals[TOTAL_DAURV];
1291     inactiveVarsCompsTotals[TOTAL_CEUV]  = variablesCompsTotals[TOTAL_CEUV];
1292     inactiveVarsCompsTotals[TOTAL_DEUIV] = variablesCompsTotals[TOTAL_DEUIV];
1293     inactiveVarsCompsTotals[TOTAL_DEUSV] = variablesCompsTotals[TOTAL_DEUSV];
1294     inactiveVarsCompsTotals[TOTAL_DEURV] = variablesCompsTotals[TOTAL_DEURV];
1295     break;
1296   case MIXED_STATE:               case RELAXED_STATE:
1297     inactiveVarsCompsTotals[TOTAL_CSV]  = variablesCompsTotals[TOTAL_CSV];
1298     inactiveVarsCompsTotals[TOTAL_DSIV] = variablesCompsTotals[TOTAL_DSIV];
1299     inactiveVarsCompsTotals[TOTAL_DSSV] = variablesCompsTotals[TOTAL_DSSV];
1300     inactiveVarsCompsTotals[TOTAL_DSRV] = variablesCompsTotals[TOTAL_DSRV];
1301     break;
1302   //default: if inactive view unassigned, leave comp totals initialized to 0
1303   }
1304 
1305   /* This logic is insufficient for RelaxedVariables
1306 
1307   size_t i, j,
1308     icv_end   = icvStart  + numICV,  idiv_end = idivStart + numIDIV,
1309     idsv_end  = idsvStart + numIDSV, idrv_end = idrvStart + numIDRV,
1310     acv_cntr = 0, adiv_cntr = 0, adsv_cntr = 0, adrv_cntr = 0;
1311 
1312   // design
1313   inactiveVarsCompsTotals[TOTAL_CDV]
1314     = (acv_cntr  >=  icvStart &&  acv_cntr <  icv_end) ? num_cdv  : 0;
1315   inactiveVarsCompsTotals[TOTAL_DDIV]
1316     = (adiv_cntr >= idivStart && adiv_cntr < idiv_end) ? num_ddiv : 0;
1317   inactiveVarsCompsTotals[TOTAL_DDSV]
1318     = (adsv_cntr >= idsvStart && adsv_cntr < idsv_end) ? num_ddsv : 0;
1319   inactiveVarsCompsTotals[TOTAL_DDRV]
1320     = (adrv_cntr >= idrvStart && adrv_cntr < idrv_end) ? num_ddrv : 0;
1321   acv_cntr  += num_cdv;  adiv_cntr += num_ddiv;
1322   adsv_cntr += num_ddsv; adrv_cntr += num_ddrv;
1323   // aleatory uncertain
1324   inactiveVarsCompsTotals[TOTAL_CAUV]
1325     = (acv_cntr  >=  icvStart &&  acv_cntr <  icv_end) ? num_cauv  : 0;
1326   inactiveVarsCompsTotals[TOTAL_DAUIV]
1327     = (adiv_cntr >= idivStart && adiv_cntr < idiv_end) ? num_dauiv : 0;
1328   inactiveVarsCompsTotals[TOTAL_DAUSV]
1329     = (adsv_cntr >= idsvStart && adsv_cntr < idsv_end) ? num_dausv : 0;
1330   inactiveVarsCompsTotals[TOTAL_DAURV]
1331     = (adrv_cntr >= idrvStart && adrv_cntr < idrv_end) ? num_daurv : 0;
1332   acv_cntr  += num_cauv;  adiv_cntr += num_dauiv;
1333   adsv_cntr += num_dausv; adrv_cntr += num_daurv;
1334   // epistemic uncertain
1335   inactiveVarsCompsTotals[TOTAL_CEUV]
1336     = (acv_cntr  >=  icvStart &&  acv_cntr <  icv_end) ? num_ceuv  : 0;
1337   inactiveVarsCompsTotals[TOTAL_DEUIV]
1338     = (adiv_cntr >= idivStart && adiv_cntr < idiv_end) ? num_deuiv : 0;
1339   inactiveVarsCompsTotals[TOTAL_DEUSV]
1340     = (adsv_cntr >= idsvStart && adsv_cntr < idsv_end) ? num_deusv : 0;
1341   inactiveVarsCompsTotals[TOTAL_DEURV]
1342     = (adrv_cntr >= idrvStart && adrv_cntr < idrv_end) ? num_deurv : 0;
1343   acv_cntr  += num_ceuv;  adiv_cntr += num_deuiv;
1344   adsv_cntr += num_deusv; adrv_cntr += num_deurv;
1345   // state
1346   inactiveVarsCompsTotals[TOTAL_CSV]
1347     = (acv_cntr  >=  icvStart &&  acv_cntr <  icv_end) ? num_csv  : 0;
1348   inactiveVarsCompsTotals[TOTAL_DSIV]
1349     = (adiv_cntr >= idivStart && adiv_cntr < idiv_end) ? num_dsiv : 0;
1350   inactiveVarsCompsTotals[TOTAL_DSSV]
1351     = (adsv_cntr >= idsvStart && adsv_cntr < idsv_end) ? num_dssv : 0;
1352   inactiveVarsCompsTotals[TOTAL_DSRV]
1353     = (adrv_cntr >= idrvStart && adrv_cntr < idrv_end) ? num_dsrv : 0;
1354   //acv_cntr  += num_csv;  adiv_cntr += num_dsiv;
1355   //adsv_cntr += num_dssv; adrv_cntr += num_dsrv;
1356   */
1357 }
1358 
1359 
1360 /** Deep copies are used when recasting changes the nature of a
1361     Variables set. */
copy_rep(SharedVariablesDataRep * svd_rep)1362 void SharedVariablesDataRep::copy_rep(SharedVariablesDataRep* svd_rep)
1363 {
1364   variablesId             = svd_rep->variablesId;
1365   variablesComponents     = svd_rep->variablesComponents;
1366   variablesCompsTotals    = svd_rep->variablesCompsTotals;
1367   activeVarsCompsTotals   = svd_rep->activeVarsCompsTotals;
1368   inactiveVarsCompsTotals = svd_rep->inactiveVarsCompsTotals;
1369   variablesView           = svd_rep->variablesView;
1370 
1371   cvStart   = svd_rep->cvStart;   numCV   = svd_rep->numCV;
1372   divStart  = svd_rep->divStart;  numDIV  = svd_rep->numDIV;
1373   dsvStart  = svd_rep->dsvStart;  numDSV  = svd_rep->numDSV;
1374   drvStart  = svd_rep->drvStart;  numDRV  = svd_rep->numDRV;
1375   icvStart  = svd_rep->icvStart;  numICV  = svd_rep->numICV;
1376   idivStart = svd_rep->idivStart; numIDIV = svd_rep->numIDIV;
1377   idsvStart = svd_rep->idsvStart; numIDSV = svd_rep->numIDSV;
1378   idrvStart = svd_rep->idrvStart; numIDRV = svd_rep->numIDRV;
1379 
1380   // Boost MultiArrays must be resized prior to operator= assignment
1381   size_t num_acv  = svd_rep->allContinuousLabels.size(),
1382          num_adiv = svd_rep->allDiscreteIntLabels.size(),
1383          num_adsv = svd_rep->allDiscreteStringLabels.size(),
1384          num_adrv = svd_rep->allDiscreteRealLabels.size();
1385 
1386   allContinuousLabels.resize(boost::extents[num_acv]);
1387   allContinuousLabels = svd_rep->allContinuousLabels;
1388   allDiscreteIntLabels.resize(boost::extents[num_adiv]);
1389   allDiscreteIntLabels = svd_rep->allDiscreteIntLabels;
1390   allDiscreteStringLabels.resize(boost::extents[num_adsv]);
1391   allDiscreteStringLabels = svd_rep->allDiscreteStringLabels;
1392   allDiscreteRealLabels.resize(boost::extents[num_adrv]);
1393   allDiscreteRealLabels = svd_rep->allDiscreteRealLabels;
1394 
1395   allContinuousTypes.resize(boost::extents[num_acv]);
1396   allContinuousTypes = svd_rep->allContinuousTypes;
1397   allDiscreteIntTypes.resize(boost::extents[num_adiv]);
1398   allDiscreteIntTypes = svd_rep->allDiscreteIntTypes;
1399   allDiscreteStringTypes.resize(boost::extents[num_adsv]);
1400   allDiscreteStringTypes = svd_rep->allDiscreteStringTypes;
1401   allDiscreteRealTypes.resize(boost::extents[num_adrv]);
1402   allDiscreteRealTypes = svd_rep->allDiscreteRealTypes;
1403 
1404   allContinuousIds.resize(boost::extents[num_acv]);
1405   allContinuousIds = svd_rep->allContinuousIds;
1406   allDiscreteIntIds.resize(boost::extents[num_adiv]);
1407   allDiscreteIntIds = svd_rep->allDiscreteIntIds;
1408   allDiscreteStringIds.resize(boost::extents[num_adsv]);
1409   allDiscreteStringIds = svd_rep->allDiscreteStringIds;
1410   allDiscreteRealIds.resize(boost::extents[num_adrv]);
1411   allDiscreteRealIds = svd_rep->allDiscreteRealIds;
1412 
1413   allRelaxedDiscreteInt  = svd_rep->allRelaxedDiscreteInt;
1414   allRelaxedDiscreteReal = svd_rep->allRelaxedDiscreteReal;
1415 }
1416 
1417 
1418 size_t SharedVariablesDataRep::
cv_index_to_all_index(size_t cv_index,bool cdv,bool cauv,bool ceuv,bool csv) const1419 cv_index_to_all_index(size_t cv_index,
1420 		      bool cdv, bool cauv, bool ceuv, bool csv) const
1421 {
1422   // *** TO DO: a mapping from CV to spec order must account for individual
1423   //            var relaxation indices, not just the aggregate counts
1424 
1425   size_t offset = 0, bound = 0, num_cv, num_div, num_dsv, num_drv;
1426   design_counts(num_cv, num_div, num_dsv, num_drv); // w/ relaxed
1427   if (cdv) {
1428     bound += num_cv;
1429     if (cv_index < bound)
1430       return offset + cv_index;
1431   }
1432   else
1433     offset += num_cv;
1434   offset += num_div + num_dsv + num_drv;
1435 
1436   aleatory_uncertain_counts(num_cv, num_div, num_dsv, num_drv);
1437   if (cauv) {
1438     bound += num_cv;
1439     if (cv_index < bound)
1440       return offset + cv_index;
1441   }
1442   else
1443     offset += num_cv;
1444   offset += num_div + num_dsv + num_drv;
1445 
1446   epistemic_uncertain_counts(num_cv, num_div, num_dsv, num_drv);
1447   if (ceuv) {
1448     bound += num_cv;
1449     if (cv_index < bound)
1450       return offset + cv_index;
1451   }
1452   else
1453     offset += num_cv;
1454   offset += num_div + num_dsv + num_drv;
1455 
1456   state_counts(num_cv, num_div, num_dsv, num_drv);
1457   if (csv) {
1458     bound += num_cv;
1459     if (cv_index < bound)
1460       return offset + cv_index;
1461   }
1462   //else
1463   //  offset += num_cv;
1464   //offset += num_div + num_dsv + num_drv;
1465 
1466   Cerr << "Error: CV index out of range in SharedVariablesDataRep::"
1467        << "cv_index_to_all_index()" << std::endl;
1468   abort_handler(VARS_ERROR);
1469   return _NPOS;
1470 }
1471 
1472 
1473 size_t SharedVariablesDataRep::
div_index_to_all_index(size_t div_index,bool ddv,bool dauv,bool deuv,bool dsv) const1474 div_index_to_all_index(size_t div_index,
1475 		       bool ddv, bool dauv, bool deuv, bool dsv) const
1476 {
1477   // *** TO DO: a mapping from DIV to spec order must account for individual
1478   //            var relaxation indices, not just the aggregate counts
1479 
1480   size_t num_cv, num_div, num_dsv, num_drv;
1481   design_counts(num_cv, num_div, num_dsv, num_drv); // w/ relaxed
1482   size_t bound = 0, offset = num_cv;
1483   if (ddv) {
1484     bound += num_div;
1485     if (div_index < bound)
1486       return offset + div_index;
1487   }
1488   else
1489     offset += num_div;
1490   offset += num_dsv + num_drv;
1491 
1492   aleatory_uncertain_counts(num_cv, num_div, num_dsv, num_drv);
1493   offset += num_cv;
1494   if (dauv) {
1495     bound += num_div;
1496     if (div_index < bound)
1497       return offset + div_index;
1498   }
1499   else
1500     offset += num_div;
1501   offset += num_dsv + num_drv;
1502 
1503   epistemic_uncertain_counts(num_cv, num_div, num_dsv, num_drv);
1504   offset += num_cv;
1505   if (deuv) {
1506     bound += num_div;
1507     if (div_index < bound)
1508       return offset + div_index;
1509   }
1510   else
1511     offset += num_div;
1512   offset += num_dsv + num_drv;
1513 
1514   state_counts(num_cv, num_div, num_dsv, num_drv);
1515   offset += num_cv;
1516   if (dsv) {
1517     bound += num_div;
1518     if (div_index < bound)
1519       return offset + div_index;
1520   }
1521   //else
1522   //  offset += num_div;
1523   //offset += num_dsv + num_drv;
1524 
1525   Cerr << "Error: DIV index out of range in SharedVariablesDataRep::"
1526        << "div_index_to_all_index()" << std::endl;
1527   abort_handler(VARS_ERROR);
1528   return _NPOS;
1529 }
1530 
1531 
1532 size_t SharedVariablesDataRep::
dsv_index_to_all_index(size_t dsv_index,bool ddv,bool dauv,bool deuv,bool dsv) const1533 dsv_index_to_all_index(size_t dsv_index,
1534 		       bool ddv, bool dauv, bool deuv, bool dsv) const
1535 {
1536   // *** TO DO: a mapping from DSV to spec order must account for individual
1537   //            var relaxation indices, not just the aggregate counts
1538 
1539   size_t num_cv, num_div, num_dsv, num_drv;
1540   design_counts(num_cv, num_div, num_dsv, num_drv); // w/ relaxed
1541   size_t bound = 0, offset = num_cv + num_div;
1542   if (ddv) {
1543     bound += num_dsv;
1544     if (dsv_index < bound)
1545       return offset + dsv_index;
1546   }
1547   else
1548     offset += num_dsv;
1549   offset += num_drv;
1550 
1551   aleatory_uncertain_counts(num_cv, num_div, num_dsv, num_drv);
1552   offset += num_cv + num_div;
1553   if (dauv) {
1554     bound += num_dsv;
1555     if (dsv_index < bound)
1556       return offset + dsv_index;
1557   }
1558   else
1559     offset += num_dsv;
1560   offset += num_drv;
1561 
1562   epistemic_uncertain_counts(num_cv, num_div, num_dsv, num_drv);
1563   offset += num_cv + num_div;
1564   if (deuv) {
1565     bound += num_dsv;
1566     if (dsv_index < bound)
1567       return offset + dsv_index;
1568   }
1569   else
1570     offset += num_dsv;
1571   offset += num_drv;
1572 
1573   state_counts(num_cv, num_div, num_dsv, num_drv);
1574   offset += num_cv + num_div;
1575   if (dsv) {
1576     bound += num_dsv;
1577     if (dsv_index < bound)
1578       return offset + dsv_index;
1579   }
1580   //else
1581   //  offset += num_dsv;
1582   //offset += num_drv;
1583 
1584   Cerr << "Error: DSV index out of range in SharedVariablesDataRep::"
1585        << "dsv_index_to_all_index()" << std::endl;
1586   abort_handler(VARS_ERROR);
1587   return _NPOS;
1588 }
1589 
1590 
1591 size_t SharedVariablesDataRep::
drv_index_to_all_index(size_t drv_index,bool ddv,bool dauv,bool deuv,bool dsv) const1592 drv_index_to_all_index(size_t drv_index,
1593 		       bool ddv, bool dauv, bool deuv, bool dsv) const
1594 {
1595   // *** TO DO: a mapping from DRV to spec order must account for individual
1596   //            var relaxation indices, not just the aggregate counts
1597 
1598   size_t num_cv, num_div, num_dsv, num_drv;
1599   design_counts(num_cv, num_div, num_dsv, num_drv); // w/ relaxed
1600   size_t bound = 0, offset = num_cv + num_div + num_dsv;
1601   if (ddv) {
1602     bound += num_drv;
1603     if (drv_index < bound)
1604       return offset + drv_index;
1605   }
1606   else
1607     offset += num_drv;
1608 
1609   aleatory_uncertain_counts(num_cv, num_div, num_dsv, num_drv);
1610   offset += num_cv + num_div + num_dsv;
1611   if (dauv) {
1612     bound += num_drv;
1613     if (drv_index < bound)
1614       return offset + drv_index;
1615   }
1616   else
1617     offset += num_drv;
1618 
1619   epistemic_uncertain_counts(num_cv, num_div, num_dsv, num_drv);
1620   offset += num_cv + num_div + num_dsv;
1621   if (deuv) {
1622     bound += num_drv;
1623     if (drv_index < bound)
1624       return offset + drv_index;
1625   }
1626   else
1627     offset += num_drv;
1628 
1629   state_counts(num_cv, num_div, num_dsv, num_drv);
1630   offset += num_cv + num_div + num_dsv;
1631   if (dsv) {
1632     bound += num_drv;
1633     if (drv_index < bound)
1634       return offset + drv_index;
1635   }
1636   //else
1637   //  offset += num_drv;
1638 
1639   Cerr << "Error: DRV index out of range in SharedVariablesDataRep::"
1640        << "drv_index_to_all_index()" << std::endl;
1641   abort_handler(VARS_ERROR);
1642   return _NPOS;
1643 }
1644 
1645 
1646 BitArray SharedVariablesDataRep::
cv_to_all_mask(bool cdv,bool cauv,bool ceuv,bool csv) const1647 cv_to_all_mask(bool cdv, bool cauv, bool ceuv, bool csv) const
1648 {
1649   size_t num_cv, num_div, num_dsv, num_drv;
1650   all_counts(num_cv, num_div, num_dsv, num_drv);
1651   BitArray all_mask(num_cv + num_div + num_dsv + num_drv); // init bits to false
1652 
1653   design_counts(num_cv, num_div, num_dsv, num_drv); // w/ relaxed
1654   size_t i, all_index = 0;
1655   if (cdv)
1656     for (i=0; i<num_cv; ++i, ++all_index)
1657       all_mask.set(all_index);
1658   else
1659     all_index += num_cv;
1660   all_index += num_div + num_dsv + num_drv;
1661 
1662   aleatory_uncertain_counts(num_cv, num_div, num_dsv, num_drv);
1663   if (cauv)
1664     for (i=0; i<num_cv; ++i, ++all_index)
1665       all_mask.set(all_index);
1666   else
1667     all_index += num_cv;
1668   all_index += num_div + num_dsv + num_drv;
1669 
1670   epistemic_uncertain_counts(num_cv, num_div, num_dsv, num_drv);
1671   if (ceuv)
1672     for (i=0; i<num_cv; ++i, ++all_index)
1673       all_mask.set(all_index);
1674   else
1675     all_index += num_cv;
1676   all_index += num_div + num_dsv + num_drv;
1677 
1678   state_counts(num_cv, num_div, num_dsv, num_drv);
1679   if (csv)
1680     for (i=0; i<num_cv; ++i, ++all_index)
1681       all_mask.set(all_index);
1682   //else
1683   //  all_index += num_cv;
1684   //all_index += num_div + num_dsv + num_drv;
1685 
1686   return all_mask;
1687 }
1688 
1689 
1690 BitArray SharedVariablesDataRep::
div_to_all_mask(bool ddv,bool dauv,bool deuv,bool dsv) const1691 div_to_all_mask(bool ddv, bool dauv, bool deuv, bool dsv) const
1692 {
1693   size_t num_cv, num_div, num_dsv, num_drv;
1694   all_counts(num_cv, num_div, num_dsv, num_drv);
1695   BitArray all_mask(num_cv + num_div + num_dsv + num_drv); // init bits to false
1696 
1697   design_counts(num_cv, num_div, num_dsv, num_drv); // w/ relaxed
1698   size_t i, all_index = num_cv;
1699   if (ddv)
1700     for (i=0; i<num_div; ++i, ++all_index)
1701       all_mask.set(all_index);
1702   else
1703     all_index += num_div;
1704   all_index += num_dsv + num_drv;
1705 
1706   aleatory_uncertain_counts(num_cv, num_div, num_dsv, num_drv);
1707   all_index += num_cv;
1708   if (dauv)
1709     for (i=0; i<num_div; ++i, ++all_index)
1710       all_mask.set(all_index);
1711   else
1712     all_index += num_div;
1713   all_index += num_dsv + num_drv;
1714 
1715   epistemic_uncertain_counts(num_cv, num_div, num_dsv, num_drv);
1716   all_index += num_cv;
1717   if (deuv)
1718     for (i=0; i<num_div; ++i, ++all_index)
1719       all_mask.set(all_index);
1720   else
1721     all_index += num_div;
1722   all_index += num_dsv + num_drv;
1723 
1724   state_counts(num_cv, num_div, num_dsv, num_drv);
1725   all_index += num_cv;
1726   if (dsv)
1727     for (i=0; i<num_div; ++i, ++all_index)
1728       all_mask.set(all_index);
1729   //else
1730   //  all_index += num_div;
1731   //all_index += num_dsv + num_drv;
1732 
1733   return all_mask;
1734 }
1735 
1736 
1737 BitArray SharedVariablesDataRep::
dsv_to_all_mask(bool ddv,bool dauv,bool deuv,bool dsv) const1738 dsv_to_all_mask(bool ddv, bool dauv, bool deuv, bool dsv) const
1739 {
1740   size_t num_cv, num_div, num_dsv, num_drv;
1741   all_counts(num_cv, num_div, num_dsv, num_drv);
1742   BitArray all_mask(num_cv + num_div + num_dsv + num_drv); // init bits to false
1743 
1744   design_counts(num_cv, num_div, num_dsv, num_drv); // w/ relaxed
1745   size_t i, all_index = num_cv + num_div;
1746   if (ddv)
1747     for (i=0; i<num_dsv; ++i, ++all_index)
1748       all_mask.set(all_index);
1749   else
1750     all_index += num_dsv;
1751   all_index += num_drv;
1752 
1753   aleatory_uncertain_counts(num_cv, num_div, num_dsv, num_drv);
1754   all_index += num_cv + num_div;
1755   if (dauv)
1756     for (i=0; i<num_dsv; ++i, ++all_index)
1757       all_mask.set(all_index);
1758   else
1759     all_index += num_dsv;
1760   all_index += num_drv;
1761 
1762   epistemic_uncertain_counts(num_cv, num_div, num_dsv, num_drv);
1763   all_index += num_cv + num_div;
1764   if (deuv)
1765     for (i=0; i<num_dsv; ++i, ++all_index)
1766       all_mask.set(all_index);
1767   else
1768     all_index += num_dsv;
1769   all_index += num_drv;
1770 
1771   state_counts(num_cv, num_div, num_dsv, num_drv);
1772   all_index += num_cv + num_div;
1773   if (dsv)
1774     for (i=0; i<num_dsv; ++i, ++all_index)
1775       all_mask.set(all_index);
1776   //else
1777   //  all_index += num_dsv;
1778   //all_index += num_drv;
1779 
1780   return all_mask;
1781 }
1782 
1783 
1784 BitArray SharedVariablesDataRep::
drv_to_all_mask(bool ddv,bool dauv,bool deuv,bool dsv) const1785 drv_to_all_mask(bool ddv, bool dauv, bool deuv, bool dsv) const
1786 {
1787   size_t num_cv, num_div, num_dsv, num_drv;
1788   all_counts(num_cv, num_div, num_dsv, num_drv);
1789   BitArray all_mask(num_cv + num_div + num_dsv + num_drv); // init bits to false
1790 
1791   design_counts(num_cv, num_div, num_dsv, num_drv); // w/ relaxed
1792   size_t i, all_index = num_cv + num_div + num_dsv;
1793   if (ddv)
1794     for (i=0; i<num_drv; ++i, ++all_index)
1795       all_mask.set(all_index);
1796   else
1797     all_index += num_drv;
1798 
1799   aleatory_uncertain_counts(num_cv, num_div, num_dsv, num_drv);
1800   all_index += num_cv + num_div + num_dsv;
1801   if (dauv)
1802     for (i=0; i<num_drv; ++i, ++all_index)
1803       all_mask.set(all_index);
1804   else
1805     all_index += num_drv;
1806 
1807   epistemic_uncertain_counts(num_cv, num_div, num_dsv, num_drv);
1808   all_index += num_cv + num_div + num_dsv;
1809   if (deuv)
1810     for (i=0; i<num_drv; ++i, ++all_index)
1811       all_mask.set(all_index);
1812   else
1813     all_index += num_drv;
1814 
1815   state_counts(num_cv, num_div, num_dsv, num_drv);
1816   all_index += num_cv + num_div + num_dsv;
1817   if (dsv)
1818     for (i=0; i<num_drv; ++i, ++all_index)
1819       all_mask.set(all_index);
1820   //else
1821   //  all_index += num_drv;
1822 
1823   return all_mask;
1824 }
1825 
1826 
cv_index_to_active_index(size_t cv_index) const1827 size_t SharedVariablesData::cv_index_to_active_index(size_t cv_index) const
1828 {
1829   bool cdv, ddv, cauv, dauv, ceuv, deuv, csv, dsv;
1830   active_subsets(cdv, ddv, cauv, dauv, ceuv, deuv, csv, dsv);
1831 
1832   // This mapping is insensitive to var relaxation ADIV/ADRV -> ACV, as
1833   // source+target variable set orderings are impacted the same way
1834 
1835   size_t offset = 0, bound = 0, num_cv, num_div, num_dsv, num_drv;
1836   svdRep->design_counts(num_cv, num_div, num_dsv, num_drv); // w/ relaxed
1837   if (cdv) {
1838     bound += num_cv;
1839     if (cv_index < bound)
1840       return offset + cv_index;
1841   }
1842   if (ddv)
1843     offset += num_div + num_dsv + num_drv;
1844 
1845   svdRep->aleatory_uncertain_counts(num_cv, num_div, num_dsv, num_drv);
1846   if (cauv) {
1847     bound += num_cv;
1848     if (cv_index < bound)
1849       return offset + cv_index;
1850   }
1851   if (dauv)
1852     offset += num_div + num_dsv + num_drv;
1853 
1854   svdRep->epistemic_uncertain_counts(num_cv, num_div, num_dsv, num_drv);
1855   if (ceuv) {
1856     bound += num_cv;
1857     if (cv_index < bound)
1858       return offset + cv_index;
1859   }
1860   if (deuv)
1861     offset += num_div + num_dsv + num_drv;
1862 
1863   svdRep->state_counts(num_cv, num_div, num_dsv, num_drv);
1864   if (csv) {
1865     bound += num_cv;
1866     if (cv_index < bound)
1867       return offset + cv_index;
1868   }
1869 
1870   Cerr << "Error: CV index out of range in SharedVariablesData::"
1871        << "cv_index_to_active_index()" << std::endl;
1872   abort_handler(VARS_ERROR);
1873   return _NPOS;
1874 }
1875 
1876 
div_index_to_active_index(size_t div_index) const1877 size_t SharedVariablesData::div_index_to_active_index(size_t div_index) const
1878 {
1879   bool cdv, ddv, cauv, dauv, ceuv, deuv, csv, dsv;
1880   active_subsets(cdv, ddv, cauv, dauv, ceuv, deuv, csv, dsv);
1881 
1882   // This mapping is insensitive to var relaxation ADIV/ADRV -> ACV, as
1883   // source+target variable set orderings are impacted the same way
1884 
1885   size_t offset = 0, bound = 0, num_cv, num_div, num_dsv, num_drv;
1886   svdRep->design_counts(num_cv, num_div, num_dsv, num_drv); // w/ relaxed
1887   if (cdv)
1888     offset += num_cv;
1889   if (ddv) {
1890     bound += num_div;
1891     if (div_index < bound)
1892       return offset + div_index;
1893     offset += num_dsv + num_drv;
1894   }
1895 
1896   svdRep->aleatory_uncertain_counts(num_cv, num_div, num_dsv, num_drv);
1897   if (cauv)
1898     offset += num_cv;
1899   if (dauv) {
1900     bound += num_div;
1901     if (div_index < bound)
1902       return offset + div_index;
1903     offset += num_dsv + num_drv;
1904   }
1905 
1906   svdRep->epistemic_uncertain_counts(num_cv, num_div, num_dsv, num_drv);
1907   if (ceuv)
1908     offset += num_cv;
1909   if (deuv) {
1910     bound += num_div;
1911     if (div_index < bound)
1912       return offset + div_index;
1913     offset += num_dsv + num_drv;
1914   }
1915 
1916   svdRep->state_counts(num_cv, num_div, num_dsv, num_drv);
1917   if (csv)
1918     offset += num_cv;
1919   if (dsv) {
1920     bound += num_div;
1921     if (div_index < bound)
1922       return offset + div_index;
1923     //offset += num_dsv + num_drv;
1924   }
1925 
1926   Cerr << "Error: DIV index out of range in SharedVariablesData::"
1927        << "div_index_to_active_index()" << std::endl;
1928   abort_handler(VARS_ERROR);
1929   return _NPOS;
1930 }
1931 
1932 
dsv_index_to_active_index(size_t dsv_index) const1933 size_t SharedVariablesData::dsv_index_to_active_index(size_t dsv_index) const
1934 {
1935   bool cdv, ddv, cauv, dauv, ceuv, deuv, csv, dsv;
1936   active_subsets(cdv, ddv, cauv, dauv, ceuv, deuv, csv, dsv);
1937 
1938   // This mapping is insensitive to var relaxation ADIV/ADRV -> ACV, as
1939   // source+target variable set orderings are impacted the same way
1940 
1941   size_t offset = 0, bound = 0, num_cv, num_div, num_dsv, num_drv;
1942   svdRep->design_counts(num_cv, num_div, num_dsv, num_drv); // w/ relaxed
1943   if (cdv)
1944     offset += num_cv;
1945   if (ddv) {
1946     offset += num_div;  bound += num_dsv;
1947     if (dsv_index < bound)
1948       return offset + dsv_index;
1949     offset += num_drv;
1950   }
1951 
1952   svdRep->aleatory_uncertain_counts(num_cv, num_div, num_dsv, num_drv);
1953   if (cauv)
1954     offset += num_cv;
1955   if (dauv) {
1956     offset += num_div;  bound += num_dsv;
1957     if (dsv_index < bound)
1958       return offset + dsv_index;
1959     offset += num_drv;
1960   }
1961 
1962   svdRep->epistemic_uncertain_counts(num_cv, num_div, num_dsv, num_drv);
1963   if (ceuv)
1964     offset += num_cv;
1965   if (deuv) {
1966     offset += num_div;  bound += num_dsv;
1967     if (dsv_index < bound)
1968       return offset + dsv_index;
1969     offset += num_drv;
1970   }
1971 
1972   svdRep->state_counts(num_cv, num_div, num_dsv, num_drv);
1973   if (csv)
1974     offset += num_cv;
1975   if (dsv) {
1976     offset += num_div;  bound += num_dsv;
1977     if (dsv_index < bound)
1978       return offset + dsv_index;
1979     //offset += num_drv;
1980   }
1981 
1982   Cerr << "Error: DSV index out of range in SharedVariablesData::"
1983        << "dsv_index_to_active_index()" << std::endl;
1984   abort_handler(VARS_ERROR);
1985   return _NPOS;
1986 }
1987 
1988 
drv_index_to_active_index(size_t drv_index) const1989 size_t SharedVariablesData::drv_index_to_active_index(size_t drv_index) const
1990 {
1991   bool cdv, ddv, cauv, dauv, ceuv, deuv, csv, dsv;
1992   active_subsets(cdv, ddv, cauv, dauv, ceuv, deuv, csv, dsv);
1993 
1994   // This mapping is insensitive to var relaxation ADIV/ADRV -> ACV, as
1995   // source+target variable set orderings are impacted the same way
1996 
1997   size_t offset = 0, bound = 0, num_cv, num_div, num_dsv, num_drv;
1998   svdRep->design_counts(num_cv, num_div, num_dsv, num_drv); // w/ relaxed
1999   if (cdv)
2000     offset += num_cv;
2001   if (ddv) {
2002     offset += num_div + num_dsv;  bound += num_drv;
2003     if (drv_index < bound)
2004       return offset + drv_index;
2005   }
2006 
2007   svdRep->aleatory_uncertain_counts(num_cv, num_div, num_dsv, num_drv);
2008   if (cauv)
2009     offset += num_cv;
2010   if (dauv) {
2011     offset += num_div + num_dsv;  bound += num_drv;
2012     if (drv_index < bound)
2013       return offset + drv_index;
2014   }
2015 
2016   svdRep->epistemic_uncertain_counts(num_cv, num_div, num_dsv, num_drv);
2017   if (ceuv)
2018     offset += num_cv;
2019   if (deuv) {
2020     offset += num_div + num_dsv;  bound += num_drv;
2021     if (drv_index < bound)
2022       return offset + drv_index;
2023   }
2024 
2025   svdRep->state_counts(num_cv, num_div, num_dsv, num_drv);
2026   if (csv)
2027     offset += num_cv;
2028   if (dsv) {
2029     offset += num_div + num_dsv;  bound += num_drv;
2030     if (drv_index < bound)
2031       return offset + drv_index;
2032   }
2033 
2034   Cerr << "Error: DRV index out of range in SharedVariablesData::"
2035        << "drv_index_to_active_index()" << std::endl;
2036   abort_handler(VARS_ERROR);
2037   return _NPOS;
2038 }
2039 
2040 
ccv_index_to_acv_index(size_t ccv_index) const2041 size_t SharedVariablesData::ccv_index_to_acv_index(size_t ccv_index) const
2042 {
2043   bool cdv, ddv, cauv, dauv, ceuv, deuv, csv, dsv;
2044   complement_subsets(cdv, ddv, cauv, dauv, ceuv, deuv, csv, dsv);
2045 
2046   // This mapping is insensitive to var relaxation ADIV/ADRV -> ACV, as
2047   // source+target variable set orderings are impacted the same way
2048 
2049   size_t offset = 0, bound = 0, num_cv, num_div, num_dsv, num_drv;
2050   svdRep->design_counts(num_cv, num_div, num_dsv, num_drv); // w/ relaxed
2051   if (cdv) {
2052     bound += num_cv;
2053     if (ccv_index < bound)
2054       return offset + ccv_index;
2055   }
2056   else
2057     offset += num_cv;
2058 
2059   svdRep->aleatory_uncertain_counts(num_cv, num_div, num_dsv, num_drv);
2060   if (cauv) {
2061     bound += num_cv;
2062     if (ccv_index < bound)
2063       return offset + ccv_index;
2064   }
2065   else
2066     offset += num_cv;
2067 
2068   svdRep->epistemic_uncertain_counts(num_cv, num_div, num_dsv, num_drv);
2069   if (ceuv) {
2070     bound += num_cv;
2071     if (ccv_index < bound)
2072       return offset + ccv_index;
2073   }
2074   else
2075     offset += num_cv;
2076 
2077   svdRep->state_counts(num_cv, num_div, num_dsv, num_drv);
2078   if (csv) {
2079     bound += num_cv;
2080     if (ccv_index < bound)
2081       return offset + ccv_index;
2082   }
2083   //else
2084   //  offset += num_cv;
2085 
2086   Cerr << "Error: CCV index out of range in SharedVariablesData::"
2087        << "ccv_index_to_acv_index()" << std::endl;
2088   abort_handler(VARS_ERROR);
2089   return _NPOS;
2090 }
2091 
2092 
cdiv_index_to_adiv_index(size_t cdiv_index) const2093 size_t SharedVariablesData::cdiv_index_to_adiv_index(size_t cdiv_index) const
2094 {
2095   bool cdv, ddv, cauv, dauv, ceuv, deuv, csv, dsv;
2096   complement_subsets(cdv, ddv, cauv, dauv, ceuv, deuv, csv, dsv);
2097 
2098   // This mapping is insensitive to var relaxation ADIV/ADRV -> ACV, as
2099   // source+target variable set orderings are impacted the same way
2100 
2101   size_t offset = 0, bound = 0, num_cv, num_div, num_dsv, num_drv;
2102   svdRep->design_counts(num_cv, num_div, num_dsv, num_drv); // w/ relaxed
2103   if (ddv) {
2104     bound += num_div;
2105     if (cdiv_index < bound)
2106       return offset + cdiv_index;
2107   }
2108   else
2109     offset += num_div;
2110 
2111   if (dauv) {
2112     bound += num_div;
2113     if (cdiv_index < bound)
2114       return offset + cdiv_index;
2115   }
2116   else
2117     offset += num_div;
2118 
2119   if (deuv) {
2120     bound += num_div;
2121     if (cdiv_index < bound)
2122       return offset + cdiv_index;
2123   }
2124   else
2125     offset += num_div;
2126 
2127   if (dsv) {
2128     bound += num_div;
2129     if (cdiv_index < bound)
2130       return offset + cdiv_index;
2131   }
2132   //else
2133   //  offset += num_div;
2134 
2135   Cerr << "Error: CDIV index out of range in SharedVariablesData::"
2136        << "cdiv_index_to_adiv_index()" << std::endl;
2137   abort_handler(VARS_ERROR);
2138   return _NPOS;
2139 }
2140 
2141 
cdsv_index_to_adsv_index(size_t cdsv_index) const2142 size_t SharedVariablesData::cdsv_index_to_adsv_index(size_t cdsv_index) const
2143 {
2144   bool cdv, ddv, cauv, dauv, ceuv, deuv, csv, dsv;
2145   complement_subsets(cdv, ddv, cauv, dauv, ceuv, deuv, csv, dsv);
2146 
2147   // This mapping is insensitive to var relaxation ADIV/ADRV -> ACV, as
2148   // source+target variable set orderings are impacted the same way
2149 
2150   size_t bound = 0, offset = 0, num_cv, num_div, num_dsv, num_drv;
2151   svdRep->design_counts(num_cv, num_div, num_dsv, num_drv); // w/ relaxed
2152   if (ddv) {
2153     bound += num_dsv;
2154     if (cdsv_index < bound)
2155       return offset + cdsv_index;
2156   }
2157   else
2158     offset += num_dsv;
2159 
2160   svdRep->aleatory_uncertain_counts(num_cv, num_div, num_dsv, num_drv);
2161   if (dauv) {
2162     bound += num_dsv;
2163     if (cdsv_index < bound)
2164       return offset + cdsv_index;
2165   }
2166   else
2167     offset += num_dsv;
2168 
2169   svdRep->epistemic_uncertain_counts(num_cv, num_div, num_dsv, num_drv);
2170   if (deuv) {
2171     bound += num_dsv;
2172     if (cdsv_index < bound)
2173       return offset + cdsv_index;
2174   }
2175   else
2176     offset += num_dsv;
2177 
2178   svdRep->state_counts(num_cv, num_div, num_dsv, num_drv);
2179   if (dsv) {
2180     bound += num_dsv;
2181     if (cdsv_index < bound)
2182       return offset + cdsv_index;
2183   }
2184 
2185   Cerr << "Error: CDSV index out of range in SharedVariablesData::"
2186        << "cdsv_index_to_adsv_index()" << std::endl;
2187   abort_handler(VARS_ERROR);
2188   return _NPOS;
2189 }
2190 
2191 
cdrv_index_to_adrv_index(size_t cdrv_index) const2192 size_t SharedVariablesData::cdrv_index_to_adrv_index(size_t cdrv_index) const
2193 {
2194   bool cdv, ddv, cauv, dauv, ceuv, deuv, csv, dsv;
2195   complement_subsets(cdv, ddv, cauv, dauv, ceuv, deuv, csv, dsv);
2196 
2197   // This mapping is insensitive to var relaxation ADIV/ADRV -> ACV, as
2198   // source+target variable set orderings are impacted the same way
2199 
2200   size_t bound = 0, offset = 0, num_cv, num_div, num_dsv, num_drv;
2201   svdRep->design_counts(num_cv, num_div, num_dsv, num_drv); // w/ relaxed
2202   if (ddv) {
2203     bound += num_drv;
2204     if (cdrv_index < bound)
2205       return offset + cdrv_index;
2206   }
2207   else
2208     offset += num_drv;
2209 
2210   svdRep->aleatory_uncertain_counts(num_cv, num_div, num_dsv, num_drv);
2211   if (dauv) {
2212     bound += num_drv;
2213     if (cdrv_index < bound)
2214       return offset + cdrv_index;
2215   }
2216   else
2217     offset += num_drv;
2218 
2219   svdRep->epistemic_uncertain_counts(num_cv, num_div, num_dsv, num_drv);
2220   if (deuv) {
2221     bound += num_drv;
2222     if (cdrv_index < bound)
2223       return offset + cdrv_index;
2224   }
2225   else
2226     offset += num_drv;
2227 
2228   svdRep->state_counts(num_cv, num_div, num_dsv, num_drv);
2229   if (dsv) {
2230     bound += num_drv;
2231     if (cdrv_index < bound)
2232       return offset + cdrv_index;
2233   }
2234 
2235   Cerr << "Error: CDRV index out of range in SharedVariablesData::"
2236        << "cdrv_index_to_adrv_index()" << std::endl;
2237   abort_handler(VARS_ERROR);
2238   return _NPOS;
2239 }
2240 
2241 
assemble_all_labels(StringArray & all_labels) const2242 void SharedVariablesData::assemble_all_labels(StringArray& all_labels) const
2243 {
2244   const StringMultiArray&  acv_labels = svdRep->allContinuousLabels;
2245   const StringMultiArray& adiv_labels = svdRep->allDiscreteIntLabels;
2246   const StringMultiArray& adsv_labels = svdRep->allDiscreteStringLabels;
2247   const StringMultiArray& adrv_labels = svdRep->allDiscreteRealLabels;
2248 
2249   size_t num_av =  acv_labels.size() + adiv_labels.size()
2250                 + adsv_labels.size() + adrv_labels.size();
2251   all_labels.resize(num_av);
2252 
2253   size_t num_cv, num_div, num_dsv, num_drv, cv_start = 0, div_start = 0,
2254     dsv_start = 0, drv_start = 0, all_start = 0;
2255   design_counts(num_cv, num_div, num_dsv, num_drv); // includes relaxation
2256   copy_data_partial(acv_labels,   cv_start, all_labels, all_start, num_cv);
2257   all_start += num_cv;    cv_start += num_cv;
2258   copy_data_partial(adiv_labels, div_start, all_labels, all_start, num_div);
2259   all_start += num_div;  div_start += num_div;
2260   copy_data_partial(adsv_labels, dsv_start, all_labels, all_start, num_dsv);
2261   all_start += num_dsv;  dsv_start += num_dsv;
2262   copy_data_partial(adrv_labels, drv_start, all_labels, all_start, num_drv);
2263   all_start += num_drv;  drv_start += num_drv;
2264 
2265   aleatory_uncertain_counts(num_cv, num_div, num_dsv, num_drv); // w/ relaxation
2266   copy_data_partial(acv_labels,   cv_start, all_labels, all_start, num_cv);
2267   all_start += num_cv;    cv_start += num_cv;
2268   copy_data_partial(adiv_labels, div_start, all_labels, all_start, num_div);
2269   all_start += num_div;  div_start += num_div;
2270   copy_data_partial(adsv_labels, dsv_start, all_labels, all_start, num_dsv);
2271   all_start += num_dsv;  dsv_start += num_dsv;
2272   copy_data_partial(adrv_labels, drv_start, all_labels, all_start, num_drv);
2273   all_start += num_drv;  drv_start += num_drv;
2274 
2275   epistemic_uncertain_counts(num_cv, num_div, num_dsv, num_drv);// w/ relaxation
2276   copy_data_partial(acv_labels,   cv_start, all_labels, all_start, num_cv);
2277   all_start += num_cv;    cv_start += num_cv;
2278   copy_data_partial(adiv_labels, div_start, all_labels, all_start, num_div);
2279   all_start += num_div;  div_start += num_div;
2280   copy_data_partial(adsv_labels, dsv_start, all_labels, all_start, num_dsv);
2281   all_start += num_dsv;  dsv_start += num_dsv;
2282   copy_data_partial(adrv_labels, drv_start, all_labels, all_start, num_drv);
2283   all_start += num_drv;  drv_start += num_drv;
2284 
2285   state_counts(num_cv, num_div, num_dsv, num_drv);              // w/ relaxation
2286   copy_data_partial(acv_labels,   cv_start, all_labels, all_start, num_cv);
2287   all_start += num_cv;   // cv_start += num_cv;
2288   copy_data_partial(adiv_labels, div_start, all_labels, all_start, num_div);
2289   all_start += num_div;  //div_start += num_div;
2290   copy_data_partial(adsv_labels, dsv_start, all_labels, all_start, num_dsv);
2291   all_start += num_dsv;  //dsv_start += num_dsv;
2292   copy_data_partial(adrv_labels, drv_start, all_labels, all_start, num_drv);
2293   //all_start += num_drv;  drv_start += num_drv;
2294 }
2295 
2296 
2297 /** Deep copies are used when recasting changes the nature of a
2298     Variables set. */
copy() const2299 SharedVariablesData SharedVariablesData::copy() const
2300 {
2301   // the handle class instantiates a new handle and a new body and copies
2302   // current attributes into the new body
2303   SharedVariablesData svd; // new handle: svdRep=NULL
2304 
2305   if (svdRep) {
2306     svd.svdRep.reset(new SharedVariablesDataRep());
2307     svd.svdRep->copy_rep(svdRep.get());
2308   }
2309 
2310   return svd;
2311 }
2312 
2313 
2314 template<class Archive>
save(Archive & ar,const unsigned int version) const2315 void SharedVariablesDataRep::save(Archive& ar, const unsigned int version) const
2316 {
2317   // for now only serializing the essential data needed to reconstruct
2318   // (or at least that used historically)
2319   // consider storing additional information
2320   ar & variablesView;
2321   ar & variablesCompsTotals;
2322   ar & allRelaxedDiscreteInt;
2323   ar & allRelaxedDiscreteReal;
2324   ar & allContinuousLabels;
2325   ar & allDiscreteIntLabels;
2326   ar & allDiscreteStringLabels;
2327   ar & allDiscreteRealLabels;
2328 }
2329 
2330 
2331 template<class Archive>
load(Archive & ar,const unsigned int version)2332 void SharedVariablesDataRep::load(Archive& ar, const unsigned int version)
2333 {
2334   ar & variablesView;
2335   ar & variablesCompsTotals;
2336   ar & allRelaxedDiscreteInt;
2337   ar & allRelaxedDiscreteReal;
2338   ar & allContinuousLabels;
2339   ar & allDiscreteIntLabels;
2340   ar & allDiscreteStringLabels;
2341   ar & allDiscreteRealLabels;
2342 
2343   // no need to size labels since they are read: size_all_labels();
2344   size_all_types();
2345   initialize_all_ids();
2346   // TODO: rebuild more sizes and indices if possible
2347 }
2348 
2349 
2350 template<class Archive>
serialize(Archive & ar,const unsigned int version)2351 void SharedVariablesData::serialize(Archive& ar, const unsigned int version)
2352 {
2353   // load will default construct and load through the pointer
2354   ar & svdRep;
2355 }
2356 
2357 
2358 // explicit instantions needed due to serialization through pointer,
2359 // which won't instantate the above template?
2360 template void SharedVariablesData::serialize<boost::archive::binary_iarchive>
2361 (boost::archive::binary_iarchive& ar, const unsigned int version);
2362 
2363 template void SharedVariablesData::serialize<boost::archive::binary_oarchive>
2364 (boost::archive::binary_oarchive& ar, const unsigned int version);
2365 
2366 
2367 } // namespace Dakota
2368