LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Solution.h
Go to the documentation of this file.
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 
14 #ifndef LLVM_CODEGEN_PBQP_SOLUTION_H
15 #define LLVM_CODEGEN_PBQP_SOLUTION_H
16 
17 #include "Graph.h"
18 #include "Math.h"
19 #include <map>
20 
21 namespace PBQP {
22 
23  /// \brief Represents a solution to a PBQP problem.
24  ///
25  /// To get the selection for each node in the problem use the getSelection method.
26  class Solution {
27  private:
28 
29  typedef std::map<Graph::NodeId, unsigned> SelectionsMap;
30  SelectionsMap selections;
31 
32  unsigned r0Reductions, r1Reductions, r2Reductions, rNReductions;
33 
34  public:
35 
36  /// \brief Initialise an empty solution.
38  : r0Reductions(0), r1Reductions(0), r2Reductions(0), rNReductions(0) {}
39 
40  /// \brief Number of nodes for which selections have been made.
41  /// @return Number of nodes for which selections have been made.
42  unsigned numNodes() const { return selections.size(); }
43 
44  /// \brief Records a reduction via the R0 rule. Should be called from the
45  /// solver only.
46  void recordR0() { ++r0Reductions; }
47 
48  /// \brief Returns the number of R0 reductions applied to solve the problem.
49  unsigned numR0Reductions() const { return r0Reductions; }
50 
51  /// \brief Records a reduction via the R1 rule. Should be called from the
52  /// solver only.
53  void recordR1() { ++r1Reductions; }
54 
55  /// \brief Returns the number of R1 reductions applied to solve the problem.
56  unsigned numR1Reductions() const { return r1Reductions; }
57 
58  /// \brief Records a reduction via the R2 rule. Should be called from the
59  /// solver only.
60  void recordR2() { ++r2Reductions; }
61 
62  /// \brief Returns the number of R2 reductions applied to solve the problem.
63  unsigned numR2Reductions() const { return r2Reductions; }
64 
65  /// \brief Records a reduction via the RN rule. Should be called from the
66  /// solver only.
67  void recordRN() { ++ rNReductions; }
68 
69  /// \brief Returns the number of RN reductions applied to solve the problem.
70  unsigned numRNReductions() const { return rNReductions; }
71 
72  /// \brief Set the selection for a given node.
73  /// @param nodeId Node id.
74  /// @param selection Selection for nodeId.
75  void setSelection(Graph::NodeId nodeId, unsigned selection) {
76  selections[nodeId] = selection;
77  }
78 
79  /// \brief Get a node's selection.
80  /// @param nodeId Node id.
81  /// @return The selection for nodeId;
82  unsigned getSelection(Graph::NodeId nodeId) const {
83  SelectionsMap::const_iterator sItr = selections.find(nodeId);
84  assert(sItr != selections.end() && "No selection for node.");
85  return sItr->second;
86  }
87 
88  };
89 
90 }
91 
92 #endif // LLVM_CODEGEN_PBQP_SOLUTION_H
void recordR0()
Records a reduction via the R0 rule. Should be called from the solver only.
Definition: Solution.h:46
unsigned numR2Reductions() const
Returns the number of R2 reductions applied to solve the problem.
Definition: Solution.h:63
void recordR1()
Records a reduction via the R1 rule. Should be called from the solver only.
Definition: Solution.h:53
void recordRN()
Records a reduction via the RN rule. Should be called from the solver only.
Definition: Solution.h:67
unsigned getSelection(Graph::NodeId nodeId) const
Get a node's selection.
Definition: Solution.h:82
Solution()
Initialise an empty solution.
Definition: Solution.h:37
unsigned numR0Reductions() const
Returns the number of R0 reductions applied to solve the problem.
Definition: Solution.h:49
unsigned numNodes() const
Number of nodes for which selections have been made.
Definition: Solution.h:42
void setSelection(Graph::NodeId nodeId, unsigned selection)
Set the selection for a given node.
Definition: Solution.h:75
unsigned numRNReductions() const
Returns the number of RN reductions applied to solve the problem.
Definition: Solution.h:70
unsigned numR1Reductions() const
Returns the number of R1 reductions applied to solve the problem.
Definition: Solution.h:56
Represents a solution to a PBQP problem.
Definition: Solution.h:26
void recordR2()
Records a reduction via the R2 rule. Should be called from the solver only.
Definition: Solution.h:60