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
  • 1. use c++ write a c++ program that reads 10 integers from a file named input.txt...

    1. use c++ write a c++ program that reads 10 integers from a file named input.txt in this file the 10 integers wil be on a single line with space between the. calculate the average of these numbers and then write his number to a file named output.txt. if the program is unable to successfully complete the file operations then display eero message to the console.

  • 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...

  • Write a C++ program that reads a flat file of the following format. Input 42 1...

    Write a C++ program that reads a flat file of the following format. Input 42 1 John Curry 5 2345.34 345.40 569.89 4560.45 450.00 2 Abigail Right 0 3 Jack Monstrom 2 34569.00 3456.45 …. 42 Evelyn Madim 0 Instructions The number in the first row indicates the number of rows/managers in the file. In each row, the first number is the UIN of the manager followed by his first name and last name, the number of customers and the...

  • Please write a java program with a input file "jabberwock.txt", and output the "output.txt" with following...

    Please write a java program with a input file "jabberwock.txt", and output the "output.txt" with following requirement. You and your partner will be writing a simple Java program that implements some basic file I/O operations. You can use this code as the basis for some of your next project. FIRST: Write code that prompts the user for the name of a text file, opens that file if it exists and reads the file one line at a time printing each...

  • I need help writing python code with following instructions. You will write a program that reads...

    I need help writing python code with following instructions. You will write a program that reads a data file. The data file contains ticket IDs and ticket prices. Your job is to read these tickets (and prices). find minimum, maximum and average ticket prices and output a report file. The report file should look exactly (or better than) the one attached (output.txt). Input: A31 149.99 B31 49.99 A41 179.99 F31 169.99 A35 179.99 A44 169.99 open "input.txt" file using open()...

  • 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 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...

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