Guest User

Untitled

a guest
Apr 25th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. // Szeregowanie zadan.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. #include <fstream>
  7. #include <Windows.h>
  8.  
  9. using namespace std;
  10.  
  11. int size_max;
  12. int dane[4][18];
  13. int d[]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18};
  14. void wczytaj_plik()
  15. {
  16. ifstream stream1("6.txt");
  17. if(!stream1)
  18. {
  19. cout<<"Nie mozna wczytac pliku\n";
  20. exit(1);
  21. }
  22. while(!stream1.eof())
  23. {
  24. for(int i=0; i<18; ++i)
  25. {
  26. for(int j=0; j<3; ++j)
  27. {
  28. stream1>>dane[i][j];
  29. }
  30. }
  31. }
  32. stream1.close();
  33. }
  34.  
  35. void wyswietl_plik()
  36. {
  37.  
  38. cout << "Lp - liczba zadan wykonywanych na 1 procesorze\n";
  39. cout <<"P[j] - czas wykonywania zadania na maszynie\n";
  40. cout <<"D[j] - żadany czas zakonczenia sie zadania\n";
  41. cout <<"W[J] - waga zadania\n";
  42. cout<<"##########################################################\n";
  43. cout<<"##############Zawartosc pliku tesktowego##################\n";
  44. cout<<"##########################################################\n";
  45. cout << "Lp\t"<<"P[j]\t"<<"D[j]\t"<<"W[j]"<<endl;
  46. for(int i=0; i<5; i++)
  47. {
  48. cout<<d[i]<<"\t";
  49. for(int j=0; j<3; j++)
  50. {
  51. cout<<dane[i][j]<<"\t";
  52. }
  53. cout<<endl;
  54.  
  55. }
  56. cout<<"##########################################################\n";
  57. }
  58.  
  59. #define P(i) dane[i][0]
  60. #define D(i) dane[i][1]
  61. #define W(i) dane[i][2]
  62.  
  63. int opoznienia(int all_time, int task)
  64. {
  65. int curr_delay = 0;
  66. all_time += P(task);
  67. if(all_time > D(task))
  68. {
  69. curr_delay = W(task)*(all_time - D(task));
  70. }
  71. return curr_delay;
  72. }
  73.  
  74. void permutacje(int *curr_way, bool *used, int curr_size, int all_delay, int curr_time)
  75. {
  76. int curr_delay;
  77. if(curr_size == size_max)
  78. {
  79. for(int i = 0;i < size_max;i++)
  80. {
  81. printf("%d:", curr_way[i]);
  82. }
  83. printf("(opoznienia=%d, czas=%d)\n", all_delay, curr_time);
  84. return;
  85. }
  86. for(int i = 0;i < size_max;i++)
  87. {
  88. if(used[i] == true)
  89. continue;
  90. used[i] = true;
  91. curr_delay = opoznienia(curr_time, i);
  92. curr_way[curr_size] = i;
  93. permutacje(curr_way, used, curr_size+1, curr_delay+all_delay, curr_time+P(i));
  94. used[i] = false;
  95. }
  96. }
  97.  
  98. int main()
  99. {
  100. size_max = 5;
  101. wczytaj_plik();
  102. wyswietl_plik();
  103. int *tempway = (int*)malloc(sizeof(int)*size_max);
  104. bool *tempused = (bool*)malloc(sizeof(bool)*size_max);
  105. RtlZeroMemory(tempused, sizeof(bool)*size_max);
  106. permutacje(tempway, tempused, 0, 0, 0);
  107. free(tempused);
  108. free(tempway);
  109. //system("pause");
  110. return 0;
  111. }
Add Comment
Please, Sign In to add comment