Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Szeregowanie zadan.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <iostream>
- #include <fstream>
- #include <Windows.h>
- using namespace std;
- int *gMinWay;
- int gMin;
- int size_max;
- int dane[4][18];
- int d[]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18};
- void wczytaj_plik()
- {
- ifstream stream1("6.txt");
- if(!stream1)
- {
- cout<<"Nie mozna wczytac pliku\n";
- exit(1);
- }
- while(!stream1.eof())
- {
- for(int i=0; i<18; ++i)
- {
- for(int j=0; j<3; ++j)
- {
- stream1>>dane[j][i];
- }
- }
- }
- stream1.close();
- }
- void wyswietl_plik()
- {
- cout << "Lp - liczba zadan wykonywanych na 1 procesorze\n";
- cout <<"P[j] - czas wykonywania zadania na maszynie\n";
- cout <<"D[j] - żadany czas zakonczenia sie zadania\n";
- cout <<"W[J] - waga zadania\n";
- cout<<"##########################################################\n";
- cout<<"##############Zawartosc pliku tesktowego##################\n";
- cout<<"##########################################################\n";
- cout << "Lp\t"<<"P[j]\t"<<"D[j]\t"<<"W[j]"<<endl;
- for(int i=0; i<size_max; i++)
- {
- cout<<d[i]<<"\t";
- for(int j=0; j<3; j++)
- {
- cout<<dane[j][i]<<"\t";
- }
- cout<<endl;
- }
- cout<<"##########################################################\n";
- }
- #define P(i) dane[0][i]
- #define D(i) dane[1][i]
- #define W(i) dane[2][i]
- int opoznienia(int all_time, int task)
- {
- int curr_delay = 0;
- all_time += P(task);
- if(all_time > D(task))
- {
- curr_delay = W(task)*(all_time - D(task));
- }
- return curr_delay;
- }
- void permutacje(int *curr_way, bool *used, int curr_size, int all_delay, int curr_time)
- {
- int curr_delay;
- if(curr_size == size_max)
- {
- if(all_delay >= gMin)
- {
- return;
- }
- RtlCopyMemory(gMinWay, curr_way, size_max*sizeof(int));
- gMin = all_delay;
- for(int i = 0;i < size_max;i++)
- {
- printf("%d:", curr_way[i]);
- }
- printf("(opoznienia=%d, czas=%d)\n", all_delay, curr_time);
- return;
- }
- for(int i = 0;i < size_max;i++)
- {
- if(used[i] == true)
- continue;
- used[i] = true;
- curr_delay = opoznienia(curr_time, i);
- curr_way[curr_size] = i;
- permutacje(curr_way, used, curr_size+1, curr_delay+all_delay, curr_time+P(i));
- used[i] = false;
- }
- }
- int main()
- {
- size_max = 5;
- wczytaj_plik();
- wyswietl_plik();
- gMinWay = (int*)malloc(sizeof(int)*size_max);
- gMin = 0x09999999;
- int *tempway = (int*)malloc(sizeof(int)*size_max);
- bool *tempused = (bool*)malloc(sizeof(bool)*size_max);
- RtlZeroMemory(tempused, sizeof(bool)*size_max);
- permutacje(tempway, tempused, 0, 0, 0);
- free(tempused);
- free(tempway);
- printf("##########################################################\n");
- printf("Min=%d\nZadania", gMin);
- for(int i = 0;i < size_max;i++)
- {
- printf(":%d", gMinWay[i]);
- }
- free(gMinWay);
- //system("pause");
- return 0;
- }
Add Comment
Please, Sign In to add comment