PCB Environment 2

Loading...
Searching...
No Matches
Reward.hpp
1
2#ifndef GYM_PCB_REWARD_H
3#define GYM_PCB_REWARD_H
4
5#include <vector>
6#include "Py.hpp"
7
8 using Reward = float;
9
10 class RewardFunction;
11 class PCBoard;
12 class Connection;
13
14 struct RouterResult
15{
16 bool isSet() const { return !std::isnan(TrackLen); }
17 float TrackLen{std::numeric_limits<float>::quiet_NaN()};
18 int16_t NumVias{0};
19 int16_t NumDisconnected{0};
20 bool operator==(const RouterResult&) const = default;
21 PyObject *getPy() const;
22};
23
24 class RewardFunction
25{
26 public:
27 static RewardFunction *create(PyObject *);
28 public:
29 virtual ~RewardFunction() { }
30 virtual void setContext(const PCBoard&) { }
31 virtual Reward operator()(const Connection&, RouterResult * = 0) const = 0;
32 virtual Reward operator()(const std::vector<Connection *>&, RouterResult * = 0) const = 0;
33 virtual Reward operator()(int unrouted) const = 0;
34};
35
36 namespace rewards
37{
38
39 class RouteLength : public RewardFunction
40{
41 public:
42 static RouteLength *create(PyObject *);
43 RouteLength();
44 virtual void setContext(const PCBoard&) override;
45 Reward operator()(const Connection&, RouterResult * = 0) const override;
46 Reward operator()(const std::vector<Connection *>&, RouterResult * = 0) const override;
47 Reward operator()(int unrouted) const override;
48 private:
49 float FPerUnrouted{0.0f};
50 float FAnyUnrouted{0.0f};
51 float FPerVia{0.0f};
52 float FPerRouted{1.0f};
53 float FScale{0.0f};
54 std::string ScaleLength;
55 std::string ScaleGlobal;
56 char ScaleLength_{0};
57 bool IgnoreNecessaryVias{true};
58};
59
60} // namespace rewards
61
62#endif // GYM_PCB_REWARD_H
Connection
Definition Connection.hpp:17
PCBoard
Definition PCBoard.hpp:36
RewardFunction
Definition Reward.hpp:25
RouterResult
Definition Reward.hpp:15