Question

Write a C program that reads a simple data file such as, text.txt 3 2 //This...

Write a C program that reads a simple data file such as,

text.txt

3 2 //This first row indicates the number of jobs and the number of machines

0 5 1 10 //These other row represents a specific job combined by (machine-id, job-duration) pairs.

0 10 1 5

0 1 1 4

After 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 to an outtput file. The makespan would look like this for text.txt,

makespan

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

The compile should look like text.txt output.txt

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <stdio.h>

int nofjobs;

int nofmachines;

struct s {

int mId,duration;

};

int main() {

struct s machines[nofmachines],jobs[nofjobs];

FILE *fptr;

fptr=fopen("file.txt","rb");

fread(jobs,sizeof(jobs),1,fptr);

fread(machines,sizeof(machines),1,fptr);

for (i=0;i<nofjobs;++i) {

printf("Machine ID: %d\n duration: %d",jobs[i].mId,jobs[i].);

}

fclose(fptr);

}

// s1 -> machine 1

//s2->machine 2 , a[i]-> job[i] ,time-> time consumed,jobs sorted in descending order

// allocated one by one to the machine which is free.

long long ans=INT_MAX;

sort(a,a+n);

reverse(a,a+n);

int i=2;

int s1=machines[0];

int s2=machines[1];

long long time=min(s1,s2);

s1-=time;

s2-=time;

while(i<n)

{

if(s1==0 && s2==0)

{

s1=a[i];

if(i+1<n) s2=a[i+1];

int c=min(s1,s2);

time+=c;

s1-=c;

s2-=c;

i+=2;

continue;

}

else

{

if(s1<s2) swap(s1,s2);

s2=a[i];

int c=min(s1,s2);

time+=c;

s1-=c;

s2-=c;

i++;

}

}

assert(s1*s2==0);

ans = min(ans,time+max(s1,s2));

Add a comment
Know the answer?
Add Answer to:
Write a C program that reads a simple data file such as, text.txt 3 2 //This...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a C++ program that reads text from a file and encrypts the file by adding...

    Write a C++ program that reads text from a file and encrypts the file by adding 6 to the ASCII value of each character. See section 5.11 in Starting out with C++ for information on reading and writing to text files. Your program should: 1. Read the provided plain.txt file one line at a time. Because this file has spaces, use getline (see section 3.8). 2. Change each character of the string by adding 6 to it. 3. Write the...

  • Lab #10 C++ Write a C++ program that reads text from a file and encrypts the...

    Lab #10 C++ Write a C++ program that reads text from a file and encrypts the file by adding an encryption factor (EF) to the ASCII value of each character. The encryption factor is 1 for the first line and increases by 1 for each line up to 4 and then starts over at 1. So, for the 4 th line the EF is 4, for the 5th line it is 1, for the 10th line it is 2. In...

  • C++ Programming question Problem: 5. Write a program that reads in a list of integers into...

    C++ Programming question Problem: 5. Write a program that reads in a list of integers into an array with base type int. Provide the facility to either read this array from the keyboard or from a file, at the user's option. If the user chooses file input, the program should request a file name. You may assume that there are fewer than 50 entries in the array. Your program determines how many entries there are. The output is to be...

  • C++ please Write a program that reads the following sentences from a file: I am Sam...

    C++ please Write a program that reads the following sentences from a file: I am Sam Sam I am That Sam I am That Sam I am I do not like that Sam I am Do you like green eggs and ham I do not like them But I do like spam! You will first have to create the text file containing the input, separate from your program. Your program should produce two output files: (i) (ii) one with the...

  • Write in Java please. The purpose of this program is to read a file, called WaterData.csv....

    Write in Java please. The purpose of this program is to read a file, called WaterData.csv. It will output date and gallons. So it would look something like "2/04/15 40 Gallons". The pseudo code is as follows. prompt the user for a file name open the file if that file cannot be opened display an error message and quit endif create a String variable 'currentDate' and initialize it to the empty string. create a variable gallonsUsed and initialize it to...

  • Write a Java program in Eclipse that reads from a file, does some clean up, and...

    Write a Java program in Eclipse that reads from a file, does some clean up, and then writes the “cleaned” data to an output file. Create a class called FoodItem. This class should have the following: A field for the item’s description. A field for the item’s price. A field for the item’s expiration date. A constructor to initialize the item’s fields to specified values. Getters (Accessors) for each field. This class should implement the Comparable interface so that food...

  • Write a C++ program that will read in image data from the file "image.txt" and illustrate...

    Write a C++ program that will read in image data from the file "image.txt" and illustrate that image as ASCII art. The Image file will contain several lines, representing horizontal rows in the image, and each line will have several integers in the range 0-255. representing povels, separated by spaces. You should read this image data into a vector vector in Once you've read in the phel data, go through the image and print out each piel in the image...

  • QUESTION The ReadFile class opens and reads a text file. The WriteFile class opens and writes...

    QUESTION The ReadFile class opens and reads a text file. The WriteFile class opens and writes to a file. Compile and run these programs. There are several ways to read/write text files. The examples shown here are just one way of achieving this. Look at the API for the BufferedReader class. The readline() method is a simple way to read the text file line by line. It returns null when the end of the file has been reached. https://docs.oracle.com/javase/8/docs/api/java/io/BufferedReader.html Look...

  • write a code on .C file Problem Write a C program to implement a banking application...

    write a code on .C file Problem Write a C program to implement a banking application system. The program design must use a main and the below functions only. The program should use the below three text files that contain a set of lines. Sample data of these files are provided with the assessment. Note that you cannot use the library string.h to manipulate string variables. For the file operations and manipulations, you can use only the following functions: fopen(),...

  • In c programming . Part A: Writing into a Sequential File Write a C program called...

    In c programming . Part A: Writing into a Sequential File Write a C program called "Lab5A.c" to prompt the user and store 5 student records into a file called "stdInfo.txt". This "stdInfo.txt" file will also be used in the second part of this laboratory exercise The format of the file would look like this sample (excluding the first line) ID FIRSTNAME LASTNAME GPA YEAR 10 jack drell 64.5 2018 20 mina alam 92.3 2016 40 abed alie 54.0 2017...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT