TraceMaker
C++ API of the engine
Loading...
Searching...
No Matches
lower_bound.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-3.0-or-later
2#pragma once
3// Exact lower bound on weighted HPWL (design doc 04 §1 level L4).
4//
5// Without overlap and outline constraints, minimising Σ_n w_n (max_i x_i − min_i x_i) over the movable
6// parts' positions is a linear program whose constraints are all differences (U_n − X_p ≥ o, X_p − L_n ≥ −o),
7// so its dual is an uncapacitated min-cost flow from the nets' upper nodes U_n through the parts (or the fixed
8// "ground" node) to the nets' lower nodes L_n. Solved exactly in integers by successive shortest paths
9// (Ahuja, Magnanti, Orlin, "Network Flows", 1993, ch. 9). By LP duality the optimum equals the minimum of the
10// relaxed placement problem, so it bounds every legal placement from below.
11#include <cstdint>
12
13#include "place/legality.hpp"
14
15namespace tmk::place {
16
17enum class RotationModel {
18 Fixed, // movable parts keep the rotations in the given placement: the exact relaxed optimum for them
19 Any, // valid for every rotation of the movable parts (each pin may take its most favourable offset
20 // per axis independently; both sides for parts that may flip): a weaker bound that also holds for our
21 // final placement
22};
23
24// Minimum weighted HPWL (Σ weight · HPWL, nm) over all positions of the movable parts with overlaps and the
25// board outline ignored. Fixed parts are taken from `pl`.
26std::int64_t hpwl_lower_bound(const Problem& p, const Placement& pl, RotationModel model);
27
28// Min-cost flow on a small graph (exposed for tests). Successive shortest paths with Dijkstra and
29// potentials; arcs from add_arc have infinite capacity unless `cap` is given. Costs are integers.
31 public:
32 explicit MinCostFlow(int n) : head_(static_cast<std::size_t>(n), -1) {}
33 static constexpr std::int64_t kInf = INT64_MAX / 4;
34 void add_arc(int u, int v, std::int64_t cost, std::int64_t cap = kInf);
35 // Sends up to `limit` units from s to t at minimum cost; returns {flow, cost}. The graph must have no
36 // negative cycle; negative arc costs are allowed (initial potentials by Bellman–Ford).
37 std::pair<std::int64_t, std::int64_t> solve(int s, int t, std::int64_t limit);
38
39 private:
40 struct Arc {
41 int to, next;
42 std::int64_t cap, cost;
43 };
44 std::vector<int> head_;
45 std::vector<Arc> arcs_;
46};
47
48} // namespace tmk::place
static constexpr std::int64_t kInf
void add_arc(int u, int v, std::int64_t cost, std::int64_t cap=kInf)
std::pair< std::int64_t, std::int64_t > solve(int s, int t, std::int64_t limit)
Sends up to limit units from s to t at minimum cost; returns {flow, cost}.
Placement legality (design doc 04 §3 D/E): exact integer tests of courtyards, through-hole obstacles,...
@ Fixed
movable parts keep the rotations in the given placement: the exact relaxed optimum for them
@ Any
valid for every rotation of the movable parts (each pin may take its most favourable offset
std::int64_t hpwl_lower_bound(const Problem &p, const Placement &pl, RotationModel model)
Minimum weighted HPWL (Σ weight · HPWL, nm) over all positions of the movable parts with overlaps and...