/*-------------------------------------------------------------------------------------*/
/* NOMAD - Nonsmooth Optimization by Mesh Adaptive Direct search - version 3.2 */
/* */
/* Copyright (C) 2001-2008 Mark Abramson - the Boeing Company, Seattle */
/* Charles Audet - Ecole Polytechnique, Montreal */
/* Gilles Couture - Ecole Polytechnique, Montreal */
/* John Dennis - Rice University, Houston */
/* Sebastien Le Digabel - Ecole Polytechnique, Montreal */
/* */
/* funded in part by AFOSR and Exxon Mobil */
/* */
/* Author: Quentin Reynaud */
/* */
/* Contact information: */
/* Ecole Polytechnique de Montreal - GERAD */
/* C.P. 6079, Succ. Centre-ville, Montreal (Quebec) H3C 3A7 Canada */
/* e-mail: nomad@gerad.ca */
/* phone : 1-514-340-6053 #6928 */
/* fax : 1-514-340-5665 */
/* */
/* This program is free software: you can redistribute it and/or modify it under the */
/* terms of the GNU General Public License as published by the Free Software */
/* Foundation, either version 3 of the License, or (at your option) any later */
/* version. */
/* */
/* This program is distributed in the hope that it will be useful, but WITHOUT ANY */
/* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A */
/* PARTICULAR PURPOSE. See the GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License along with this */
/* program. If not, see . */
/* */
/* You can find information on the NOMAD software at www.gerad.ca/nomad */
/*-------------------------------------------------------------------------------------*/
/* This program read informations files from NOMAD version 2 and create the */
/* parameters files used by NOMAD version 3 */
/*-------------------------------------------------------------------------------------*/
#include
#include
#include
#include
#include
using namespace std;
// This method fills the array 'coord' with numbers read from the file 'fin'.
void fillArray(ifstream & fin, double * coord, int dimension)
{
char ch;
char line[80];
int i = 0;
// We go in the loop: the next character is extracted from the file.
while ((i < dimension) && (fin.get(ch)))
{
// '%' marks a comment line.
if (ch == '%')
// The line is read.
fin.getline(line, 80);
else // If the end of line is reached we do nothing.
if (ch == '\n') {}
else // If it's not a comment line or an end of line, it's a number.
{
// The character is reinserted in the file.
fin.putback(ch);
// The number is read and put in the 'coord' array.
fin >> coord[i++];
}
}
}
// This method fills the array 'coord' with string read from the file 'fin'.
void fillArrayString(ifstream & fin, string * coord, int dimension)
{
char ch;
char line[80];
int i = 0;
// We go in the loop: the next character is extracted from the file.
while ((i < dimension) && (fin.get(ch)))
{
// '%' marks a comment line.
if (ch == '%')
// The line is read.
fin.getline(line, 80);
else // If the end of line is reached we do nothing.
if (ch == '\n') {}
else // If it's not a comment line or an end of line, it's a string.
{
// The character is reinserted in the file.
fin.putback(ch);
// The string is read and put in the 'coord' array.
fin >> coord[i++];
}
}
}
// This method remplace the path from s
string remplace (string s)
{
char c = ' ';
char s2[255];
int i = 0,
j = 0;
while(c != '\0')
{
c = s[i++];
if (c == '/') j = 0;
s2[j++] = c;
}
s2[j] = '\0';
return (s2);
}
int main(int argc, char** argv)
{
if (argc > 1 && argc <= 3)
{
// Reading the description file
ifstream desc(argv[1], ios::in);
if(desc)
{
string mot = "",
bounds = "",
start = "",
results = "",
blackBox = "",
input = "",
truth = "",
constrains = "",
surrogate = "",
caches = "";
char path[50];
bool isBounds = false,
isBB = false,
isSurrogate = false,
isCaches = false,
pollComplete,
speculativeSearch,
initialComplete,
isParam[21];
int dim = -1,
cons = -1,
coarseningExponent,
refiningExponent,
filterNorm,
seed,
truthEvals,
newTruthEvals,
iterations,
iterativePoints,
iterativeSearch,
initialSearch,
initialPoints,
pollDirections,
displayFactor;
double pollBasis,
frameCenterTrigger,
hmin,
hmax,
pollSizeTerm;
// Initialize the presence of the parameters
for (int i = 0; i < 21; ++i) isParam[i] = false;
// Searching some parameters
while (!desc.eof())
{
desc >> mot;
if (mot == "DIMENSION")
{
desc >> dim;
}
else if (mot == "USE_CACHES")
{
desc >> mot;
if (mot == "1") isCaches = true;
}
else if (mot == "CACHE_FILE")
{
desc >> caches;
caches = remplace (caches);
}
else if (mot == "GEN_CONS_NB")
{
desc >> cons;
}
else if (mot == "USE_BOUNDS")
{
desc >> mot;
if (mot == "1") isBounds = true;
}
else if (mot == "BOUNDS_FILE")
{
desc >> bounds;
}
else if (mot == "START_PT_FILE")
{
desc >> start;
}
else if (mot == "RESULTS_FILE")
{
desc >> results;
results = remplace (results);
}
else if (mot == "USE_BLACK_BOXES")
{
desc >> mot;
if (mot == "1") isBB = true;
}
else if (mot == "INPUT_FILE")
{
desc >> input;
input = remplace (input);
}
else if (mot == "TRUTH_EXE")
{
desc >> truth;
truth = remplace (truth);
}
else if (mot == "GEN_CONS_FILE")
{
desc >> constrains;
}
else if (mot == "USE_SURROGATE")
{
desc >> mot;
if (mot == "1") isSurrogate = true;
}
else if (mot == "SURROGATE")
{
desc >> surrogate;
surrogate = remplace (surrogate);
}
else desc >> mot;
}
desc.close();
// Path of the input file
if (input != "")
{
char c = ' ';
int i = 0,
tmp = 0;
while (c != '\0')
{
c = argv[1][i];
if (c == '/') tmp = i;
path[i++] = c;
}
path[tmp] = '\0';
}
else
{
cout<< "Error : you must give an input file."<\n#include \n#include \nusing namespace std;\n";
bb << "int main(int argc, char** argv)\n{\n";
bb << "if (argc == 2){\n";
bb << "\tdouble entree[";
bb << dim;
bb << "];\n\tint i = 0;\n\tifstream file(argv[1], ios::in);\n";
bb << "\tif(file){\n";
bb << "\t/* Reading the point */\n\t\twhile ( !file.eof()) file >> entree[i++];\n";
bb << "\t\tfile.close();\n";
bb << "\t\tofstream fic(\"input.txt\", ios::trunc);\n";
bb << "\t\tfic.precision(15);\n";
bb << "\t\tfor (i = 0; i < ";
bb << dim;
bb << "; ++i){\n";
bb << "\t\tfic << entree[i] << \" \";}\n";
bb << "\t\tfic.close();";
bb << "system(\"" << path << truth << "\");\n";
bb << "\t\tcout << endl;\n";
for (int i = 0; i < cons; ++i)
{
bb << "\t\tsystem(\"" << path << cons_val[i] << "\");\n";
bb << "\t\tcout << endl;\n";
}
bb << "\t\t}\n\t}\n";
bb << "\telse{\n\t\tcout << \"Error.\" << endl;\n";
bb << "\t\treturn 1;}\n";
bb << "\n\treturn 0;\n}"<> mot;
// Searching the parameters
if (mot == "POLL_BASIS")
{
param >> pollBasis;
isParam[0] = true;
}
else if (mot == "COARSENING_EXPONENT")
{
param >> coarseningExponent;
isParam[1] = true;
}
else if (mot == "REFINING_EXPONENT")
{
param >> refiningExponent;
isParam[2] = true;
}
else if (mot == "RANDOM_SEED")
{
param >> seed;
isParam[3] = true;
}
else if (mot == "POLL_COMPLETE")
{
param >> pollComplete;
isParam[4] = true;
}
else if (mot == "POLL_DIRECTIONS")
{
param >> pollDirections;
isParam[5] = true;
}
else if (mot == "INITIAL_SEARCH")
{
param >> initialSearch;
isParam[6] = true;
}
else if (mot == "INITIAL_COMPLETE")
{
param >> initialComplete;
isParam[7] = true;
}
else if (mot == "INITIAL_POINTS")
{
param >> initialPoints;
isParam[8] = true;
}
else if (mot == "ITERATIVE_SEARCH")
{
param >> iterativeSearch;
isParam[9] = true;
}
else if (mot == "ITERATIVE_POINTS")
{
param >> iterativePoints;
isParam[10] = true;
}
else if (mot == "SPECULATIVE_SEARCH")
{
param >> speculativeSearch;
isParam[11] = true;
}
else if (mot == "POLL_SIZE_TERM")
{
param >> pollSizeTerm;
isParam[12] = true;
}
else if (mot == "ITERATIONS")
{
param >> iterations;
isParam[13] = true;
}
else if (mot == "TRUTH_EVALS")
{
param >> truthEvals;
isParam[14] = true;
}
else if (mot == "NEW_TRUTH_EVALS")
{
param >> newTruthEvals;
isParam[15] = true;
}
else if (mot == "HMAX")
{
param >> hmax;
isParam[16] = true;
}
else if (mot == "HMIN")
{
param >> hmin;
isParam[17] = true;
}
else if (mot == "FILTER_NORM")
{
param >> filterNorm;
isParam[18] = true;
}
else if (mot == "FRAME_CENTER_TRIGGER")
{
param >> frameCenterTrigger;
isParam[19] = true;
}
else if (mot == "DISPLAY_FACTOR")
{
param >> displayFactor;
isParam[20] = true;
}
}
}
param.close();
}
// Writing the output file
ofstream fic("param.txt", ios::trunc);
if (fic)
{
// Parameters from description file
if (dim != -1)
{
fic << "DIMENSION\t\t" << dim << "\n\n";
}
else
{
cout << "Error : DIMENSION is missing."<