cocomice
10/27/2014 - 2:38 PM

extract_opt.c

// Optional settings:
// BORG_Debug_on();
// BORG_Algorithm_ms_max_time(0.008);
// BORG_Algorithm_output_aerovis();

char runtime[256];
char outputFilename[256];
FILE* outputFile = NULL;

BORG_Algorithm_ms_startup(&argc, &argv);
BORG_Algorithm_ms_max_evaluations(100000);
BORG_Problem problem = BORG_Problem_create(num_decisions, num_objectives, num_constraints, my_eval_function);

// Define filenames for runtime and end-of-run output
sprintf(runtime, "./output/runtime_seed_%d.txt",seed);
sprintf(outputFilename, "./output/my_results_seed_%d.set", seed);

// Turn on the runtime output (pass in the filename), and define the printing frequency
BORG_Algorithm_output_runtime(runtime);
BORG_Algorithm_output_frequency(5000);

BORG_Random_seed(seed);
BORG_Archive result = BORG_Algorithm_ms_run(problem);

// If this is the master node, print out the final archive
if (result != NULL) { 
	outputFile = fopen(outputFilename, "w");
	if (!outputFile) {
		BORG_Debug("Unable to open final output file\n");
	}
	BORG_Archive_print(result, outputFile);
	BORG_Archive_destroy(result);
	fclose(outputFile);
}

BORG_Algorithm_ms_shutdown();
BORG_Problem_destroy(problem);
/*
* by YU LI 
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>


int main(int argc, char* argv[])
{	

	char tar_var1[]="SBX" , tar_var2[]="DE"  , tar_var3[]="PCX";
	char tar_var4[]="SPX" , tar_var5[]="UNDX", tar_var6[]="UM" ;	

	char tar_var7[] = "PopulationSize" ;
	char tar_var8[] = "ArchiveSize"    ;  
	
	char header[]   = "#SBX\tDE\tPCX\tSPX\tUNDX\tUM\tPopulationSize\tArchiveSize\n" ;

	char buffer[100], *p ;
	double val_dum[8] ;

	FILE *fin, *fout ;

	fin  = fopen(argv[1], "r") ;
	fout = fopen(argv[2], "w") ;


	if (fin==NULL)  perror("Error opening file") ;
	if (fout==NULL) perror("Error creating file");

	fprintf(fout, header) ;

	while ( fgets(buffer, 100, fin)!=NULL ){

	p = buffer ;

	if( strstr(buffer, tar_var1) ){
		while(*p){
			if(isdigit(*p)){
				val_dum[0] = strtod(p, NULL) ;
				fprintf(fout, "%f\t", val_dum[0]);
				break ;
			}
		p++ ;
		}
	continue;		
	}

	if( strstr(buffer, tar_var2) ){
		while(*p){
			if(isdigit(*p)){
				val_dum[1] = strtod(p, NULL) ;
				fprintf(fout, "%f\t", val_dum[1]);
				break ;
			}
		p++ ;
		}
	continue;		
	}

	if( strstr(buffer, tar_var3) ){
		while(*p){
			if(isdigit(*p)){
				val_dum[2] = strtod(p, NULL) ;
				fprintf(fout, "%f\t", val_dum[2]);
				break ;
			}
		p++ ;
		}
	continue;		
	}

	if( strstr(buffer, tar_var4) ){
		while(*p){
			if(isdigit(*p)){
				val_dum[3] = strtod(p, NULL) ;
				fprintf(fout, "%f\t", val_dum[3]);
				break ;
			}
		p++ ;
		}
	continue;		
	}

	if( strstr(buffer, tar_var5) ){
		while(*p){
			if(isdigit(*p)){
				val_dum[4] = strtod(p, NULL) ;
				fprintf(fout, "%f\t", val_dum[4]);
				break ;
			}
		p++ ;
		}
	continue;		
	}

	if( strstr(buffer, tar_var6) ){
		while(*p){
			if(isdigit(*p)){
				val_dum[5] = strtod(p, NULL) ;
				fprintf(fout, "%f\t", val_dum[5]);
				break ;
			}
		p++ ;
		}
	continue;		
	}

	if( strstr(buffer, tar_var7) ){
		while(*p){
			if(isdigit(*p)){
				val_dum[6] = strtod(p, NULL) ;
				fprintf(fout, "%d\t", (int)val_dum[6]);
				break ;
			}
		p++ ;
		}
	continue;		
	}

	if( strstr(buffer, tar_var8) ){
		while(*p){
			if(isdigit(*p)){
				val_dum[7] = strtod(p, NULL) ;
				fprintf(fout, "%d\n", (int)val_dum[7]);
				break ;
			}
		p++ ;
		}
	continue;		
	}		
		
	}										

	fclose(fin)  ;
	fclose(fout) ;

	return 0 ;
}