/*********************************************************************** This is an example of a blackbox optimization model which communicates via plain text file input/output: variables.txt is read: X, one value per line objectives.txt is written: F (O lines), then G (M lines) Both files lie in the folder the blackbox is started in. Replace this program with your own simulation or model. ***********************************************************************/ #ifdef _MSC_VER #define _CRT_SECURE_NO_WARNINGS /* MSVC: fopen, fscanf (C4996) */ #endif #include #include /***********************************************************************/ int main( void ) { /* Problem dimensions *********************/ int o = 1; /* Number of objectives */ int n = 4; /* Number of variables (in total) */ int m = 3; /* Number of constraints (in total) */ /* F,G,X arrays for input/output via text file **********************************************/ double f[10], g[100], x[1000]; FILE *input_file, *output_file; int i; /*#################################################################*/ /*############### READ X VARIABLES FROM TEXT-FILE ##############*/ /*#################################################################*/ input_file = fopen("variables.txt", "r"); if( input_file == NULL ) { printf("\n ERROR IN BLACKBOX: NO variables.txt FILE FOUND\n"); return 1; } for( i=0; i= 0 MUST COME SECOND in g[me:m-1] */ g[1] = x[1] - 1.333333333; g[2] = x[2] - 2.666666666; /*#################################################################*/ /*######## WRITE OBJECTIVE AND CONSTRAINTS TO TEXT-FILE #########*/ /*#################################################################*/ output_file = fopen("objectives.txt", "w"); if( output_file == NULL ) { printf("\n ERROR IN BLACKBOX: CANNOT WRITE objectives.txt\n"); return 1; } for( i=0; i