Skip to content
Snippets Groups Projects
Commit 6f7429e1 authored by Miroslav Shaltev's avatar Miroslav Shaltev
Browse files

initial commit using version 3.6.1

parents
No related branches found
No related tags found
No related merge requests found
Showing
with 411 additions and 0 deletions
EXE = basic_lib.exe
EXE_MPI = basic_lib_MPI.exe
COMPILATOR = g++
COMPILATOR_MPI = mpic++
SUNAME = $(shell uname)
OSS=$(findstring MINGW32,$(SUNAME))
ifneq "$(strip $(OSS))" ""
COMPILATOR_MPI = g++
endif
COMPILATOR_OPTIONS = -O2 -ansi
COMPILATOR_OPTIONS_MPI = $(COMPILATOR_OPTIONS) -DUSE_MPI
L1 = $(NOMAD_HOME)/lib/nomad.a
L1_MPI = $(NOMAD_HOME)/lib/nomad.MPI.a
LIBS = $(L1) -lm
LIBS_MPI = $(L1_MPI) -lm -lmpi
INCLUDE = -I$(NOMAD_HOME)/src -I.
COMPILE = $(COMPILATOR) $(COMPILATOR_OPTIONS) $(INCLUDE) -c
COMPILE_MPI = $(COMPILATOR_MPI) $(COMPILATOR_OPTIONS_MPI) $(INCLUDE) -c
OBJS = basic_lib.o
OBJS_MPI = basic_lib_MPI.o
ifndef NOMAD_HOME
define ECHO_NOMAD
@echo Please set NOMAD_HOME environment variable!
@false
endef
endif
$(EXE): $(L1) $(OBJS)
$(ECHO_NOMAD)
@echo " building the scalar version ..."
@echo " exe file : "$(EXE)
@$(COMPILATOR) -o $(EXE) $(OBJS) $(LIBS) $(COMPILATOR_OPTIONS)
@strip $(EXE)
$(EXE_MPI): $(L1_MPI) $(OBJS_MPI)
$(ECHO_NOMAD)
@echo " building the MPI version ..."
@echo " exe file : "$(EXE_MPI)
@$(COMPILATOR_MPI) -o $(EXE_MPI) $(OBJS_MPI) $(LIBS_MPI) $(COMPILATOR_OPTIONS_MPI)
@strip $(EXE_MPI)
basic_lib.o: basic_lib.cpp
$(ECHO_NOMAD)
@$(COMPILE) basic_lib.cpp
basic_lib_MPI.o: basic_lib.cpp
$(ECHO_NOMAD)
@$(COMPILE_MPI) basic_lib.cpp -o basic_lib_MPI.o
$(L1) $(L1_MPI): ;
$(ECHO_NOMAD)
mpi: $(EXE_MPI)
all: $(EXE) $(EXE_MPI)
clean: ;
@echo " cleaning obj files"
@rm -f $(OBJS) $(OBJS_MPI)
del: ;
@echo " cleaning trash files"
@rm -f core *~
@echo " cleaning obj files"
@rm -f $(OBJS) $(OBJS_MPI)
@echo " cleaning exe file"
@rm -f $(EXE) $(EXE_MPI)
multi-MADS run {
MADS run 1 ...... OK [bb eval= 46] [overall bb eval= 46] [# dominant pts= 3] [# new pts= 3] [f1=-6 f2=94.436255]
MADS run 2 ...... OK [bb eval= 23] [overall bb eval= 69] [# dominant pts= 3] [# new pts= 0] [f1=-4.5 f2=16.5199438]
MADS run 3 ...... OK [bb eval= 23] [overall bb eval= 92] [# dominant pts= 3] [# new pts= 0] [f1=-5.25 f2=15.24515131]
MADS run 4 ...... OK [bb eval= 8] [overall bb eval= 100] [# dominant pts= 3] [# new pts= 0] [f1=-5.25 f2=15.24515131]
} end of run (max number of bb evaluations)
blackbox evaluations : 100
number of MADS runs : 4
Pareto front {
-6.0000000000 25.1826513073
-5.2500000000 15.2451513073
0.7500000000 12.8461452933
}
number of Pareto points: 3
/*-----------------------------------------------------*/
/* how to use the NOMAD library with a user function */
/*-----------------------------------------------------*/
#include "nomad.hpp"
using namespace std;
// using namespace NOMAD; avoids putting NOMAD:: everywhere
/*----------------------------------------*/
/* The problem */
/*----------------------------------------*/
class My_Evaluator : public NOMAD::Evaluator {
public:
My_Evaluator ( const NOMAD::Parameters & p ) :
NOMAD::Evaluator ( p ) {}
~My_Evaluator ( void ) {}
bool eval_x ( NOMAD::Eval_Point & x ,
const NOMAD::Double & h_max ,
bool & count_eval ) const
{
NOMAD::Double c1 = 0.0 , c2 = 0.0;
for ( int i = 0 ; i < 5 ; i++ )
{
c1 += (x[i]-1).pow2();
c2 += (x[i]+1).pow2();
}
x.set_bb_output ( 0 , x[4] ); // objective value
x.set_bb_output ( 1 , c1-25 ); // constraint 1
x.set_bb_output ( 2 , 25-c2 ); // constraint 2
count_eval = true; // count a black-box evaluation
return true; // the evaluation succeeded
}
};
/*------------------------------------------*/
/* NOMAD main function */
/*------------------------------------------*/
int main ( int argc , char ** argv ) {
// display:
NOMAD::Display out ( std::cout );
out.precision ( NOMAD::DISPLAY_PRECISION_STD );
try {
// NOMAD initializations:
NOMAD::begin ( argc , argv );
NOMAD::RNG::set_seed(12345);
// parameters creation:
NOMAD::Parameters p ( out );
p.set_DIMENSION (5); // number of variables
vector<NOMAD::bb_output_type> bbot (3); // definition of
bbot[0] = NOMAD::OBJ; // output types
bbot[1] = NOMAD::PB;
bbot[2] = NOMAD::EB;
p.set_BB_OUTPUT_TYPE ( bbot );
//p.set_DISPLAY_ALL_EVAL(true); // displays all evaluations.
p.set_DISPLAY_STATS ( "bbe ( sol ) obj" );
p.set_X0 ( NOMAD::Point(5,0.0) ); // starting point
p.set_LOWER_BOUND ( NOMAD::Point ( 5 , -6.0 ) ); // all var. >= -6
NOMAD::Point ub ( 5 ); // x_4 and x_5 have no bounds
ub[0] = 5.0; // x_1 <= 5
ub[1] = 6.0; // x_2 <= 6
ub[2] = 7.0; // x_3 <= 7
p.set_UPPER_BOUND ( ub );
p.set_MAX_BB_EVAL (100); // the algorithm terminates after
// 100 black-box evaluations
// p.set_TMP_DIR ("/tmp"); // directory for temporary files
// parameters validation:
p.check();
// custom evaluator creation:
My_Evaluator ev ( p );
// algorithm creation and execution:
NOMAD::Mads mads ( p , &ev );
mads.run();
}
catch ( exception & e ) {
cerr << "\nNOMAD has been interrupted (" << e.what() << ")\n\n";
}
NOMAD::Slave::stop_slaves ( out );
NOMAD::end();
return EXIT_SUCCESS;
}
EXE = basic_lib.exe
EXE_MPI = basic_lib_MPI.exe
COMPILATOR = g++
COMPILATOR_MPI = mpic++
SUNAME = $(shell uname)
OSS=$(findstring MINGW32,$(SUNAME))
ifneq "$(strip $(OSS))" ""
COMPILATOR_MPI = g++
endif
COMPILATOR_OPTIONS = -O2 -ansi
COMPILATOR_OPTIONS_MPI = $(COMPILATOR_OPTIONS) -DUSE_MPI
L1 = $(NOMAD_HOME)/lib/nomad.a
L1_MPI = $(NOMAD_HOME)/lib/nomad.MPI.a
LIBS = $(L1) -lm
LIBS_MPI = $(L1_MPI) -lm -lmpi
INCLUDE = -I$(NOMAD_HOME)/src -I.
COMPILE = $(COMPILATOR) $(COMPILATOR_OPTIONS) $(INCLUDE) -c
COMPILE_MPI = $(COMPILATOR_MPI) $(COMPILATOR_OPTIONS_MPI) $(INCLUDE) -c
OBJS = basic_lib.o
OBJS_MPI = basic_lib_MPI.o
ifndef NOMAD_HOME
define ECHO_NOMAD
@echo Please set NOMAD_HOME environment variable!
@false
endef
endif
$(EXE): $(L1) $(OBJS)
$(ECHO_NOMAD)
@echo " building the scalar version ..."
@echo " exe file : "$(EXE)
@$(COMPILATOR) -o $(EXE) $(OBJS) $(LIBS) $(COMPILATOR_OPTIONS)
@strip $(EXE)
$(EXE_MPI): $(L1_MPI) $(OBJS_MPI)
$(ECHO_NOMAD)
@echo " building the MPI version ..."
@echo " exe file : "$(EXE_MPI)
@$(COMPILATOR_MPI) -o $(EXE_MPI) $(OBJS_MPI) $(LIBS_MPI) $(COMPILATOR_OPTIONS_MPI)
@strip $(EXE_MPI)
basic_lib.o: basic_lib.cpp
$(ECHO_NOMAD)
@$(COMPILE) basic_lib.cpp
basic_lib_MPI.o: basic_lib.cpp
$(ECHO_NOMAD)
@$(COMPILE_MPI) basic_lib.cpp -o basic_lib_MPI.o
$(L1) $(L1_MPI): ;
$(ECHO_NOMAD)
mpi: $(EXE_MPI)
all: $(EXE) $(EXE_MPI)
clean: ;
@echo " cleaning obj files"
@rm -f $(OBJS) $(OBJS_MPI)
del: ;
@echo " cleaning trash files"
@rm -f core *~
@echo " cleaning obj files"
@rm -f $(OBJS) $(OBJS_MPI)
@echo " cleaning exe file"
@rm -f $(EXE) $(EXE_MPI)
MADS run {
BBE ( SOL ) OBJ
2 ( 1.1000000000 0.0000000000 0.0000000000 0.0000000000 0.0000000000 ) 275.2281000000 (PhaseOne)
3 ( 4.4000000000 0.0000000000 0.0000000000 0.0000000000 0.0000000000 ) 0.0000000000 (PhaseOne)
3 ( 4.4000000000 0.0000000000 0.0000000000 0.0000000000 0.0000000000 ) 0.0000000000
11 ( 4.6750000000 0.9000000000 0.9750000000 1.5000000000 -1.5000000000 ) -1.5000000000
55 ( 1.6500000000 1.8000000000 1.9500000000 -1.5000000000 -3.0000000000 ) -3.0000000000
100 ( 1.6500000000 1.8000000000 1.9500000000 -1.5000000000 -3.0000000000 ) -3.0000000000
} end of run (max number of blackbox evaluations)
blackbox evaluations : 100
best infeasible solution (min. violation): ( 0.55 1.8 2.6 -1.5 -3 ) h=0.6525 f=-3
best feasible solution : ( 1.65 1.8 1.95 -1.5 -3 ) h=0 f=-3
This diff is collapsed.
LIBAMPL_DIR = $(LIBAMPLDIR)
CXX = gcc -std=c99
INCLUDE_DIRS = $(LIBAMPL_DIR)/Src/solvers
CXX_OPTS = $(addprefix -I,$(INCLUDE_DIRS))
LIBS = -L$(LIBAMPL_DIR)/Lib -lampl -lfuncadd0 -lm -ldl
%.o: %.c
$(CXX) -c $(CXX_OPTS) $?
bb.exe: bb.o
$(CXX) -o $@ $? $(LIBS)
clean:
rm *.o miniampl
set A; # asset categories
set T := {1973..1994}; # years
param r_min default 1.10; # i.e., at least 10 percent return
param R {T,A};
param mean {j in A}
:= ( sum{i in T} R[i,j] )/card(T);
param Rtilde {i in T, j in A}
:= R[i,j] - mean[j];
param Cov {j in A, k in A}
:= sum {i in T} (Rtilde[i,j]*Rtilde[i,k]) / card(T);
param Corr {j in A, k in A}
:= Cov[j,k]/sqrt(Cov[j,j]*Cov[k,k]);
var x{A} >=0;
minimize risk:
sum{i in T} (sum{j in A} Rtilde[i,j]*x[j])^2 / card{T} ;
subject to reward_bound:
r_min <= sum{j in A} mean[j]*x[j];
subject to tot_mass:
sum{j in A} x[j] = 1;
data;
set A :=
US_3-MONTH_T-BILLS US_GOVN_LONG_BONDS SP_500 WILSHIRE_5000 NASDAQ_COMPOSITE
LEHMAN_BROTHERS_CORPORATE_BONDS_INDEX EAFE GOLD;
param R:
US_3-MONTH_T-BILLS US_GOVN_LONG_BONDS SP_500 WILSHIRE_5000 NASDAQ_COMPOSITE
LEHMAN_BROTHERS_CORPORATE_BONDS_INDEX EAFE GOLD :=
1973 1.075 0.942 0.852 0.815 0.698 1.023 0.851 1.677
1974 1.084 1.020 0.735 0.716 0.662 1.002 0.768 1.722
1975 1.061 1.056 1.371 1.385 1.318 1.123 1.354 0.760
1976 1.052 1.175 1.236 1.266 1.280 1.156 1.025 0.960
1977 1.055 1.002 0.926 0.974 1.093 1.030 1.181 1.200
1978 1.077 0.982 1.064 1.093 1.146 1.012 1.326 1.295
1979 1.109 0.978 1.184 1.256 1.307 1.023 1.048 2.212
1980 1.127 0.947 1.323 1.337 1.367 1.031 1.226 1.296
1981 1.156 1.003 0.949 0.963 0.990 1.073 0.977 0.688
1982 1.117 1.465 1.215 1.187 1.213 1.311 0.981 1.084
1983 1.092 0.985 1.224 1.235 1.217 1.080 1.237 0.872
1984 1.103 1.159 1.061 1.030 0.903 1.150 1.074 0.825
1985 1.080 1.366 1.316 1.326 1.333 1.213 1.562 1.006
1986 1.063 1.309 1.186 1.161 1.086 1.156 1.694 1.216
1987 1.061 0.925 1.052 1.023 0.959 1.023 1.246 1.244
1988 1.071 1.086 1.165 1.179 1.165 1.076 1.283 0.861
1989 1.087 1.212 1.316 1.292 1.204 1.142 1.105 0.977
1990 1.080 1.054 0.968 0.938 0.830 1.083 0.766 0.922
1991 1.057 1.193 1.304 1.342 1.594 1.161 1.121 0.958
1992 1.036 1.079 1.076 1.090 1.174 1.076 0.878 0.926
1993 1.031 1.217 1.100 1.113 1.162 1.110 1.326 1.146
1994 1.045 0.889 1.012 0.999 0.968 0.965 1.078 0.990
;
solve;
display Corr;
printf: "-------------------------------------------------------------------\n";
printf: " Asset Mean Variance \n";
printf {j in A}: "%45s %10.7f %10.7f \n",
j, mean[j], sum{i in T} Rtilde[i,j]^2 / card(T);
printf: "\n";
printf: "Optimal Portfolio: Asset Fraction \n";
printf {j in A: x[j] > 0.001}: "%45s %10.7f \n", j, x[j];
printf: "Mean = %10.7f, Variance = %10.5f \n",
sum{j in A} mean[j]*x[j],
sum{i in T} (sum{j in A} Rtilde[i,j]*x[j])^2 / card(T);
This diff is collapsed.
DIMENSION 8
BB_EXE bb.exe
BB_OUTPUT_TYPE OBJ PB PB PB
x0 points/x0.txt
lower_bound points/lb.txt
upper_bound points/ub.txt
#tmp_dir /tmp
max_bb_eval 1000
h_min 0.05
#display_degree 2
0
0
0
0
0
0
0
0
1
1
1
1
1
1
1
1
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment