Guest User

Untitled

a guest
Jan 20th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. void BAPT16Partitioner::AssignVesselToRandomSection(T16Vessel& v)
  2. {
  3. // List of candidate sections to be assigned to v
  4. set<int> sectSet = v.Destinations(); // Copy, preserve original
  5. array<int> S(1, sectSet.size()); // Array of destination sections
  6. //my start
  7. array<int> SectionFlow(1, sectSet.size()); // To compute section flow
  8. //my end
  9. int i = 1, k;
  10.  
  11. while (!sectSet.empty())
  12. {
  13. k = sectSet.choose();
  14. sectSet.del(k);
  15. S[i++] = k;
  16. }
  17.  
  18. // Loop to do actual assignment
  19. int SectionsLeft = S.size();
  20.  
  21. //my start
  22. while (SectionsLeft > 0)
  23. {
  24. SectionFlow[SectionsLeft] = 0;
  25. set<int> stest = mSect[SectionsLeft].Vessels();
  26.  
  27. int itest;
  28. while(!stest.empty())
  29. {
  30. itest = stest.choose();
  31. cout << "(" << v.ID() << ", " << itest << ")" << " Flow= " << TotalFlow(v.ID(),itest) << endl;
  32. SectionFlow[SectionsLeft] += TotalFlow(v.ID(),itest);
  33.  
  34. stest.del(itest);
  35. }
  36. cout << "SectionFlow for " << SectionsLeft << " = " << SectionFlow[SectionsLeft] << endl;
  37. SectionsLeft--;
  38.  
  39. }
  40.  
  41. SectionsLeft = SectionFlow.size();
  42. //my end
  43.  
  44. //while (SectionsLeft > 0 && v.Section() == UNASSIGNED)
  45. for(int counter=1; counter <= SectionsLeft && v.Section() == UNASSIGNED; counter++)
  46. {
  47. //my start
  48. int maxSect=1;
  49. for(int x=2; x <= SectionsLeft; x++)
  50. {
  51. if (SectionFlow[x] > SectionFlow[maxSect])
  52. maxSect = x;
  53. }
  54. cout << "Section Max Flow " << SectionFlow[maxSect] << endl;
  55. //my end
  56.  
  57. //i = mRandom(1, SectionsLeft); // randomly pick a section
  58. //int k = S[i];
  59.  
  60. if (mSect[maxSect].CanAccommodate(v))
  61. {
  62. Assign(v, mSect[maxSect]);
  63. cout << "Assigned to " << maxSect << endl;
  64. }
  65. else
  66. {
  67. //S[i--] = S[SectionsLeft--]; // remove from further consideration
  68. SectionFlow[maxSect] = -1;
  69. cout << "Not Assigned" << endl;
  70. }
  71. }
  72. }
Add Comment
Please, Sign In to add comment