CkPttn 1.2.5
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#include "LegalCheck.hpp" // for LegalCheck
18
19// forward declare
20// template <typename graph_t> struct Netlist;
21// using SimpleNetlist = Netlist<xnetwork::SimpleGraph>;
22
67template <typename Gnl, typename GainMgr, typename ConstrMgr> //
69 public:
70 using GainCalc_ = typename GainMgr::GainCalc_;
71 using GainMgr_ = GainMgr;
72 using ConstrMgr_ = ConstrMgr;
73
74 // using Der = Derived<Gnl, GainMgr, ConstrMgr>;
75
76 protected:
78 const Gnl& hyprgraph;
80 GainMgr& gain_mgr;
82 ConstrMgr& validator;
84 size_t num_parts;
85 // std::vector<std::uint8_t> snapshot;
86 // std::vector<std::uint8_t> part;
87
88 public:
90
99 PartMgrBase(const Gnl& hyprgraph, GainMgr& gain_mgr, ConstrMgr& constr_mgr, size_t num_parts)
101
107 void init(std::span<std::uint8_t> part);
108
115 auto legalize(std::span<std::uint8_t> part) -> LegalCheck;
116
122 void optimize(std::span<std::uint8_t> part);
123
124 protected:
134 virtual void _optimize_1pass(std::span<std::uint8_t> part);
135
136 private:
142 auto final_check(std::span<const std::uint8_t> part) -> bool {
143 return this->validator.final_check(part);
144 }
145
156 auto take_snapshot(std::span<const std::uint8_t> part) -> std::vector<std::uint8_t> {
157 // const auto N = part.size();
158 // auto snapshot = std::vector<std::uint8_t>(N, 0U);
159 // // snapshot.reserve(N);
160 // for (auto i = 0U; i != N; ++i)
161 // {
162 // snapshot[i] = part[i];
163 // }
164 auto snapshot = std::vector<std::uint8_t>(part.begin(), part.end());
165 return snapshot;
166 }
167
178 auto restore_part(const std::vector<std::uint8_t>& snapshot, std::span<std::uint8_t> part)
179 -> void {
180 // std::copy(snapshot.begin(), snapshot.end(), part.begin());
181 const auto N = part.size();
182 for (auto idx = 0U; idx != N; ++idx) {
183 part[idx] = snapshot[idx];
184 }
185 }
186};
Result of a partition legality check.
LegalCheck
Check if the move of v can be satisfied, get better, or not satisfied.
Definition LegalCheck.hpp:11
Fiduccia-Mattheyses Partitioning Algorithm Manager Base.
Definition PartMgrBase.hpp:68
int total_cost
Definition PartMgrBase.hpp:89
size_t num_parts
Number of partitions.
Definition PartMgrBase.hpp:84
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:70
GainMgr & gain_mgr
Gain manager for computing and managing gains.
Definition PartMgrBase.hpp:80
GainMgr GainMgr_
Definition PartMgrBase.hpp:71
ConstrMgr ConstrMgr_
Definition PartMgrBase.hpp:72
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:99
virtual void _optimize_1pass(std::span< std::uint8_t > part)
Performs a single pass of the FM optimization algorithm.
ConstrMgr & validator
Constraint manager for validating partition constraints.
Definition PartMgrBase.hpp:82
const Gnl & hyprgraph
Reference to the hypergraph being partitioned.
Definition PartMgrBase.hpp:78