Commit 090544aa authored by gsell's avatar gsell

Merge branch '389-removed-unused-nsga2-directory' into 'master'

Resolve "removed unused nsga2 directory"

Closes #389

See merge request !201
parents 1d423599 dee4a211
# FinPhase3.data
#
# checked by Hao Zha in 15:33, 21/02/2011, with the data from *110217_1512.snap
# add quadrupoles by Hao Zha in 17:09, 27/02/2011. The data were from *110217_1512.snap
#
# CTF3 GUN
#
FINSS_RGUN_dphi -3.30 # Gun phase [deg] w.r.t autophase -3.25
FINSS_RGUN_volt 100.0 # Gun voltage [MV]
D_LAG_RGUN 0.0
#
#
# Traveling Wave Stuctures
#
FINSB01_RACC_dphi 0.0 # TW-Structure phase w.r.t autophase [deg]
FINSB02_RACC_dphi 0.0 # TW-Structure phase w.r.t autophase [deg]
FINSB03_RACC_dphi 0.0 # TW-Structure phase w.r.t autophase [deg]
FINSB04_RACC_dphi -34.2 # TW-Structure phase w.r.t autophase [deg]
FINXB_RACC_dphi 0.0 # X-band phase w.r.t autophase [deg]
FIND1_RTDC_dphi 0.0 # TDC at low energy
F10D1_RTDC_dphi 0.0 # TDC ay higher energy
D_LAG_B01 0.0
D_LAG_B02 0.0
#
FINSB01_RACC_volt 19 # TW-Structure voltage [MV]
FINSB02_RACC_volt 25 # TW-Structure voltage [MV]
FINSB03_RACC_volt 25 # TW-Structure voltage [MV]
FINSB04_RACC_volt 0.0 # TW-Structure voltage [MV]
#
FIND1_RTDC_volt 0.0 # TDC voltage [MV]
F10D1_RTDC_volt 0.0 # TDC voltage [MV]
#
FINXB_RACC_volt 0.0 # TW-Structure voltage [MV]
#
#
FIND1_MSOL10_i 116.5
#
# Solenoids over the
# first 2 TW Stuctures
#
FINSB01_MSOL10_ks 0.04 #
FINSB01_MSOL20_ks 0.04 #
FINSB01_MSOL30_ks 0.08 #
FINSB01_MSOL40_ks 0.08 #
#
FINSB02_MSOL10_ks 0.068 #
FINSB02_MSOL20_ks 0.068 #
FINSB02_MSOL30_ks 0.068 #
FINSB02_MSOL40_ks 0.068 #
#
FINSB03_MSOL10_ks 0.02 #
FINSB03_MSOL20_ks 0.02 #
FINSB03_MSOL30_ks 0.02 #
FINSB03_MSOL40_ks 0.02 #
#
FINSB04_MSOL10_ks 0.0 #
FINSB04_MSOL20_ks 0.0 #
FINSB04_MSOL30_ks 0.0 #
FINSB04_MSOL40_ks 0.0 #
#
#
FINXB_MQUA10_k1 -0.3663 #
FINXB_MQUA20_k1 2.8417 #
FINXB_MQUA30_k1 -2.7941 #
FINXB_MQUA40_k1 2.1990 #
FINXB_MQUA50_k1 -1.3724 # Hao : the original line is 'FINXB_MQUA10_k1', is this a spell mistake ?
F10D1_MQUA10_k1 0.0 #
F10D1_MQUA15_k1 0.0 #
F10D1_MQUA20_k1 0.0 #
F10D1_MQUA25_k1 0.0 #
F10D1_MQUA30_k1 0.0 #
F10D1_MQUA35_k1 0.0 #
F10D1_MQUA40_k1 0.0 #
F10D1_MQUA45_k1 0.0 #
F10D1_MQUA50_k1 0.0 #
F10D1_MQUA55_k1 0.0 #
F10D1_MQUA60_k1 0.0 #
F10D1_MQUA65_k1 0.0 #
F10D1_MQUA70_k1 0.0 #
F10D1_MQUA75_k1 0.0 #
F10D1_MQUA80_k1 0.0 #
F10D1_MQUA85_k1 0.0 #
F10D1_MQUA90_k1 0.0 #
F10D1_MQUA95_k1 0.0 #
#
#
TFWHM 6.03 # Laser fwhm time [ps]
TRISE 0.432 # Laser rise time [ps] Simona: it was 4.32
TFALL 0.432 # Laser fall time [ps] Simona: it was 4.32
CUTOFF 4.0 # Cutoff in units of sigma
#
SIGX 275 # Laser spot size (x) [um]
SIGY 275 # Laser spot size (y) [um]
#
EKIN 0.63 # kinetic energy of electrons at emission [eV]
QBUNCH 200 # Bunch charge [pC]
#
NBIN 8 # Number of energy bins (gun)
#
MX 2 # Mesh size in X Simona: it was 64
MY 2 # Mesh size in Y Simona: it was 64
MT 2 # Mesh size in T/Z Simona: it was 1024
#
NPART 1E8 # Number of simulation particles
#
DT 5.0 # time step in beamline [ps]
DTGUN 0.1 # time step in gun [ps]
#
ZSTOP 13.0 # z where simulation stops [m]
ZSTOPGUN 0.2 # z where simulation of the gun stops [m]
#
CORES 32 # number of cores (cpus) to use
#
FREQ 2997.912 # rf frequency Mhz
#
H5PSFQ 5000 # h5 phase space dump frequency Simona: it was 500
#
USEET -1 # flag for envelope-tracker (-1 == OPAL-t 1 == OPAL-e)
#
NSLICE 100 # number of slices for opal-e
#
FTOSCAMPLITUDE 1 # amplidude
#
FTOSCPERIODS 100 # periods
This diff is collapsed.
1DProfile1 5 5 1.50
-6.1 -1.6 2.9 1
22.1000 26.6000 31.1000 1
-0.0170
1.8055
-0.2819
0.5680
0.3817
0.0966
-0.017
1.8055
-0.2819
0.5680
0.3817
0.0966
This diff is collapsed.
This diff is collapsed.
seed 11
tournament 2
\ No newline at end of file
#!/bin/sh
./nsga2 nsga2_param.txt ../PISA_ 0.1
#!/bin/bash
ulimit -m 1800000 -v 1800000
export FIELDMAPS=`pwd`/fieldmaps
export TEMPLATES=`pwd`
export SIMTMPDIR=`pwd`/tmp_sim
# cleanup
if stat -t *_results.dat* >/dev/null 2>&1
then
rm *_results.dat*
fi
if stat -t PISA_* >/dev/null 2>&1
then
rm PISA_*
fi
if stat -t *.trace.* >/dev/null 2>&1
then
rm *.trace.*
fi
if test -d "tmp_sim"; then
rm -rf tmp_sim
fi
mkdir tmp_sim
mpirun -np 3 ${OPT_BUILD_DIR}/Drivers/homotopy-opal/homotopy-opal.exe \
--inputfile=FiPha3Opt1.tmpl --outfile=results.dat --outdir=./ \
--iterations=10 --num-points=100 --num-objectives=3 --num-design-vars=13 \
--num-masters=1 --num-coworkers=1 --sol-synch=1
#!/bin/bash
ulimit -m 1800000 -v 1800000
export FIELDMAPS=`pwd`/fieldmaps
export TEMPLATES=`pwd`
export SIMTMPDIR=`pwd`/tmp_sim
# cleanup
if stat -t *_results.dat* >/dev/null 2>&1
then
rm *_results.dat*
fi
if stat -t PISA_* >/dev/null 2>&1
then
rm PISA_*
fi
if stat -t *.trace.* >/dev/null 2>&1
then
rm *.trace.*
fi
if test -d "tmp_sim"; then
rm -rf tmp_sim
fi
mkdir tmp_sim
mpirun -np 6 ${OPT_BUILD_DIR}/Drivers/pisa-opal/pisa-opal.exe \
--inputfile=FiPha3Opt1.tmpl --outfile=results.dat --outdir=./ \
--maxGenerations=10 --initialPopulation=10 \
--num-masters=2 --num-coworkers=1 --sol-synch=5 \
--selector=${OPT_BUILD_DIR}/extlib/nsga2/nsga2
d1: DVAR, VARIABLE="x", LOWERBOUND="-1.0", UPPERBOUND="1.0";
d2: DVAR, VARIABLE="y", LOWERBOUND="-1.0", UPPERBOUND="1.0";
d3: DVAR, VARIABLE="z", LOWERBOUND="-1.0", UPPERBOUND="1.0";
//obj1: OBJECTIVE, EXPR="FON(x,y,z,1)";
//obj2: OBJECTIVE, EXPR="FON(x,y,z,2)";
obj1: OBJECTIVE, EXPR="1.0 - exp(-1.0 * (sq(x - 1.0/sqrt(3.0)) + sq(y - 1.0/sqrt(3.0)) + sq(z - 1.0/sqrt(3.0)) ))";
obj2: OBJECTIVE, EXPR="1.0 - exp(-1.0 * (sq(x + 1.0/sqrt(3.0)) + sq(y + 1.0/sqrt(3.0)) + sq(z + 1.0/sqrt(3.0)) ))";
objs: OBJECTIVES = (obj1, obj2);
dvars: DVARS = (d1, d2, d3);
constrs: CONSTRAINTS = ();
opt: OPTIMIZE, OBJECTIVES=objs, DVARS=dvars, CONSTRAINTS=constrs;
seed 11
tournament 2
\ No newline at end of file
#!/bin/bash
# cleanup
if stat -t *_results.dat* >/dev/null 2>&1
then
rm *_results.dat*
fi
if stat -t PISA_* >/dev/null 2>&1
then
rm PISA_*
fi
if stat -t *.trace.* >/dev/null 2>&1
then
rm *.trace.*
fi
folder=`date +'%d-%m-%Y-%H-%M'`
mpirun -np 6 ${OPT_BUILD_DIR}/Drivers/pisa-standalone/pisa-standalone.exe \
--inputfile=Problem.in --outfile=results.dat --outdir=./$folder \
--maxGenerations=10000 --initialPopulation=100 \
--expected-hypervol=0.6575 --epsilon=2e-4 --one-pilot-converge=1 \
--num-masters=2 --num-coworkers=1 --sol-synch=100 \
--selector=${OPT_BUILD_DIR}/extlib/nsga2/nsga2
add_subdirectory( wfgHypervolume )
add_subdirectory( nsga2 )
add_executable(nsga2 nsga2.c nsga2_functions.c nsga2_io.c)
target_link_libraries( nsga2 "-lm")
alpha 20
mu 10
lambda 10
dim 2
/*========================================================================
PISA (www.tik.ee.ethz.ch/pisa/)
========================================================================
Computer Engineering (TIK)
ETH Zurich
========================================================================
NSGA2
Implementation in C for the selector side.
Implements Petri net.
file: nsga2.c
author: Marco Laumanns, laumanns@tik.ee.ethz.ch
revision by: Stefan Bleuler, bleuler@tik.ee.ethz.ch
last change: $date$
========================================================================
*/
/* CAUTION: <unistd.h> is not standard C
It is used only for sleep() and usleep() in wait().
In Windows use Sleep() in <windows.h> or implement busy waiting.
*/
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <math.h>
#include "nsga2.h"
#ifdef PISA_UNIX
#include <unistd.h>
#endif
#ifdef PISA_WIN
#include <windows.h>
#endif
/*------------------------------| main() |-------------------------------*/
int main(int argc, char* argv[])
{
/* command line parameters */
char paramfile[FILE_NAME_LENGTH]; /* file with local parameters */
char filenamebase[FILE_NAME_LENGTH]; /* filename base,
e.g., "dir/test." */
double poll = 1.0; /* polling interval in seconds */
/* other variables */
int state = -1;
char *statefile;
int result;
/* reading command line parameters */
if (argc != 4)
PISA_ERROR("Selector: wrong number of arguments");
sscanf(argv[1], "%s", paramfile);
sscanf(argv[2], "%s", filenamebase);
sscanf(argv[3], "%lf", &poll);
/* generate name of statefile */
asprintf(&statefile, "%ssta", filenamebase);
/* main loop */
while (state != 6) /* stop state for selector */
/* Caution: if reading of the statefile fails
(e.g. no permission) this is an infinite loop */
{
state = read_flag(statefile);
if (state == 1) /* inital selection */
{
initialize(paramfile, filenamebase);
result = read_ini(); /* read ini file */
if (result == 0) /* reading ini file successful */
{
select_initial(); /* do selection */
write_arc(); /* write arc file (all individuals
that could ever be used again) */
write_sel(); /* write sel file */
state = 2;
write_flag(statefile, state);
} /* else don't do anything and wait again */
}
else if (state == 3) /* selection */
{
if(check_arc() == 0 && check_sel() == 0)
{
result = read_var(); /* read var file */
if (result == 0) /*reading var file successful */
{
select_normal(); /* do selection */
write_arc(); /* write arc file (all individuals
that could ever be used again) */
write_sel(); /* write sel file */
state = 2;
write_flag(statefile, state);
} /* else don't do anything and wait again */
else
printf("read_var failed\n");
} /* else don't do anything and wait again */
}
else if (state == 5) /* variator just terminated,
here you can do what you want */
{
state = 6; /* e.g., terminate too */
write_flag(statefile, state);
}
else if (state == 9) /* variator ready for reset,
here you can do what you want */
{
state = 10; /* e.g., get ready for reset too */
write_flag(statefile, state);
}
else if (state == 10) /* reset */
{
free_memory();
state = 11;
write_flag(statefile, state);
}
else /* state == -1 (reading failed) or state concerns variator */
{
nsga_wait(poll);
}
} /* state == 6 (stop) */
free_memory();
state = 7;
write_flag(statefile, state);
return (0);
}
/*--------------------| functions for control flow |---------------------*/
void write_flag(char* filename, int flag)
/* Write the state flag to given file. */
{
FILE *fp;
assert(0 <= flag && flag <= 11);
fp = fopen(filename, "w");
assert(fp != NULL);
fprintf(fp, "%d", flag);
fclose(fp);
}
int read_flag(char* filename)
/* Read state flag from given file. */
{
int result;
int flag = -1;
FILE *fp;
fp = fopen(filename, "r");
if (fp != NULL)
{
result = fscanf(fp, "%d", &flag);
fclose(fp);
if (result == 1) /* excatly one element read */
{
if (flag < 0 || flag > 11)
PISA_ERROR("Selector: Invalid state read from file.");
}
}
return (flag);
}
void nsga_wait(double sec)
/* Makes the calling process sleep. */
/* pre: sec >= 0.01 */
{
#ifdef PISA_UNIX
unsigned int int_sec;
unsigned int usec;
assert(sec > 0);
int_sec = (unsigned int) floor(sec);
usec = (unsigned int) floor((sec - floor(sec)) * 1e6);
/* split it up, usleep can fail if argument greater than 1e6 */
/* two asserts to make sure your file server doesn't break down */
assert(!((int_sec == 0) && (usec == 0))); /* should never be 0 */
assert((int_sec * 1e6) + usec >= 10000); /* you might change this one
if you know what you are
doing */
sleep(int_sec);
usleep(usec);
#endif
#ifdef PISA_WIN
unsigned int msec;
assert(sec > 0);
msec = (unsigned int) floor(sec * 1e3);
assert(msec >= 10); /* making sure we are really sleeping for some time*/
Sleep(msec);
#endif
}
/*========================================================================
PISA (www.tik.ee.ethz.ch/pisa/)
========================================================================
Computer Engineering (TIK)
ETH Zurich
========================================================================
NSGA2
Implementation in C for the selector side.
Header file.
file: nsga2.h
author: Marco Laumanns, laumanns@tik.ee.ethz.ch
revision by: Stefan Bleuler, bleuler@tik.ee.ethz.ch
last change: $date$
========================================================================
*/
#ifndef NSGA2_H
#define NSGA2_H
/*-----------------------| specify Operating System |------------------*/
/* necessary for wait() */
/* #define PISA_WIN */
#define PISA_UNIX
/*----------------------------| macro |----------------------------------*/
#define PISA_ERROR(x) fprintf(stderr, "\nError: " x "\n"), fflush(stderr), exit(EXIT_FAILURE)
/*---------------------------| constants |-------------------------------*/
#define FILE_NAME_LENGTH 128 /* maximal length of filenames */
#define CFG_ENTRY_LENGTH 128 /* maximal length of entries in cfg file */
#define PISA_MAXDOUBLE 1E99 /* Internal maximal value for double */
/*----------------------------| structs |--------------------------------*/
typedef struct ind_st /* an individual */
{
int index;
double *f; /* objective vector */
double fitness;
} ind;
typedef struct pop_st /* a population */
{
int size;
int maxsize;
ind **ind_array;
} pop;
/*-------------| functions for control flow (in nsga2.c) |------------*/
void write_flag(char *filename, int flag);
int read_flag(char *filename);
void nsga_wait(double sec);
/*---------| initialization function (in nsga2_functions.c) |---------*/
void initialize(char *paramfile, char *filenamebase);
/*--------| memory allocation functions (in nsga2_functions.c) |------*/
void* chk_malloc(size_t size);
pop* create_pop(int size, int dim);
ind* create_ind(int dim);
void free_memory(void);
void free_pop(pop *pp);
void complete_free_pop(pop *pp);
void free_ind(ind *p_ind);
/*-----| functions implementing the selection (nsga2_functions.c) |---*/
void selection();
void mergeOffspring();
void calcFitnesses();
void calcDistances();
int getNN(int index, int k);
double getNNd(int index, int k);
void environmentalSelection();
void truncate_nondominated();
void truncate_dominated();
void matingSelection();
void select_initial();
void select_normal();
int dominates(ind *p_ind_a, ind *p_ind_b);
int is_equal(ind *p_ind_a, ind *p_ind_b);
double calcDistance(ind *p_ind_a, ind *p_ind_b);
int irand(int range);
/*--------------------| data exchange functions |------------------------*/
/* in nsga2_functions.c */
int read_ini(void);
int read_var(void);
void write_sel(void);
void write_arc(void);
int check_sel(void);
int check_arc(void);
/* in nsga2_io.c */
int read_pop(char *filename, pop *pp, int size, int dim);
void write_pop(char *filename, pop *pp, int size);
int check_file(char *filename);
#endif /* NSGA2_H */
========================================================================
PISA (www.tik.ee.ethz.ch/pisa/)
========================================================================
Computer Engineering (TIK)
ETH Zurich
========================================================================
NSGA2 - Nondominated Sorting GA II
Implementation in C for the selector side.
Documentation
file: nsga2_documentation.txt
author: Marco Laumanns, laumanns@tik.ee.ethz.ch
last change: $date$
========================================================================
The Optimizer
=============
NSGA2 in an elitist multiobjective evolutionary algorithm and has been
proposed by Prof. Kalyanmoy Deb at the KanGAL. Here, we present a
PISA-implementation of the algorithm based on the description in the
cited paper.
@InProceedings{DAPM2000,
author = {K. Deb and Samir Agrawal and Amrit Pratap and T. Meyarivan},
title = {A Fast Elitist Non-Dominated Sorting Genetic Algorithm for
Multi-Objective Optimization: {NSGA-II}},
booktitle = {Parallel Problem Solving from Nature -- {PPSN VI}},
pages = {849--858},
year = {2000},
editor = {Marc Schoenauer and K. Deb and G.
Rudolph and Xin Yao and Evelyne Lutton and Juan
Julian Merelo and Hans-Paul Schwefel},
address = {Berlin},
publisher = {Springer}
}
The Parameters
==============
NSGA2 uses the following values for the common parameters.
These parameters are specified in 'PISA_cfg'.
alpha (population size)
mu (number of parent individuals)
lambda (number of offspring individuals)
dim (number of objectives)
NSGA2 takes two local parameter which is given in a parameter
file. The name of this parameter file is passed to NSGA2 as command
line argument. (See 'nsga2_param.txt' for an example.)
seed (seed for the random number generator)
tournament (tournament size for mating selection)
Source Files
============
The source code for LOTZ is divided into four files:
'nsga2.h' is the header file.
'nsga2.c' contains the main function and implements the control flow.
'nsga2_io.c' implements the file i/o functions.
'nsga2_functions.c' implements all other functions including the
selection.