Advertisement
Guest User

Untitled

a guest
Dec 9th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. std::vector<torch::jit::IValue> generate_binary_vector_representation(uint32_t n_agents, uint32_t n_tasks)
  2. {
  3. // This is a ridiculous way of setting the elements' values,
  4. // but I couldn't find a better way to do it. Feel free to replace this
  5. // with something more efficient, since this is really damn costly.
  6.  
  7. std::vector<int> vector_representation; vector_representation.reserve(n_agents * n_tasks);
  8. for (uint32_t agent_j = 0; agent_j < n_agents; agent_j++)
  9. {
  10. for (uint32_t task_i = 0; task_i < n_tasks; task_i++)
  11. {
  12. if (is_agent_in_coalition(agent_j, task_i))
  13. {
  14. vector_representation.push_back(1.0f);
  15. }
  16. else
  17. {
  18. vector_representation.push_back(0.0f);
  19. }
  20. }
  21. }
  22.  
  23. torch::Tensor tensor = torch::from_blob(vector_representation.data(), { 1, n_agents * n_tasks });
  24. return std::vector<torch::jit::IValue>{std::move(tensor)};
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement