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 #include <cstdlib>
10 #include <iostream>
11 #include <fstream>
12 #include <vector>
13 #include <string>
14 #include <cmath>
15 
16 
main(int argc,char ** argv)17 int main(int argc, char** argv)
18 {
19 
20   // This sample Dakota program implements the Srinivas' problem
21   // defined on page B-5 of David Van Veldhuizen's Ph.D.
22   // thesis at the Air Force Institute of Technology, titled
23   // "Multiobjective Evolutionary Algorithms:  Classifications,
24   // Analyses, and New Innovations.
25   // This application program reads and writes parameter and response data
26   // directly so that the NO_FILTER option of dakota may be used.
27 
28   std::ifstream fin(argv[1]);
29   if (!fin) {
30     std::cerr << "\nError: failure opening " << argv[1] << std::endl;
31     exit(-1);
32   }
33   size_t i, num_vars, num_fns;
34   std::string vars_text, fns_text;
35 
36   // Get the parameter std::vector and ignore the labels
37   fin >> num_vars >> vars_text;
38   std::vector<double> x(num_vars);
39   for (i=0; i<num_vars; i++) {
40     fin >> x[i];
41     fin.ignore(256, '\n');
42   }
43 
44   // Get the ASV std::vector and ignore the labels
45   fin >> num_fns >> fns_text;
46   std::vector<int> ASV(num_fns);
47   for (i=0; i<num_fns; i++) {
48     fin >> ASV[i];
49     fin.ignore(256, '\n');
50   }
51 
52   if (num_vars != 2) {
53     std::cerr << "Wrong number of variables for the MOP Constrained problem\n";
54     exit(-1);
55   }
56   if (num_fns != 4) {
57     std::cerr << "Wrong number of functions for the MOP Constrained problem\n";
58     exit(-1);
59   }
60 
61   // Compute and output responses
62   double f0=0;
63   double f1=0;
64   double g0=0;
65   double g1=0;
66   f0 = pow(x[0]-2,2)+pow(x[1]-1,2)+2;
67   f1 = 9*x[0]-pow(x[1]-1,2);
68   g0 = (x[0]*x[0])+(x[1]*x[1])-225;
69   g1 = x[0]-3*x[1]+10;
70 
71   std::ofstream fout(argv[2]);
72   if (!fout) {
73     std::cerr << "\nError: failure creating " << argv[2] << std::endl;
74     exit(-1);
75   }
76   fout.precision(15); // 16 total digits
77   fout.setf(std::ios::scientific);
78   fout.setf(std::ios::right);
79 
80   // **** f:
81   if (ASV[0] & 1)
82     fout << "                     " << f0 << " f0\n";
83     fout << "                     " << f1 << " f1\n";
84  // **** c1:
85   if (ASV[1] & 1)
86     fout << "                     " << g0 << " c1\n";
87 
88   // **** c2:
89   if (ASV[2] & 1)
90     fout << "                     " << g1 << " c2\n";
91 
92   fout.flush();
93   fout.close();
94   return 0;
95 }
96 
97 
98