-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.c
executable file
·41 lines (32 loc) · 1021 Bytes
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include "a4.h"
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
int main(int argc, char **argv) {
srand(time(NULL));
// Process input parameters
if (argc!=6)
{
printf("Usage ./evolve in_file out_file num_gen p_size rate\n");
return 1;
}
const char *input_file = argv[1];
const char *output_file = argv[2];
int num_generations = atoi(argv[3]);
int population_size = atoi(argv[4]);
double mutation_rate = atof(argv[5]);
// Read image.
PPM_IMAGE *goal = read_ppm(input_file);
printf("\nFile %s:\n %dx%d, max color %d, pixels to mutate %d\n",
input_file, goal->width, goal->height, goal->max_color, (int)(mutation_rate/100*goal->width*goal->height));
// Compute image
PPM_IMAGE *new_image =
evolve_image(goal, num_generations, population_size, mutation_rate);
// Write image
write_ppm(output_file, new_image);
// Free memory
free_image(goal);
free_image(new_image);
return (0);
}