TTK
Loading...
Searching...
No Matches
PersistenceDiagramWarmRestartAuction.h
Go to the documentation of this file.
1
13
14#pragma once
15
17
18namespace ttk {
19 using RipsPersistencePair = std::pair<std::pair<std::vector<int>, double>,
20 std::pair<std::vector<int>, double>>;
21 using ValuesPair = std::pair<double, double>;
22
23 template <typename T>
26
27 public:
28 PersistenceDiagramWarmRestartAuction(const std::vector<T> &goodDiagram) {
29 setDebugMsgPrefix("PersistenceDiagramWarmRestartAuction");
30
31 std::vector<double> coordinates(0);
32 std::vector<std::vector<double>> weights(1);
33 for(unsigned i = 0; i < goodDiagram.size(); ++i) {
34 const ValuesPair &g = getPair(goodDiagram[i]);
35 goods_.emplace_back(g.first, g.second, false, i);
36 coordinates.push_back(g.first);
37 coordinates.push_back(g.second);
38 weights[0].push_back(0.);
39 }
40
41 kdt_ = std::make_unique<KDT>(true, wasserstein_);
42 correspondence_kdt_map_
43 = kdt_->build(coordinates.data(), goodDiagram.size(), 2, weights, 1);
44 }
45
46 void setNewBidder(const std::vector<T> &bidderDiagram) {
47 bidders_.resize(0);
48
49 for(unsigned i = 0; i < bidderDiagram.size(); ++i) {
50 const ValuesPair &b = getPair(bidderDiagram[i]);
51 Bidder bidder(b.first, b.second, false, i);
52 bidder.setPositionInAuction(i);
53 bidders_.emplace_back(bidder);
54 }
55 }
56
58 for(Good &g : goods_)
59 g.setPrice(0.);
60 }
61
62 double runAuction(std::vector<MatchingType> &matchings) {
63 PersistenceDiagramAuction auction(bidders_, goods_, wasserstein_, 1., 1.,
64 delta_, *kdt_, correspondence_kdt_map_);
65 Timer t;
66
67 matchings.resize(0);
69
70 const double w = auction.run(matchings);
71
72 printMsg("Auction completed", 1.0, t.getElapsedTime());
73
74 return w;
75 }
76
77 double runAuction() {
78 std::vector<MatchingType> matchings;
79 return runAuction(matchings);
80 }
81
82 inline void setWasserstein(double wasserstein) {
83 wasserstein_ = wasserstein;
84 }
85
86 inline void setDelta(double delta) {
87 delta_ = delta;
88 }
89
90 private:
91 double wasserstein_{2.};
92 double delta_{0.01};
93
94 std::unique_ptr<KDT> kdt_;
95 std::vector<KDT *> correspondence_kdt_map_;
96
97 GoodDiagram goods_;
98 BidderDiagram bidders_;
99
100 static inline ValuesPair getPair(const T &p) {
101 return {p.first, p.second};
102 };
103 };
104
105 template <>
106 inline ValuesPair
107 PersistenceDiagramWarmRestartAuction<RipsPersistencePair>::getPair(
108 const RipsPersistencePair &p) {
109 return {p.first.second, p.second.second};
110 }
111
112 template <>
113 inline ValuesPair
114 PersistenceDiagramWarmRestartAuction<PersistencePair>::getPair(
115 const PersistencePair &p) {
116 return {p.birth.sfValue, p.death.sfValue};
117 }
118} // namespace ttk
void setPositionInAuction(const int pos)
void setDebugMsgPrefix(const std::string &prefix)
Definition Debug.h:364
double run(std::vector< MatchingType > &matchings, const int kdt_index=0)
PersistenceDiagramWarmRestartAuction(const std::vector< T > &goodDiagram)
void setNewBidder(const std::vector< T > &bidderDiagram)
double runAuction(std::vector< MatchingType > &matchings)
double getElapsedTime()
Definition Timer.h:15
TTK base package defining the standard types.
std::pair< double, double > ValuesPair
std::vector< Good > GoodDiagram
std::pair< std::pair< std::vector< int >, double >, std::pair< std::vector< int >, double > > RipsPersistencePair
std::vector< Bidder > BidderDiagram
printMsg(debug::output::BOLD+" | | | | | . \\ | | (__| | / __/| |_| / __/| (_) |"+debug::output::ENDCOLOR, debug::Priority::PERFORMANCE, debug::LineMode::NEW, stream)