From 406298b68bd0f21efb8ea0cd34c3b2bfebae049e Mon Sep 17 00:00:00 2001 From: Francesco Biscani Date: Mon, 15 Dec 2008 17:55:35 +0100 Subject: [PATCH] Update from Dario, SVN rev. 113. --- AstroToolbox/mga_dsm.cpp | 24 ++--- AstroToolbox/mga_dsm.h | 5 +- Functions/objfuns/trajobjfuns.cpp | 164 ++++++------------------------ Functions/objfuns/trajobjfuns.h | 1 - GOclasses/problems/TrajectoryProblems.cpp | 13 +-- GOclasses/problems/TrajectoryProblems.h | 36 +++---- main.cpp | 8 +- 7 files changed, 73 insertions(+), 178 deletions(-) diff --git a/AstroToolbox/mga_dsm.cpp b/AstroToolbox/mga_dsm.cpp index 86e2490..5e779d4 100644 --- a/AstroToolbox/mga_dsm.cpp +++ b/AstroToolbox/mga_dsm.cpp @@ -308,11 +308,10 @@ void final_block(const mgadsmproblem& problem, const std::vector& , con int MGA_DSM( /* INPUT values: */ //[MR] make this parameters const, if they are not modified and possibly references (especially 'problem'). vector t, // it is the vector which provides time in modified julian date 2000. [MR] ??? Isn't it the decision vetor ??? - mgadsmproblem problem, + mgadsmproblem& problem, /* OUTPUT values: */ - double &J, // output - double *DVvec // output + double &J // output ) { //[MR] A bunch of helper variables to simplify the code @@ -320,12 +319,12 @@ int MGA_DSM( int i; //loop counter - //References to objects pre-allocated in the mgadsm struct + //References to objects pre-allocated in the mgadsm struct std::vector& r = problem.r; std::vector& v = problem.v; std::vector& DV = problem.DV; //DV contributions - + precalculate_ers_and_vees(t, problem, r, v); double inter_pl_in_v[3], inter_pl_out_v[3]; //inter-hop velocities @@ -361,12 +360,13 @@ int MGA_DSM( // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% //[MR] Calculation of the actual procedure output (DVvec and J) - const double VINF = t[1]; // Hyperbolic escape velocity (km/sec) + const double& VINF = t[1]; // Variable renaming: Hyperbolic escape velocity (km/sec) - DVvec[0] = VINF; - for (i = 1; i < n + 1; i++) { - DVvec[i] = DV[i - 1]; + for (i = n; i > 0; i--) { + DV[i] = DV[i - 1]; } + DV[0] = VINF; + // Finally our objective function (J) is: @@ -455,14 +455,14 @@ int MGA_DSM( double sum = 0.0; for (i=0; i DVtotal) DVpen += DVpen+(sum-DVtotal); sum = 0.0; for (i=1; i DVonboard) DVpen = DVpen + (sum - DVonboard); @@ -475,7 +475,7 @@ int MGA_DSM( } else J = 100000; // there was an ERROR in time2distance - } // time2AU + } // time2AU return 0; } diff --git a/AstroToolbox/mga_dsm.h b/AstroToolbox/mga_dsm.h index f9dd940..f64737c 100644 --- a/AstroToolbox/mga_dsm.h +++ b/AstroToolbox/mga_dsm.h @@ -35,11 +35,10 @@ struct mgadsmproblem { int MGA_DSM( /* INPUT values: */ std::vector x , // it is the decision vector - mgadsmproblem, // contains the problem specific data + mgadsmproblem &mgadsm, // contains the problem specific data /* OUTPUT values: */ - double& J, // J output - double* DVVec// DVVec + double &J // J output ); #endif diff --git a/Functions/objfuns/trajobjfuns.cpp b/Functions/objfuns/trajobjfuns.cpp index 91f924d..cd0d2e6 100644 --- a/Functions/objfuns/trajobjfuns.cpp +++ b/Functions/objfuns/trajobjfuns.cpp @@ -7,23 +7,22 @@ * */ -#include +#include + #include "mga.h" #include "mga_dsm.h" #include "misc4Tandem.h" - using namespace std; double messenger(const vector& x){ - double Delta_V[6]; mgadsmproblem problem; int sequence_[5] = {3, 3, 2, 2, 1}; // sequence of planets problem.sequence.insert(problem.sequence.begin(), sequence_, sequence_+ 5 ); problem.type = total_DV_rndv; - - + + //Memory allocation problem.r = std::vector(5); problem.v = std::vector(5); @@ -32,7 +31,7 @@ double messenger(const vector& x){ problem.r[i] = new double[3]; problem.v[i] = new double[3]; } - + double obj = 0; @@ -42,9 +41,9 @@ double messenger(const vector& x){ problem, /* OUTPUT values: */ - obj, Delta_V); - - + obj); + + //Memory release for(int i = 0; i < 5; i++) { delete[] problem.r[i]; @@ -52,13 +51,12 @@ double messenger(const vector& x){ } problem.r.clear(); problem.v.clear(); - - + + return obj; } double cassini2(const vector& x){ - double Delta_V[7]; mgadsmproblem problem; int sequence_[6] = {3, 2, 2, 3, 5, 6}; // sequence of planets @@ -66,18 +64,18 @@ double cassini2(const vector& x){ problem.type = total_DV_rndv; double obj = 0; - + //Allocate temporary memory for MGA_DSM problem.r = std::vector(6); problem.v = std::vector(6); problem.DV = std::vector(6+1); - + for(int i = 0; i < 6; i++) { problem.r[i] = new double[3]; problem.v[i] = new double[3]; } - + MGA_DSM( /* INPUT values: */ @@ -85,8 +83,8 @@ double cassini2(const vector& x){ problem, /* OUTPUT values: */ - obj, Delta_V); - + obj); + //Free temporary memory for MGA_DSM for(int i = 0; i < 6; i++) { @@ -95,13 +93,12 @@ double cassini2(const vector& x){ } problem.r.clear(); problem.v.clear(); - - + + return obj; } double rosetta(const vector& x){ - double Delta_V[7]; mgadsmproblem problem; int sequence_[6] = {3, 3, 4, 3, 3, 10}; // sequence of planets @@ -115,18 +112,18 @@ double rosetta(const vector& x){ problem.asteroid.keplerian[5] = 0.0; problem.asteroid.epoch = 52504.23754000012; problem.asteroid.mu = 0.0; - + //Allocate temporary memory for MGA_DSM problem.r = std::vector(6); problem.v = std::vector(6); problem.DV = std::vector(6+1); - + for(int i = 0; i < 6; i++) { problem.r[i] = new double[3]; problem.v[i] = new double[3]; } - + double obj = 0; @@ -136,8 +133,8 @@ double rosetta(const vector& x){ problem, /* OUTPUT values: */ - obj, Delta_V); - + obj); + //Free temporary memory for MGA_DSM for(int i = 0; i < 6; i++) { @@ -146,114 +143,12 @@ double rosetta(const vector& x){ } problem.r.clear(); problem.v.clear(); - - - return obj; -} -double tandem(const vector& x){ - const int seqlen = 5; - const int sequence_[seqlen] = {3, 2, 3, 3, 6}; // sequence of planets - double Delta_V[seqlen+1]; - double obj = 0; - mgadsmproblem problem; - - //defining the problem - problem.sequence.insert(problem.sequence.begin(), sequence_, sequence_+ seqlen ); - problem.type = orbit_insertion; - problem.rp = 80330.0; - problem.e = 0.98531407996358; - - - //Allocate temporary memory for MGA_DSM - problem.r = std::vector(seqlen); - problem.v = std::vector(seqlen); - problem.DV = std::vector(seqlen+1); - - for(int i = 0; i < seqlen; i++) { - problem.r[i] = new double[3]; - problem.v[i] = new double[3]; - } - - - //calling mgadsm - MGA_DSM(x,problem,obj,Delta_V); - - //evaluating the mass from the dvs - double rE[3]; - double vE[3]; - Planet_Ephemerides_Analytical (x[0],3,rE,vE); - double VINFE = x[1]; - double udir = x[2]; - double vdir = x[3]; - double vtemp[3]; - vtemp[0]= rE[1]*vE[2]-rE[2]*vE[1]; - vtemp[1]= rE[2]*vE[0]-rE[0]*vE[2]; - vtemp[2]= rE[0]*vE[1]-rE[1]*vE[0]; - double iP1[3]; - double normvE=sqrt(vE[0]*vE[0]+vE[1]*vE[1]+vE[2]*vE[2]); - iP1[0]= vE[0]/normvE; - iP1[1]= vE[1]/normvE; - iP1[2]= vE[2]/normvE; - double zP1[3]; - double normvtemp=sqrt(vtemp[0]*vtemp[0]+vtemp[1]*vtemp[1]+vtemp[2]*vtemp[2]); - zP1[0]= vtemp[0]/normvtemp; - zP1[1]= vtemp[1]/normvtemp; - zP1[2]= vtemp[2]/normvtemp; - double jP1[3]; - jP1[0]= zP1[1]*iP1[2]-zP1[2]*iP1[1]; - jP1[1]= zP1[2]*iP1[0]-zP1[0]*iP1[2]; - jP1[2]= zP1[0]*iP1[1]-zP1[1]*iP1[0]; - double theta=2*M_PI*udir; //See Picking a Point on a Sphere - double phi=acos(2*vdir-1)-M_PI/2; //In this way: -pi/23652.5)|| (totaltime<3287.25)) { - // m_final = 0; - //} - //else { - m_final = m_initial * exp(-sumDVvec/Isp/g0*1000); - //} - //return (2000-m_final)/1000; - //return -log(m_final/m_initial)*Isp*g0/1000; - - - //Free temporary memory for MGA_DSM - for(int i = 0; i < seqlen; i++) { - delete[] problem.r[i]; - delete[] problem.v[i]; - } - problem.r.clear(); - problem.v.clear(); - - - return -log(m_final); + return obj; } + double gtoc1( const vector& x) { const int GTOC1_DIM = 8; @@ -323,7 +218,6 @@ double cassini1( const vector& x) } double sagas(const vector& x){ - double Delta_V[4]; mgadsmproblem problem; int sequence_[3] = {3,3,5}; // sequence of planets @@ -332,13 +226,13 @@ double sagas(const vector& x){ problem.AUdist = 50.0; problem.DVtotal = 6.782; problem.DVonboard = 1.782; - + //Allocate temporary memory for MGA_DSM problem.r = std::vector(3); problem.v = std::vector(3); problem.DV = std::vector(3+1); - + for(int i = 0; i < 3; i++) { problem.r[i] = new double[3]; problem.v[i] = new double[3]; @@ -353,8 +247,8 @@ double sagas(const vector& x){ problem, /* OUTPUT values: */ - obj, Delta_V); - + obj); + //Free temporary memory for MGA_DSM for(int i = 0; i < 3; i++) { @@ -363,7 +257,7 @@ double sagas(const vector& x){ } problem.r.clear(); problem.v.clear(); - + return obj; } diff --git a/Functions/objfuns/trajobjfuns.h b/Functions/objfuns/trajobjfuns.h index 80b8d08..8556d5a 100644 --- a/Functions/objfuns/trajobjfuns.h +++ b/Functions/objfuns/trajobjfuns.h @@ -16,7 +16,6 @@ double messenger (const std::vector& x); double rosetta (const std::vector& x); -double tandem (const std::vector& x); double gtoc1 (const std::vector& x); double cassini1 (const std::vector& x); double cassini2 (const std::vector& x); diff --git a/GOclasses/problems/TrajectoryProblems.cpp b/GOclasses/problems/TrajectoryProblems.cpp index 7566cc1..3b6bbcd 100644 --- a/GOclasses/problems/TrajectoryProblems.cpp +++ b/GOclasses/problems/TrajectoryProblems.cpp @@ -52,7 +52,7 @@ messengerProb::~messengerProb() { double messengerProb::objfun(const std::vector& x) { double obj = 0.0; MGA_DSM(x, mgadsm, - obj, Delta_V); + obj); return obj; } @@ -103,7 +103,7 @@ tandemProb::~tandemProb() { double tandemProb::objfun(const std::vector& x) { double obj = 0; - MGA_DSM(x, mgadsm, obj, Delta_V); + MGA_DSM(x, mgadsm, obj); //evaluating the mass from the dvs double rE[3]; @@ -152,7 +152,7 @@ double tandemProb::objfun(const std::vector& x) { double sumDVvec=0; //double totaltime=x[4]+x[5]+x[6]+x[7]; for(unsigned int i=1;i<=5;i++) { - sumDVvec=sumDVvec+Delta_V[i]; + sumDVvec=sumDVvec+mgadsm.DV[i]; } double m_final; sumDVvec=sumDVvec+0.165; //losses for 3 swgbys + insertion @@ -162,6 +162,7 @@ double tandemProb::objfun(const std::vector& x) { return -log(m_final); } + cassini1Prob::cassini1Prob(){ setDimension(6); //cassini1 bounds @@ -223,7 +224,7 @@ cassini2Prob::~cassini2Prob() { double cassini2Prob::objfun(const std::vector& x) { double obj = 0; MGA_DSM(x, mgadsm, - obj, Delta_V); + obj); return obj; } @@ -271,7 +272,7 @@ rosettaProb::~rosettaProb() { double rosettaProb::objfun(const std::vector& x) { double obj = 0; MGA_DSM(x, mgadsm, - obj, Delta_V); + obj); return obj; } @@ -314,7 +315,7 @@ sagasProb::~sagasProb() { double sagasProb::objfun(const std::vector& x) { double obj = 0; MGA_DSM(x, mgadsm, - obj, Delta_V); + obj); return obj; } diff --git a/GOclasses/problems/TrajectoryProblems.h b/GOclasses/problems/TrajectoryProblems.h index 5cff10f..51086d6 100644 --- a/GOclasses/problems/TrajectoryProblems.h +++ b/GOclasses/problems/TrajectoryProblems.h @@ -17,7 +17,25 @@ #include "misc4Tandem.h" //*********************************************************************************** -//Trajectory problems +//Trajectory problems MGA +//*********************************************************************************** + +class cassini1Prob : public GOProblem { +public: + cassini1Prob(); + virtual double objfun(const std::vector&); +}; //end class cassini1Prob + +class gtoc1Prob : public GOProblem { +public: + gtoc1Prob(); + virtual double objfun(const std::vector&); +}; //end class gtoc1Prob + + + +//*********************************************************************************** +//Trajectory problems MGA-1DSM //*********************************************************************************** class messengerProb : public GOProblem { @@ -28,7 +46,6 @@ public: private: mgadsmproblem mgadsm; - double Delta_V[6]; //Dummy array, required for calling MGA_DSM }; //end class messengerProb class tandemProb : public GOProblem { @@ -38,20 +55,8 @@ public: virtual double objfun(const std::vector&); private: mgadsmproblem mgadsm; - double Delta_V[6]; //Dummy array, required for calling MGA_DSM }; //end class tandemProb -class cassini1Prob : public GOProblem { -public: - cassini1Prob(); - virtual double objfun(const std::vector&); -}; //end class cassini1Prob - -class gtoc1Prob : public GOProblem { -public: - gtoc1Prob(); - virtual double objfun(const std::vector&); -}; //end class gtoc1Prob class cassini2Prob : public GOProblem { public: @@ -60,7 +65,6 @@ public: virtual double objfun(const std::vector&); private: mgadsmproblem mgadsm; - double Delta_V[7]; //Dummy array, required for calling MGA_DSM }; //end class cassini1Prob class rosettaProb : public GOProblem { @@ -69,7 +73,6 @@ public: virtual ~rosettaProb(); virtual double objfun(const std::vector&); private: - double Delta_V[7]; mgadsmproblem mgadsm; }; //end class rosettaProb @@ -79,7 +82,6 @@ public: virtual ~sagasProb(); virtual double objfun(const std::vector&); private: - double Delta_V[4]; mgadsmproblem mgadsm; }; //end class sagasProb diff --git a/main.cpp b/main.cpp index 71c07fb..0a8c18d 100644 --- a/main.cpp +++ b/main.cpp @@ -29,7 +29,7 @@ int main(){ Pk::Random32 rng(time(0)); //we set the problem - tandemProb problem; + messengerProb problem; //we extract its information into local variables const vector& LB = problem.getLB(); const vector& UB = problem.getUB(); @@ -60,11 +60,11 @@ while (choice != -1) { { //Experiment Settings int NP = 1; //population size - int trials = 100; //number of trials + int trials = 20; //number of trials int niterTot = 10000; //generations per algorithm call int niterRange = 20; int niterTemp = 1; - double T0 = 1; + double T0 = 5; double Tcoeff = 0.77; double StartStep =1; @@ -481,7 +481,7 @@ while (choice != -1) { double F = 0.8; //F in DE double CR = 0.8; //CR in DE int strategy = 2; //DE startegy - int islandsN = 5; //Number of Islands + int islandsN = 1; //Number of Islands //stopping criteria int itermax = 120; //Maximum number of iterations allowed (i.e. output printed on the screen) -- 2.11.4.GIT