Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
3.1 KiB

  1. //===-- Solution.h ------- PBQP Solution ------------------------*- C++ -*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // PBQP Solution class.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_CODEGEN_PBQP_SOLUTION_H
  14. #define LLVM_CODEGEN_PBQP_SOLUTION_H
  15. #include "Graph.h"
  16. #include "Math.h"
  17. #include <map>
  18. namespace PBQP {
  19. /// \brief Represents a solution to a PBQP problem.
  20. ///
  21. /// To get the selection for each node in the problem use the getSelection method.
  22. class Solution {
  23. private:
  24. typedef std::map<Graph::ConstNodeItr, unsigned,
  25. NodeItrComparator> SelectionsMap;
  26. SelectionsMap selections;
  27. unsigned r0Reductions, r1Reductions, r2Reductions, rNReductions;
  28. public:
  29. /// \brief Initialise an empty solution.
  30. Solution()
  31. : r0Reductions(0), r1Reductions(0), r2Reductions(0), rNReductions(0) {}
  32. /// \brief Number of nodes for which selections have been made.
  33. /// @return Number of nodes for which selections have been made.
  34. unsigned numNodes() const { return selections.size(); }
  35. /// \brief Records a reduction via the R0 rule. Should be called from the
  36. /// solver only.
  37. void recordR0() { ++r0Reductions; }
  38. /// \brief Returns the number of R0 reductions applied to solve the problem.
  39. unsigned numR0Reductions() const { return r0Reductions; }
  40. /// \brief Records a reduction via the R1 rule. Should be called from the
  41. /// solver only.
  42. void recordR1() { ++r1Reductions; }
  43. /// \brief Returns the number of R1 reductions applied to solve the problem.
  44. unsigned numR1Reductions() const { return r1Reductions; }
  45. /// \brief Records a reduction via the R2 rule. Should be called from the
  46. /// solver only.
  47. void recordR2() { ++r2Reductions; }
  48. /// \brief Returns the number of R2 reductions applied to solve the problem.
  49. unsigned numR2Reductions() const { return r2Reductions; }
  50. /// \brief Records a reduction via the RN rule. Should be called from the
  51. /// solver only.
  52. void recordRN() { ++ rNReductions; }
  53. /// \brief Returns the number of RN reductions applied to solve the problem.
  54. unsigned numRNReductions() const { return rNReductions; }
  55. /// \brief Set the selection for a given node.
  56. /// @param nItr Node iterator.
  57. /// @param selection Selection for nItr.
  58. void setSelection(Graph::NodeItr nItr, unsigned selection) {
  59. selections[nItr] = selection;
  60. }
  61. /// \brief Get a node's selection.
  62. /// @param nItr Node iterator.
  63. /// @return The selection for nItr;
  64. unsigned getSelection(Graph::ConstNodeItr nItr) const {
  65. SelectionsMap::const_iterator sItr = selections.find(nItr);
  66. assert(sItr != selections.end() && "No selection for node.");
  67. return sItr->second;
  68. }
  69. };
  70. }
  71. #endif // LLVM_CODEGEN_PBQP_SOLUTION_H