Make a C program that can read a simple data file. The program should contain co
ID: 3884704 • Letter: M
Question
Make a C program that can read a simple data file. The program should contain code that randomly initialize a genetic algorithm population (say population size = 100) and compute the makespans of the population. Select the best schedule according to makespans and output the schedule and its makespan.
For example suppose you have a file named text.txt that contains the following data.
3 2 //This first row indicates the number of jobs and the number of machines
0 5 1 10 //These other 3 rows represent a specific job combined by (machine-id, job-duration) pairs.
0 10 1 5
0 1 1 4
The output would be:
21 //This first line indicates the optimization criterion 2
0 0 1 1 6 //This second line is the makespan computed from the schedule
2 1 0 6 1 16 //This is the flowshop schedule combined by (job-id, start-time) pairs
Explanation / Answer
#include<stdio.h>
#include<stdlib.h>
int main()
{
char ch,file_name[25];
file *fp;
printf("Enter the name of file you want to open");
gets(file_name);
fp=fopen(file_name,"r");
if(fp==NULL)
{
perror("Error while opening the file";
exit(EXIT_FAILURE);
}
printf("The contents of %s files are : ",file_name);
while((ch=fgetc(fp))!=EOF)
printf("%c",ch);
fclose(fp);
return 0;
}
Please give a thumbs up if you like the program.Thankyou:) Stay connected with chegg we are always their for your hepl.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.