summaryrefslogtreecommitdiffstats
path: root/lib/CodeGen/PBQP/Solution.h
blob: aee684d33e1b50765d68debb2fb67bbf3711fcd1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//===-- Solution.h ------- PBQP Solution ------------------------*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// Annotated PBQP Graph class. This class is used internally by the PBQP solver
// to cache information to speed up reduction.
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_CODEGEN_PBQP_SOLUTION_H
#define LLVM_CODEGEN_PBQP_SOLUTION_H

#include "PBQPMath.h"

namespace PBQP {

class Solution {

  friend class SolverImplementation;

private:

  std::vector<unsigned> selections;
  PBQPNum solutionCost;
  bool provedOptimal;
  unsigned r0Reductions, r1Reductions,
           r2Reductions, rNReductions;

public:

  Solution() :
    solutionCost(0.0), provedOptimal(false),
    r0Reductions(0), r1Reductions(0), r2Reductions(0), rNReductions(0) {}

  Solution(unsigned length, bool assumeOptimal) :
    selections(length), solutionCost(0.0), provedOptimal(assumeOptimal),
    r0Reductions(0), r1Reductions(0), r2Reductions(0), rNReductions(0) {}

  void setProvedOptimal(bool provedOptimal) {
    this->provedOptimal = provedOptimal;
  }

  void setSelection(unsigned nodeID, unsigned selection) {
    selections[nodeID] = selection;
  }

  void setSolutionCost(PBQPNum solutionCost) {
    this->solutionCost = solutionCost;
  }

  void incR0Reductions() { ++r0Reductions; }
  void incR1Reductions() { ++r1Reductions; }
  void incR2Reductions() { ++r2Reductions; }
  void incRNReductions() { ++rNReductions; }

  unsigned numNodes() const { return selections.size(); }

  unsigned getSelection(unsigned nodeID) const {
    return selections[nodeID];
  }

  PBQPNum getCost() const { return solutionCost; }

  bool isProvedOptimal() const { return provedOptimal; }

  unsigned getR0Reductions() const { return r0Reductions; }
  unsigned getR1Reductions() const { return r1Reductions; }
  unsigned getR2Reductions() const { return r2Reductions; }
  unsigned getRNReductions() const { return rNReductions; }

  bool operator==(const Solution &other) const {
    return (selections == other.selections);
  }

  bool operator!=(const Solution &other) const {
    return !(*this == other);
  }

};

}

#endif // LLVM_CODEGEN_PBQP_SOLUTION_H
OpenPOWER on IntegriCloud