1 /**************************************************************************
2 ***
3 *** Copyright (c) 2000-2006 Regents of the University of Michigan,
4 *** Saurabh N. Adya, Hayward Chan, Jarrod A. Roy
5 *** and Igor L. Markov
6 ***
7 *** Contact author(s): sadya@umich.edu, imarkov@umich.edu
8 *** Original Affiliation: University of Michigan, EECS Dept.
9 *** Ann Arbor, MI 48109-2122 USA
10 ***
11 *** Permission is hereby granted, free of charge, to any person obtaining
12 *** a copy of this software and associated documentation files (the
13 *** "Software"), to deal in the Software without restriction, including
14 *** without limitation
15 *** the rights to use, copy, modify, merge, publish, distribute, sublicense,
16 *** and/or sell copies of the Software, and to permit persons to whom the
17 *** Software is furnished to do so, subject to the following conditions:
18 ***
19 *** The above copyright notice and this permission notice shall be included
20 *** in all copies or substantial portions of the Software.
21 ***
22 *** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 *** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
24 *** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
25 *** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
26 *** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
27 *** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
28 *** THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 ***
30 ***
31 ***************************************************************************/
32
33 #ifndef BASEANNEALER_H
34 #define BASEANNEALER_H
35
36 #include <random>
37 #include <string>
38
39 #include "AnalytSolve.h"
40 #include "CommandLine.h"
41 #include "DB.h"
42 #include "basepacking.h"
43
44 // --------------------------------------------------------
45 class BaseAnnealer
46 {
47 public:
48 BaseAnnealer(const parquetfp::Command_Line* const params,
49 parquetfp::DB* const db);
50 virtual ~BaseAnnealer();
51
52 virtual bool go() = 0; // go() == entire annealing process
53 virtual bool packOneBlock() = 0; // floorplan only one block
54
55 virtual void takePlfromDB() = 0; // get init soln from *db
56 virtual void solveQP(); // get a quad-minimum soln and update *db
57 virtual void compactSoln(bool minWL,
58 bool fixedOutline,
59 float reqdH,
60 float reqdW)
61 = 0;
62 void postHPWLOpt();
63
64 inline float isFixedOutline() const;
65 inline float outlineDeadspaceRatio() const;
66 inline float outlineArea() const;
67 inline float outlineWidth() const;
68 inline float outlineHeight() const;
69
70 // basic constants for readability
71 static const int UNINITIALIZED;
72 static const unsigned int UNSIGNED_UNINITIALIZED;
73 static const int FREE_OUTLINE;
74 static const int NOT_FOUND;
75
76 enum MOVE_TYPES
77 {
78 MISC = -1,
79 NOOP = 0,
80 REP_SPEC_MIN = 1, // representation-specific
81 REP_SPEC_ORIENT = 2,
82 REP_SPEC_MAX = 5,
83 SLACKS_MOVE = 6,
84 AR_MOVE = 7,
85 ORIENT = 10,
86 SOFT_BL = 11,
87 HPWL = 12,
88 ARWL = 13
89 };
90
91 class SolutionInfo
92 {
93 public:
SolutionInfo()94 SolutionInfo()
95 : area(UNINITIALIZED),
96 width(UNINITIALIZED),
97 height(UNINITIALIZED),
98 HPWL(UNINITIALIZED)
99 {
100 }
101
102 float area;
103 float width;
104 float height;
105 float HPWL;
106 };
107 void printResults(const SolutionInfo& curr) const;
108 float annealTime;
109
110 protected:
111 parquetfp::DB* const _db; // _db, _params behaves like
112 const parquetfp::Command_Line* const _params; // references, use ptrs for
113 parquetfp::AnalytSolve* const _analSolve; // code backwd compatibility
114 std::string _baseFileName;
115
116 const bool _isFixedOutline;
117 const float _outlineDeadspaceRatio;
118 const float _outlineArea;
119 const float _outlineWidth;
120 const float _outlineHeight;
121 std::random_device _rd;
122 std::mt19937 _random_gen;
123
BaseAnnealer()124 BaseAnnealer()
125 : annealTime(0),
126 _db(NULL),
127 _params(NULL),
128 _analSolve(NULL),
129 _isFixedOutline(false),
130 _outlineDeadspaceRatio(basepacking_h::Dimension::Infty),
131 _outlineArea(basepacking_h::Dimension::Infty),
132 _outlineWidth(basepacking_h::Dimension::Infty),
133 _outlineHeight(basepacking_h::Dimension::Infty)
134 { /* compilerCheck(); */
135 }
136 };
137 // --------------------------------------------------------
138
isFixedOutline()139 inline float BaseAnnealer::isFixedOutline() const
140 {
141 return _isFixedOutline;
142 }
143 // --------------------------------------------------------
outlineDeadspaceRatio()144 inline float BaseAnnealer::outlineDeadspaceRatio() const
145 {
146 return _outlineDeadspaceRatio;
147 }
148 // --------------------------------------------------------
outlineArea()149 inline float BaseAnnealer::outlineArea() const
150 {
151 return _outlineArea;
152 }
153 // --------------------------------------------------------
outlineWidth()154 inline float BaseAnnealer::outlineWidth() const
155 {
156 return _outlineWidth;
157 }
158 // --------------------------------------------------------
outlineHeight()159 inline float BaseAnnealer::outlineHeight() const
160 {
161 return _outlineHeight;
162 }
163 // --------------------------------------------------------
164
165 #endif
166