多数据源中间件标准版1.0

StrategyLoopByAgentId.cpp 1022B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include "stdafx.h"
  2. #include "StrategyLoopByAgentId.h"
  3. #include "Agent.h"
  4. #include "AgentGroup.h"
  5. #include <algorithm>
  6. CStrategyLoopByAgentId::CStrategyLoopByAgentId()
  7. {
  8. }
  9. CStrategyLoopByAgentId::~CStrategyLoopByAgentId()
  10. {
  11. }
  12. CAgent * CStrategyLoopByAgentId::_locateAgent(CAgentGroup & AgentGroup)
  13. {
  14. CAgent* pAgent = NULL;
  15. bool t_b_has_jump = false;
  16. static UINT agentId = 0;
  17. //pAgent = AgentGroup.GetFreeAgentForLoopByAgentId();
  18. std::sort(AgentGroup.GetData(), AgentGroup.GetData() + AgentGroup.GetSize(), [&](CAgent *a, CAgent *b) mutable ->bool { return a->id() < b->id(); });
  19. for (int i = 0; i < AgentGroup.GetCount(); ++i)
  20. {
  21. pAgent = AgentGroup[i];
  22. if (pAgent->isFree() && pAgent->id() > agentId)
  23. {
  24. agentId = pAgent->id();
  25. return pAgent;
  26. }
  27. }
  28. for (int i = 0; i < AgentGroup.GetCount(); ++i)
  29. {
  30. pAgent = AgentGroup[i];
  31. if (pAgent->isFree() && pAgent->id() <= agentId)
  32. {
  33. agentId = pAgent->id();
  34. return pAgent;
  35. }
  36. if (pAgent->id() > agentId)
  37. break;
  38. }
  39. return pAgent;
  40. }