LLVM API Documentation

Solution.h
Go to the documentation of this file.
00001 //===-- Solution.h ------- PBQP Solution ------------------------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // PBQP Solution class.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #ifndef LLVM_CODEGEN_PBQP_SOLUTION_H
00015 #define LLVM_CODEGEN_PBQP_SOLUTION_H
00016 
00017 #include "Graph.h"
00018 #include "Math.h"
00019 #include <map>
00020 
00021 namespace PBQP {
00022 
00023   /// \brief Represents a solution to a PBQP problem.
00024   ///
00025   /// To get the selection for each node in the problem use the getSelection method.
00026   class Solution {
00027   private:
00028 
00029     typedef std::map<GraphBase::NodeId, unsigned> SelectionsMap;
00030     SelectionsMap selections;
00031 
00032     unsigned r0Reductions, r1Reductions, r2Reductions, rNReductions;
00033 
00034   public:
00035 
00036     /// \brief Initialise an empty solution.
00037     Solution()
00038       : r0Reductions(0), r1Reductions(0), r2Reductions(0), rNReductions(0) {}
00039 
00040     /// \brief Number of nodes for which selections have been made.
00041     /// @return Number of nodes for which selections have been made.
00042     unsigned numNodes() const { return selections.size(); }
00043 
00044     /// \brief Records a reduction via the R0 rule. Should be called from the
00045     ///        solver only.
00046     void recordR0() { ++r0Reductions; }
00047 
00048     /// \brief Returns the number of R0 reductions applied to solve the problem.
00049     unsigned numR0Reductions() const { return r0Reductions; }
00050 
00051     /// \brief Records a reduction via the R1 rule. Should be called from the
00052     ///        solver only.
00053     void recordR1() { ++r1Reductions; }
00054 
00055     /// \brief Returns the number of R1 reductions applied to solve the problem.
00056     unsigned numR1Reductions() const { return r1Reductions; }
00057 
00058     /// \brief Records a reduction via the R2 rule. Should be called from the
00059     ///        solver only.
00060     void recordR2() { ++r2Reductions; }
00061 
00062     /// \brief Returns the number of R2 reductions applied to solve the problem.
00063     unsigned numR2Reductions() const { return r2Reductions; }
00064 
00065     /// \brief Records a reduction via the RN rule. Should be called from the
00066     ///        solver only.
00067     void recordRN() { ++ rNReductions; }
00068 
00069     /// \brief Returns the number of RN reductions applied to solve the problem.
00070     unsigned numRNReductions() const { return rNReductions; }
00071 
00072     /// \brief Set the selection for a given node.
00073     /// @param nodeId Node id.
00074     /// @param selection Selection for nodeId.
00075     void setSelection(GraphBase::NodeId nodeId, unsigned selection) {
00076       selections[nodeId] = selection;
00077     }
00078 
00079     /// \brief Get a node's selection.
00080     /// @param nodeId Node id.
00081     /// @return The selection for nodeId;
00082     unsigned getSelection(GraphBase::NodeId nodeId) const {
00083       SelectionsMap::const_iterator sItr = selections.find(nodeId);
00084       assert(sItr != selections.end() && "No selection for node.");
00085       return sItr->second;
00086     }
00087 
00088   };
00089 
00090 }
00091 
00092 #endif // LLVM_CODEGEN_PBQP_SOLUTION_H