Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. double Min_ost::best_way() {
  2. double ans = numeric_limits<double>::max();
  3. vector <int> shuffle(graph.VerticesCount());
  4. for (size_t j = 0; j < graph.VerticesCount(); ++j) {
  5. shuffle[j] = j;
  6. }
  7.  
  8. double cur_ans = 0;//вес очередного пути (перебор по всем возможным путям)
  9. do {//перебор всех перестановок
  10.  
  11. for (int i = 1; i < graph.VerticesCount(); ++i) {
  12. cur_ans += graph.GetWeight(shuffle[i], shuffle[i - 1]);//weight of edge from shuffle[i-1] to shuffle[i]
  13. }
  14. cur_ans += graph.GetWeight(shuffle[graph.VerticesCount() - 1], shuffle[0]); //возвращение в исходную точку
  15. ans = min(ans, cur_ans)
  16. }
  17. while(next_permutation(shuffle.begin(), shuffle.end()));
  18.  
  19. return ans;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement