📄 call_glss_bak.cc
字号:
/******************************************************************** Call_glss: Invokes a GA-LS hybrid to try and solve the docking problem. rsh 9/95********************************************************************//*** $Log$*/#include <iostream.h>#include "gs.h"#include "ls.h"#include "support.h"#include "eval.h"#include "hybrids.h"#include "mpi.h"#ifdef sgi // CC on the sgi doesn't invoke cc on *.c files #include "constants.h" #include "structs.h" extern FILE *logFile;#else extern "C" { #include "constants.h" #include "structs.h" extern FILE *logFile; }#endifint global_ntor;Eval evaluate;Phenotype genPh_cs(const Phenotype &original,float *array1){ RepType genetype; register int i, index = 0; Phenotype retval(original);#ifdef DEBUG (void)fprintf(logFile, "ls.cc/Phenotype genPh(const Phenotype &original, float *array1, float *array2)\n");#endif /* DEBUG */ for (i=0; i<retval.num_pts(); i++) { genetype = retval.gtype(i); if ((genetype == T_RealV)||(genetype == T_CRealV)) { retval.write(array1[index] , i); index++; } } return(retval);}Representation **generate_R(int num_torsions, double xlo, double xhi, double ylo, double yhi, double zlo, double zhi){ Representation **retval; retval = new Representation *[5]; retval[0] = new RealVector(1, xlo, xhi); retval[1] = new RealVector(1, ylo, yhi); retval[2] = new RealVector(1, zlo, zhi); retval[3] = new RealVector(3); retval[4] = new RealVector(num_torsions+1); return(retval);}Genotype generate_Gtype(int num_torsions, double xlo, double xhi, double ylo, double yhi, double zlo, double zhi){ Genotype temp(5, generate_R(num_torsions, xlo, xhi, ylo, yhi, zlo, zhi)); return(temp);}Phenotype generate_Ptype(int num_torsions, double xlo, double xhi, double ylo, double yhi, double zlo, double zhi){ Phenotype temp(5, generate_R(num_torsions, xlo, xhi, ylo, yhi, zlo, zhi)); return(temp);}Individual random_ind(int num_torsions, double xlo, double xhi, double ylo, double yhi, double zlo, double zhi){ Genotype temp_Gtype; Phenotype temp_Ptype; temp_Gtype = generate_Gtype(num_torsions, xlo, xhi, ylo, yhi, zlo, zhi); temp_Ptype = generate_Ptype(num_torsions, xlo, xhi, ylo, yhi, zlo, zhi); Individual temp(temp_Gtype, temp_Ptype); return(temp);}State call_glss(Global_Search *global_method, Local_Search *local_method, State now, unsigned int num_evals, unsigned int pop_size, float xlo, float xhi, float ylo, float yhi, float zlo, float zhi, int outlev, Molecule *mol,int np,int myid){ register int i; int num_iterations = 0, num_loops = 0, allEnergiesEqual = 1, numTries = 0,step=0,buffer_size=0,cs_flag=0; double firstEnergy = 0.0; global_method->reset(); local_method->reset(); evaluate.reset(); (void)fprintf( logFile, "\nCreating a population of %u individuals.\n", pop_size); Population thisPop(pop_size); Individual *heap,*heapall; heap=new Individual[step]; heapall=new Individual[pop_size]; (void)fprintf( logFile, "\nAssigning a random translation, a random orientation and %d random torsions to each of the %u individuals.\n\n", now.ntor, pop_size); global_ntor = now.ntor;//debug do { ++numTries; // Create a population of pop_size random individuals... for (i=0; i<pop_size; i++) { thisPop[i] = random_ind( now.ntor, double(xlo), double(xhi), double(ylo), double(yhi), double(zlo), double(zhi)); thisPop[i].mol = mol; thisPop[i].age = 0L; } // Now ensure that there is some variation in the energies... firstEnergy = thisPop[0].value(Normal_Eval); for (i=1; i<pop_size; i++) { allEnergiesEqual = allEnergiesEqual && (thisPop[i].value(Normal_Eval) == firstEnergy); } if (allEnergiesEqual) { (void)fprintf(logFile,"NOTE: All energies are equal in population; re-initializing. (Try Number %d)\n", numTries); } } while (allEnergiesEqual); MPI_Datatype mystruct_Pop,mystruct_Ind,mystruct_Gen,mystruct_phe,mystruct_mol,mystruct_Lok,mystruct_Rep,mystruct_Sta,mystruct_Coo,mystruct_Qua; int blocklens_Pop[3],blocklens_Ind[4],blocklens_Gen[5],blocklens_phe[7],blocklens_mol[7],blocklens_Lok[2],blocklens_Rep[3],blocklens_Sta[4],blocklens_Coo[3],blocklens_Qua[9]; MPI_Aint indices_Pop[3],indices_Ind[4],indices_Gen[5],indices_phe[7],indices_mol[7],indices_Lok[2],indices_Rep[3],indices_Sta[4],indices_Coo[3],indices_Qua[9]; int base_Ind,base_Gen,base_phe,base_mol,base_Sta,base_Qua; MPI_Datatype old_types_Pop[3],old_types_Ind[4],old_types_Gen[5],old_types_phe[7],old_types_mol[7],old_types_Lok[2],old_types_Rep[3],old_types_Sta[4],old_types_Coo[3],old_types_Qua[9];blocklens_Qua[0] = 1;blocklens_Qua[1] = 1;blocklens_Qua[2] = 1;blocklens_Qua[3] = 1;blocklens_Qua[4] = 1;blocklens_Qua[5] = 1;blocklens_Qua[6] = 1;blocklens_Qua[7] = 1;blocklens_Qua[8] = 1;/* The base types */old_types_Qua[0] = MPI_DOUBLE;old_types_Qua[1] = MPI_DOUBLE;old_types_Qua[2] = MPI_DOUBLE;old_types_Qua[3] = MPI_DOUBLE;old_types_Qua[4] = MPI_DOUBLE;old_types_Qua[5] = MPI_DOUBLE;old_types_Qua[6] = MPI_DOUBLE;old_types_Qua[7] = MPI_DOUBLE;old_types_Qua[8] = MPI_DOUBLE;MPI_Address( &thisPop[0].mol->S.Q.nx, &indices_Qua[0] );MPI_Address( &thisPop[0].mol->S.Q.ny, &indices_Qua[1] );MPI_Address( &thisPop[0].mol->S.Q.nz, &indices_Qua[2] );MPI_Address( &thisPop[0].mol->S.Q.ang, &indices_Qua[3] );MPI_Address( &thisPop[0].mol->S.Q.x, &indices_Qua[4] );MPI_Address( &thisPop[0].mol->S.Q.y, &indices_Qua[5] );MPI_Address( &thisPop[0].mol->S.Q.z, &indices_Qua[6] );MPI_Address( &thisPop[0].mol->S.Q.w, &indices_Qua[7] );MPI_Address( &thisPop[0].mol->S.Q.qmag, &indices_Qua[8] );base_Qua=indices_Qua[0];for(i=0;i<9;i++)indices_Qua[i] = indices_Qua[i] - base_Qua;MPI_Type_struct( 9, blocklens_Qua, indices_Qua, old_types_Qua, &mystruct_Qua );MPI_Type_commit( &mystruct_Qua );blocklens_Coo[0] = 1;blocklens_Coo[1] = 1;blocklens_Coo[2] = 1;/* The base types */old_types_Coo[0] = MPI_DOUBLE;old_types_Coo[1] = MPI_DOUBLE;old_types_Coo[2] = MPI_DOUBLE;MPI_Address( &thisPop[0].mol->S.T.x, &indices_Coo[0] );MPI_Address( &thisPop[0].mol->S.T.y, &indices_Coo[1] );MPI_Address( &thisPop[0].mol->S.T.z, &indices_Coo[2] );indices_Coo[2] = indices_Coo[2] - indices_Coo[0];indices_Coo[1] = indices_Coo[1] - indices_Coo[0];indices_Coo[0] = 0;MPI_Type_struct( 3, blocklens_Coo, indices_Coo, old_types_Coo, &mystruct_Coo );MPI_Type_commit( &mystruct_Coo );blocklens_Sta[0] = 1;blocklens_Sta[1] = 1;blocklens_Sta[2] = MAX_TORS;blocklens_Sta[3] = 1;/* The base types */old_types_Sta[0] = mystruct_Coo;old_types_Sta[1] = mystruct_Qua;old_types_Sta[2] = MPI_DOUBLE;old_types_Sta[3] = MPI_INT;MPI_Address( &thisPop[0].mol->S.T, &indices_Sta[0] );MPI_Address( &thisPop[0].mol->S.Q, &indices_Sta[1] );MPI_Address( &thisPop[0].mol->S.tor, &indices_Sta[2] );MPI_Address( &thisPop[0].mol->S.ntor, &indices_Sta[3] );base_Sta=indices_Sta[0];for(i=0;i<4;i++)indices_Sta[i] = indices_Sta[i] - base_Sta;MPI_Type_struct( 4, blocklens_Sta, indices_Sta, old_types_Sta, &mystruct_Sta );MPI_Type_commit( &mystruct_Sta );blocklens_Rep[0] = 1;blocklens_Rep[1] = 1;blocklens_Rep[2] = 1;/* The base types */old_types_Rep[0] = MPI_UNSIGNED;old_types_Rep[1] = MPI_INT;old_types_Rep[2] = MPI_UNSIGNED_CHAR;MPI_Address( &thisPop[0].phenotyp.value_vector[0][0].number_of_pts, &indices_Rep[0] );MPI_Address( &thisPop[0].phenotyp.value_vector[0][0].mytype, &indices_Rep[1] );MPI_Address( &thisPop[0].phenotyp.value_vector[0][0].normalized, &indices_Rep[2] );indices_Rep[2] = indices_Rep[2] - indices_Rep[0];indices_Rep[1] = indices_Rep[1] - indices_Rep[0];indices_Rep[0] = 0;MPI_Type_struct( 3, blocklens_Rep, indices_Rep, old_types_Rep, &mystruct_Rep );MPI_Type_commit( &mystruct_Rep );blocklens_Lok[0] = 1;blocklens_Lok[1] = 1;/* The base types */old_types_Lok[0] = MPI_UNSIGNED;old_types_Lok[1] = MPI_UNSIGNED;MPI_Address( &thisPop[0].phenotyp.lookup[0].vector, &indices_Lok[0] );MPI_Address( &thisPop[0].phenotyp.lookup[0].index, &indices_Lok[1] );indices_Lok[1] = indices_Lok[1] - indices_Lok[0];indices_Lok[0] = 0;MPI_Type_struct( 2, blocklens_Lok, indices_Lok, old_types_Lok, &mystruct_Lok );MPI_Type_commit( &mystruct_Lok );blocklens_mol[0] = MAX_ATOMS*SPACE;blocklens_mol[1] = MAX_ATOMS*SPACE;blocklens_mol[2] = MAX_ATOMS*MAX_CHARS;blocklens_mol[3] = 1;blocklens_mol[4] = MAX_TORS*SPACE;blocklens_mol[5] = MAX_TORS*MAX_ATOMS;blocklens_mol[6] = 1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -