Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- #include <cstring>
- #define _USE_MATH_DEFINES
- using namespace std;
- float float_rand(float min, float max)
- {
- float scale = rand() / (float)RAND_MAX; /* [0, 1.0] */
- return min + scale * (max - min); /* [min, max] */
- }
- float * return_solution_list(int number_of_solution, float min_value, float max_value){
- float* solutions = static_cast<float *>(malloc(sizeof(float) * number_of_solution));
- for (int i = 0; i < number_of_solution; ++i) {
- solutions[i] = float_rand(min_value,max_value);
- }
- return solutions;
- }
- float rastigin_function(float* solution, int dimension){
- float response = 0.00;
- response = 10*dimension;
- for (int i = 0; i <dimension ; ++i) {
- response += solution[i]*solution[i] - 10*cos(M_PI*2*solution[i]);
- }
- return response;
- }
- int main() {
- float m,M;
- int solution;
- cout<< "enter number of solution: ";
- cin >> solution;
- cout<< "enter minim value: ";
- cin >> m;
- cout<< "enter maxim value: ";
- cin >> M;
- float * sol = return_solution_list(solution,m,M);
- cout<< "Soul: " << rastigin_function(sol, solution);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement