1
2 //--------------------------------------------------------------------
3 // Copyright (C) 1993,1994:
4 // J.C. Meza
5 // Sandia National Laboratories
6 // meza@california.sandia.gov
7 //--------------------------------------------------------------------
8
9 #ifdef HAVE_CONFIG_H
10 #include "OPT++_config.h"
11 #endif
12
13 #include <iostream>
14 #include <fstream>
15 #ifdef HAVE_STD
16 #include <cmath>
17 #else
18 #include <math.h>
19 #endif
20
21 #include "newmat.h"
22
23 #include "pds.h"
24
25 using namespace std;
26 using NEWMAT::ColumnVector;
27
28 extern "C" {
29 int bin_open(char *filename, int *fd);
30 int bin_close(int fd);
31 }
32
33 namespace OPTPP {
create_scheme(ostream * fout,int ndim,int scheme_limit,char * scheme_name,int * scheme,int debug)34 int create_scheme (ostream *fout, int ndim, int scheme_limit, char
35 *scheme_name, int *scheme, int debug)
36 {
37 /*******************************************************************
38 *
39 * create a search strategy for the parallel direct search method
40 *
41 * since the size of the workspace plays a critical role in the
42 * total number of points generated for the search scheme, a brief
43 * explanation of how this workspace is used is included here for
44 * those who wish to optimize the use of memory.
45 *
46 * upon entry into the subroutine `search' the vector `scheme' is
47 * partitioned into a matrix of the following form
48 * integer scheme(-1:n,-n:?)
49 * where the total number of columns depends on the amount of space
50 * allocated in the calling program.
51 *
52 * the vector `index' is used as a permutation array to keep track
53 * of every column of `scheme'. in `search' it is an array of the
54 * form
55 * integer index(-n:?)
56 *
57 * the vector `list' is used to keep track of each unique n-tuple in
58 * `scheme'. and thus is declared to be an array of the form
59 * integer list(?)
60 *
61 * thus, `index' and `list' really only need to be large enough to
62 * track the total number of columns in scheme but are declared to
63 * be as large as `scheme' to prevent any possible overflow. for
64 * the most efficient use of space---which may become an issue when
65 * generating very large search schemes on a processor with a
66 * limited amount of memory, the constant `dim' can be set equal to
67 * the dimension of the problem(s) for which the search scheme is
68 * being generated and the constant `max' can be set equal to the
69 * number of columns of workspace to be allowed in `scheme' so that
70 * the actual amount of space for `scheme' becomes
71 * integer scheme(-1:dim,-dim:max)
72 *
73 * note that the constant `limit' automatically takes care of this
74 * in the driver. the workspace for index and list can then be
75 * redefined---in the driver--as
76 * integer index(1+dim+max), list(max)
77 * without any danger of overflow. thus all space created in the
78 * calling program will be used in the subroutine `make_search'.
79 *
80 * Original version due to Virginia Torczon
81 * This version hacked by J.C. Meza
82 *
83 *******************************************************************/
84
85 int error;
86 int factor, unique;
87 int fpscheme;
88 ColumnVector list(scheme_limit), index(scheme_limit);
89
90 (*fout) << "Creating SCHEME file: " << scheme_name << "\n";
91
92 error = bin_open(scheme_name, &fpscheme);
93 if (error != 0) {
94 cerr << "create_scheme: error opening scheme file for writing. \n"
95 << "The TMP environment variable may need to be set to a \n"
96 << "valid temporary file system. Otherwise, PDS and TRPDS \n"
97 << "will not run correctly. Please set the TMP environment \n"
98 << "variable and re-run the problem. \n" << endl;
99 return error;
100 }
101
102 make_search(ndim, fpscheme, &scheme_limit, scheme, (int *)index.Store(),
103 (int *)list.Store(), &unique, &factor, &error);
104
105 if (error == 0) {
106 if (debug) {
107 (*fout) << "Successfully completed a search strategy.\n";
108 (*fout) << "Dimension of the problem = " << ndim << "\n";
109 (*fout) << "Number of unique points = " << unique << "\n";
110 (*fout) << "Restoration factor = " << factor << "\n";
111 (*fout) << "Initialization phase finished.\n\n";
112 }
113 }
114 else {
115 (*fout) << "Returned without a completed search strategy. \n";
116 (*fout) << "Internal stack overflow in quicksort routines.\n";
117 (*fout) << "Check the documentation for further details.\n" << endl;
118 return error;
119 }
120
121 error = bin_close(fpscheme);
122 return error;
123 }
124
125 } // namespace OPTPP
126
127