int main(void) { char choice; printf("Please press desired key to continue ... \n\n "); do { printf("\nMENU\n\n" " + : addition\n" " - : substraction\n " " * : multiplication\n " " / : division\n" " ^ : power\n" " q : quit\n\n"); printf("Command: "); scanf(" %c ", &choice); switch(choice) { case '+': summation(); break; case '-': substraction(); break; case '*': multiplication(); break; case '/': division(); break; case '^': toThePower(); break; case 'q': break; default: { fprintf(stderr, "you didn't press expected key :(\n"); } } } while (choice != 'q'); }
/********** Cr� la population **********/ void itsHybridContinuousInteractingAntColony::createAnts() { // r�ervations vecteurs antProbaMemory.reserve( antsNb ); //antMoveRange.reserve( antsNb*SpaceDim() ); antMoveRange.reserve( antsNb ); antCurrentPoint.reserve( antsNb * this->getProblem()->getDimension() ); antCurrentValue.reserve( antsNb ); // trop gourmand : antIncomingPoints.reserve( antsNb*antsNb*SpaceDim() ); antIncomingPoints.reserve( antsNb*antsNb ); antIncomingValues.reserve( antsNb*antsNb ); antState.reserve( antsNb ); for( unsigned int i=0; i < antsNb; i++ ) { // tirage al�toire uniforme sur l'hypercube de l'espace de recherche vector<double> aPoint; /* aPoint.reserve( this->getProblem()->getDimension() ); aPoint = randomUniform( this->getProblem()->boundsMinima(), this->getProblem()->boundsMaxima() ); */ aPoint = this->getSamplePointAddr(i)->getSolution(); // tire suivant N l'amplitude max de mouvement // distribution normale sur la moyenne de l'amplitude de l'espace de recherche double aMoveRange; aMoveRange = abs( randomNormal( mean( substraction(this->getProblem()->boundsMaxima(),this->getProblem()->boundsMinima()) ) * moveRangeMeanRatio, 1/2 * mean( substraction(this->getProblem()->boundsMaxima(),this->getProblem()->boundsMinima()) ) * moveRangeStdRatio ) ); // tire sur N la probabilit�de d�art d'utiliser un type de m�oire double aProbaUseMemory; aProbaUseMemory = randomNormal( probaUseMemoryMean, probaUseMemoryStd ); // corrige les d�assements if ( aProbaUseMemory < 0 ) { aProbaUseMemory = 0; } if ( aProbaUseMemory > 1 ) { aProbaUseMemory = 1; } // ajoute la fourmi addAnt( aPoint, aMoveRange, aProbaUseMemory ); } }
/********** Evapore les sports **********/ void itsHybridContinuousInteractingAntColony::spotsEvaporate() { // r�uit l'attrait des spots // S - (1-p) * S spotsValues = substraction( spotsValues, multiply( spotsValues, (1-spotsPersistence ) ) ); // supprime les spots trop faibles unsigned int i; for( i=0; i < spotsValues.size(); i++ ) { if( spotsValues[i] <= spotsMinValue ) { spotsValues.erase( spotsValues.begin()+i ); spotsPoints.erase( spotsPoints.begin()+i ); } } }
void itsHybridEstimationOfDistribution::simplex() { // if no given NMS evaluations number if( getSimplexEvaluations() == -1 ) { //setSimplexEvaluations( (int)floor( pow( (this->problem->getDimension() + 1 ), 2.0 ) ) ); setSimplexEvaluations( this->getProblem()->getDimension() + 10 ); } for( unsigned int i=0; i < getSampleSizeCurrent(); i++ ) { itsNelderMead nms; // problem optimized nms.setProblem( this->getProblem() ); // no ending stopping criteria nms.setValueMin(0.0); nms.setIterationsMaxNumber( this->getIterationsMaxNumber() ); // used stopping criterion nms.setEvaluationsMaxNumber( this->simplexEvaluations ); // edges from sample hypercube vector<double> edges = multiply( substraction( this->getProblem()->boundsMaxima(), this->getProblem()->boundsMinima() ), 1 / ( pow( (double)getSampleSizeCurrent(), (double)1.0/this->getProblem()->getDimension() ) - 1 ) ); // init on current point nms.initSimplexFromBasePoint( getSamplePoint(i), edges ); // silent launch nms.startSilent(); // change the point to the new local optimum setSamplePoint( i, nms.getOptimum() ); } }
void menu(int m1, int n1, int m2, int n2, int m3, int n3) { printf("\n1.Read an Array.\n2.Print an Array.\n3.Addition of 2 Arrays.\n4.Substraction of 2 Arrays.\n5.Multiplication of 2 Arrays.\n6.Multiplication of an Array by a Number.\n7.Transpose of a Matrix.\n8.Determinant of a Matrix.\n9.Exit.\n"); scanf("%d",&f); switch (f) { case 1: read(x, &m1, &n1, y, &m2, &n2, z, &m3, &n3); menu(m1, n1, m2, n2, m3, n3); break; case 2: printa(x, m1, n1, y, m2, n2, z, m3, n3); printf("\n1.Menu.\n2.Exit.\n"); scanf("%d",&f); switch (f) { case 1: menu(m1, n1, m2, n2, m3, n3); break; case 2: break; default: break; } break; case 3: Addition(x, m1, n1, y, m2, n2, z, m3, n3, &m1, &n1, &m2, &n2, &m3, &n3); menu(m1, n1, m2, n2, m3, n3); break; case 4: substraction(x, m1, n1, y, m2, n2, z, m3, n3, &m1, &n1, &m2, &n2, &m3, &n3); menu(m1, n1, m2, n2, m3, n3); break; case 5: multiplication_array(x, m1, n1, y, m2, n2, z, m3, n3, &m1, &n1, &m2, &n2, &m3, &n3); menu(m1, n1, m2, n2, m3, n3); break; case 6: multiplaction_number(x, m1, n1, y, m2, n2, z, m3, n3, &m1, &n1, &m2, &n2, &m3, &n3); menu(m1, n1, m2, n2, m3, n3); break; case 7: transpose(x, m1, n1, y, m2, n2, z, m3, n3, &m1, &n1, &m2, &n2, &m3, &n3); menu(m1, n1, m2, n2, m3, n3); break; case 8: determinant(x, m1, n1, y, m2, n2, z, m3, n3, &m1, &n1, &m2, &n2, &m3, &n3); menu(m1, n1, m2, n2, m3, n3); break; case 9: break; default: break; } }