Guest User

Untitled

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