Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void BAPT16Partitioner::AssignVesselToRandomSection(T16Vessel& v)
- {
- // List of candidate sections to be assigned to v
- set<int> sectSet = v.Destinations(); // Copy, preserve original
- array<int> S(1, sectSet.size()); // Array of destination sections
- //my start
- array<int> SectionFlow(1, sectSet.size()); // To compute section flow
- //my end
- int i = 1, k;
- while (!sectSet.empty())
- {
- k = sectSet.choose();
- sectSet.del(k);
- S[i++] = k;
- }
- // Loop to do actual assignment
- int SectionsLeft = S.size();
- //my start
- while (SectionsLeft > 0)
- {
- SectionFlow[SectionsLeft] = 0;
- set<int> stest = mSect[SectionsLeft].Vessels();
- int itest;
- while(!stest.empty())
- {
- itest = stest.choose();
- cout << "(" << v.ID() << ", " << itest << ")" << " Flow= " << TotalFlow(v.ID(),itest) << endl;
- SectionFlow[SectionsLeft] += TotalFlow(v.ID(),itest);
- stest.del(itest);
- }
- cout << "SectionFlow for " << SectionsLeft << " = " << SectionFlow[SectionsLeft] << endl;
- SectionsLeft--;
- }
- SectionsLeft = SectionFlow.size();
- //my end
- //while (SectionsLeft > 0 && v.Section() == UNASSIGNED)
- for(int counter=1; counter <= SectionsLeft && v.Section() == UNASSIGNED; counter++)
- {
- //my start
- int maxSect=1;
- for(int x=2; x <= SectionsLeft; x++)
- {
- if (SectionFlow[x] > SectionFlow[maxSect])
- maxSect = x;
- }
- cout << "Section Max Flow " << SectionFlow[maxSect] << endl;
- //my end
- //i = mRandom(1, SectionsLeft); // randomly pick a section
- //int k = S[i];
- if (mSect[maxSect].CanAccommodate(v))
- {
- Assign(v, mSect[maxSect]);
- cout << "Assigned to " << maxSect << endl;
- }
- else
- {
- //S[i--] = S[SectionsLeft--]; // remove from further consideration
- SectionFlow[maxSect] = -1;
- cout << "Not Assigned" << endl;
- }
- }
- }
Add Comment
Please, Sign In to add comment