thezxtreme

Untitled

Jan 9th, 2020
106
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     struct Cut final
  2.     {
  3.         Cut(uint16_t _length, uint32_t _count) : length(_length), count(_count) {}
  4.  
  5.         uint16_t length = 0x0;
  6.         uint32_t count = 0x0;
  7.     };    
  8.  
  9.     struct Order final
  10.     {
  11.         std::vector<Cut> dataset = {};
  12.  
  13.         Order(const Order& _order, SolutionNode* _node);
  14.         Order(const Order& _order, SolutionNode* _node, bool _recursion);
  15.         Order(const Dataset& _order, SolutionNode* _node);
  16.  
  17.         auto remove_by_pattern(const Pattern* const _pattern, uint32_t _repeat) -> void;
  18.         auto get_pattern_repeat(const Pattern& _pattern) const -> uint16_t;
  19.         inline auto max_element() const -> decltype(auto) { return dataset.rbegin()->length; }
  20.     };
  21.  
  22. auto Edesia::SolutionNode::multi_thread_spreading(Order&& _init_order) -> void
  23. {
  24.     uint8_t allocations = 0x0;
  25.  
  26.     const auto valid_patterns = sInterface->sorted_unique_patterns.find(_init_order.max_element());
  27.     for (auto pattern = valid_patterns->second.crbegin(); pattern != valid_patterns->second.crend(); ++pattern)
  28.     {
  29.         if (allocations == data.size())
  30.             break;
  31.  
  32.         if (const uint16_t pattern_repeat = _init_order.get_pattern_repeat(*pattern->get().lengths))
  33.         {
  34.             if (data.solution_loss + pattern->get().loss*pattern_repeat > sInterface->runtime_statistics->solution_loss)
  35.                 continue;
  36.  
  37.             data[allocations++] = new SolutionNode(this, pattern->get(), pattern_repeat, Settings::multi_thread_spread_limit);
  38.         }
  39.     }
  40.     SolutionNode::begin_next_level_spreading(this, _init_order);
  41. }
  42.  
  43. auto Edesia::SolutionNode::begin_next_level_spreading(SolutionNode* const _parent, const Order& _init_order) const -> void
  44. {
  45.     /* Start spreading from future nodes... */
  46.     std::for_each(_parent->data.rbegin(), _parent->data.rend(), [&](SolutionNode* const _node) -> void
  47.     {
  48.         if (_node)
  49.         {
  50.             Order future_order = Order(_init_order, _node);
  51.             if (future_order.dataset.empty())
  52.             {
  53.                 if (_node->data.stock_used < sInterface->runtime_statistics->stock_used)
  54.                 {
  55.                     sInterface->runtime_statistics->unique_patterns = _node->data.unique_patterns;;
  56.                     sInterface->runtime_statistics->stock_used = _node->data.stock_used;
  57.                     sInterface->runtime_statistics->solution_loss = _node->data.solution_loss;
  58.                     Helper::print_solution(_node, "-> Less stock found!");
  59.                     return;
  60.                 }
  61.  
  62.                 /* We found better solution loss than our statistic algorithm. Update _statistic object. */
  63.                 if (_node->data.solution_loss < sInterface->runtime_statistics->solution_loss)
  64.                 {
  65.                     sInterface->runtime_statistics->unique_patterns = _node->data.unique_patterns;
  66.                     sInterface->runtime_statistics->solution_loss =_node->data.solution_loss;
  67.                     Helper::print_solution(_node, "-> Smaller loss found!");
  68.                     return;
  69.                 }
  70.  
  71.                 if (_node->data.unique_patterns < sInterface->runtime_statistics->unique_patterns)
  72.                 {
  73.                     sInterface->runtime_statistics->unique_patterns = _node->data.unique_patterns;
  74.                     Helper::print_solution(_node, "Less unique patterns found!");
  75.                     return;
  76.                 }
  77.                 return;
  78.             }
  79.  
  80.             if (sInterface->runtime_statistics->unique_patterns < _node->data.unique_patterns+1)
  81.                 return;
  82.  
  83.             _node->multi_thread_spreading(std::move(future_order));
  84.         }
  85.     });
  86. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×