void amoeba_go( AMOEBA* A ) { int step ; step = 1 ; while( ! amoeba_satisfied(A) && step < A->max_steps ) { step++ ; amoeba_order( A ) ; if ( amoeba_reflect( A ) ) { continue ; } if ( amoeba_expand( A ) ) { continue ; } if ( amoeba_contract( A ) ) { continue ; } amoeba_shrink( A ) ; } amoeba_order( A ) ; fprintf(stderr,"\n\nAmoeba search concluded.\n") ; fprintf(stderr,"Number iterations: %d \n", step) ; fprintf(stderr,"x=("); amoeba_print_point( A->num_dims, A->vertices[0] ) ; fprintf(stderr,")\n"); fprintf(stderr,"F(x)=%.6lf\n\n", my_func(A->vertices[0])); }
int cannon_pre_master( /* RETURN: -- Always return zero */ CANNON_AERO* C, /* INOUT: -- Parameter */ AMOEBA* A) { while ( 1 ) { switch ( A->state ) { case VERTICES: A->curr_point = A->vertices[A->curr_vertex] ; if ( A->curr_vertex == A->num_vertices ) { A->state = CALC_CENTROID_POINT ; } else { fprintf(stderr, "V[%d] ", A->curr_vertex); } A->curr_vertex++ ; break ; case CALC_CENTROID_POINT: fprintf(stderr, "CENT "); amoeba_order( A ) ; A->curr_point = A->x_cent ; A->state = CALC_REFLECTION_POINT ; break ; case CALC_REFLECTION_POINT: fprintf(stderr, "REFL "); amoeba_calc_reflection_point( A ) ; A->curr_point = A->x_refl ; A->state = REFLECT ; break ; case REFLECT: if ( amoeba_reflect( A ) ) { A->state = CALC_CENTROID_POINT ; } else { fprintf(stderr, "EXPA "); amoeba_calc_expansion_point( A ) ; A->curr_point = A->x_expa ; A->state = EXPAND ; } break ; case EXPAND: if ( amoeba_expand( A ) ) { A->state = CALC_CENTROID_POINT ; } else { fprintf(stderr, "CONT "); amoeba_calc_contraction_point( A ) ; A->curr_point = A->x_cont ; A->state = CONTRACT ; } break ; case CONTRACT: if ( amoeba_contract( A ) ) { A->state = CALC_CENTROID_POINT ; } else { A->state = SHRINK ; } break ; case SHRINK: amoeba_shrink( A ) ; fprintf(stderr, "V[0] "); A->curr_point = A->vertices[0] ; A->curr_vertex = 1 ; A->state = VERTICES ; break ; } if ( amoeba_satisfied( A ) && A->state != VERTICES ) { exec_terminate( "cannon_pre_master", "Amoeba has found a solution." ) ; } if ( A->state == CALC_CENTROID_POINT || A->state == SHRINK ) { continue ; } else { break ; } } C->time_to_fire_jet_1 = A->curr_point[0] ; C->time_to_fire_jet_2 = A->curr_point[1] ; C->time_to_fire_jet_3 = A->curr_point[2] ; C->time_to_fire_jet_4 = A->curr_point[3] ; return(0) ; }