CkPttn 1.2.4
Loading...
Searching...
No Matches
PartMgrBase.hpp
Go to the documentation of this file.
1
6#pragma once
7
8// **Special code for two-pin nets**
9// Take a snapshot when a move make **negative** gain.
10// Snapshot in the form of "interface"???
11
12#include <cstdint> // for uint8_t
13#include <span> // for span
14#include <vector> // for vector
15// #include <xnetwork/classes/graph.hpp>
16
17// forward declare
18// template <typename graph_t> struct Netlist;
19// using SimpleNetlist = Netlist<xnetwork::SimpleGraph>;
20
21enum class LegalCheck;
22
53template <typename Gnl, typename GainMgr, typename ConstrMgr> //
55 public:
56 using GainCalc_ = typename GainMgr::GainCalc_;
57 using GainMgr_ = GainMgr;
58 using ConstrMgr_ = ConstrMgr;
59
60 // using Der = Derived<Gnl, GainMgr, ConstrMgr>;
61
62 protected:
64 const Gnl& hyprgraph;
66 GainMgr& gain_mgr;
68 ConstrMgr& validator;
70 size_t num_parts;
71 // std::vector<std::uint8_t> snapshot;
72 // std::vector<std::uint8_t> part;
73
74 public:
76
85 PartMgrBase(const Gnl& hyprgraph, GainMgr& gain_mgr, ConstrMgr& constr_mgr, size_t num_parts)
87
93 void init(std::span<std::uint8_t> part);
94
101 auto legalize(std::span<std::uint8_t> part) -> LegalCheck;
102
108 void optimize(std::span<std::uint8_t> part);
109
110 private:
116 void _optimize_1pass(std::span<std::uint8_t> part);
117
123 auto final_check(std::span<const std::uint8_t> part) -> bool {
124 return this->validator.final_check(part);
125 }
126
133 auto take_snapshot(std::span<const std::uint8_t> part) -> std::vector<std::uint8_t> {
134 // const auto N = part.size();
135 // auto snapshot = std::vector<std::uint8_t>(N, 0U);
136 // // snapshot.reserve(N);
137 // for (auto i = 0U; i != N; ++i)
138 // {
139 // snapshot[i] = part[i];
140 // }
141 auto snapshot = std::vector<std::uint8_t>(part.begin(), part.end());
142 return snapshot;
143 }
144
151 auto restore_part(const std::vector<std::uint8_t>& snapshot, std::span<std::uint8_t> part)
152 -> void {
153 // std::copy(snapshot.begin(), snapshot.end(), part.begin());
154 const auto N = part.size();
155 for (auto idx = 0U; idx != N; ++idx) {
156 part[idx] = snapshot[idx];
157 }
158 }
159};
LegalCheck
Check if the move of v can satisfied, GetBetter, or NotSatisfied.
Definition FMConstrMgr.hpp:22
Fiduccia-Mattheyses Partitioning Algorithm Manager Base.
Definition PartMgrBase.hpp:54
int total_cost
Definition PartMgrBase.hpp:75
size_t num_parts
Number of partitions.
Definition PartMgrBase.hpp:70
auto legalize(std::span< std::uint8_t > part) -> LegalCheck
Legalizes the partition to satisfy balance constraints.
void optimize(std::span< std::uint8_t > part)
Optimizes the partition using the FM algorithm.
typename GainMgr::GainCalc_ GainCalc_
Definition PartMgrBase.hpp:56
GainMgr & gain_mgr
Gain manager for computing and managing gains.
Definition PartMgrBase.hpp:66
GainMgr GainMgr_
Definition PartMgrBase.hpp:57
ConstrMgr ConstrMgr_
Definition PartMgrBase.hpp:58
void init(std::span< std::uint8_t > part)
Initializes the partition manager with the given partition.
PartMgrBase(const Gnl &hyprgraph, GainMgr &gain_mgr, ConstrMgr &constr_mgr, size_t num_parts)
Construct a new Part Mgr Base object.
Definition PartMgrBase.hpp:85
ConstrMgr & validator
Constraint manager for validating partition constraints.
Definition PartMgrBase.hpp:68
const Gnl & hyprgraph
Reference to the hypergraph being partitioned.
Definition PartMgrBase.hpp:64