Lang Hames | 421c073 | 2010-01-06 08:53:34 +0000 | [diff] [blame] | 1 | //===-- Solution.h ------- PBQP Solution ------------------------*- C++ -*-===// |
Lang Hames | caaf120 | 2009-08-07 00:25:12 +0000 | [diff] [blame] | 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 | // Annotated PBQP Graph class. This class is used internally by the PBQP solver |
| 11 | // to cache information to speed up reduction. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
Lang Hames | 6699fb2 | 2009-08-06 23:32:48 +0000 | [diff] [blame] | 15 | #ifndef LLVM_CODEGEN_PBQP_SOLUTION_H |
| 16 | #define LLVM_CODEGEN_PBQP_SOLUTION_H |
| 17 | |
| 18 | #include "PBQPMath.h" |
| 19 | |
| 20 | namespace PBQP { |
| 21 | |
| 22 | class Solution { |
| 23 | |
| 24 | friend class SolverImplementation; |
| 25 | |
| 26 | private: |
| 27 | |
| 28 | std::vector<unsigned> selections; |
| 29 | PBQPNum solutionCost; |
| 30 | bool provedOptimal; |
| 31 | unsigned r0Reductions, r1Reductions, |
| 32 | r2Reductions, rNReductions; |
| 33 | |
| 34 | public: |
| 35 | |
| 36 | Solution() : |
| 37 | solutionCost(0.0), provedOptimal(false), |
| 38 | r0Reductions(0), r1Reductions(0), r2Reductions(0), rNReductions(0) {} |
| 39 | |
| 40 | Solution(unsigned length, bool assumeOptimal) : |
| 41 | selections(length), solutionCost(0.0), provedOptimal(assumeOptimal), |
| 42 | r0Reductions(0), r1Reductions(0), r2Reductions(0), rNReductions(0) {} |
| 43 | |
| 44 | void setProvedOptimal(bool provedOptimal) { |
| 45 | this->provedOptimal = provedOptimal; |
| 46 | } |
| 47 | |
| 48 | void setSelection(unsigned nodeID, unsigned selection) { |
| 49 | selections[nodeID] = selection; |
| 50 | } |
| 51 | |
| 52 | void setSolutionCost(PBQPNum solutionCost) { |
| 53 | this->solutionCost = solutionCost; |
| 54 | } |
| 55 | |
| 56 | void incR0Reductions() { ++r0Reductions; } |
| 57 | void incR1Reductions() { ++r1Reductions; } |
| 58 | void incR2Reductions() { ++r2Reductions; } |
| 59 | void incRNReductions() { ++rNReductions; } |
| 60 | |
| 61 | unsigned numNodes() const { return selections.size(); } |
| 62 | |
| 63 | unsigned getSelection(unsigned nodeID) const { |
| 64 | return selections[nodeID]; |
| 65 | } |
| 66 | |
| 67 | PBQPNum getCost() const { return solutionCost; } |
| 68 | |
| 69 | bool isProvedOptimal() const { return provedOptimal; } |
| 70 | |
| 71 | unsigned getR0Reductions() const { return r0Reductions; } |
| 72 | unsigned getR1Reductions() const { return r1Reductions; } |
| 73 | unsigned getR2Reductions() const { return r2Reductions; } |
| 74 | unsigned getRNReductions() const { return rNReductions; } |
| 75 | |
| 76 | bool operator==(const Solution &other) const { |
| 77 | return (selections == other.selections); |
| 78 | } |
| 79 | |
| 80 | bool operator!=(const Solution &other) const { |
| 81 | return !(*this == other); |
| 82 | } |
| 83 | |
| 84 | }; |
| 85 | |
| 86 | } |
| 87 | |
| 88 | #endif // LLVM_CODEGEN_PBQP_SOLUTION_H |