1
2 // This file is part of the Alliance Project.
3 // Copyright (C) Laboratoire LIP6 - Departement ASIM
4 // Universite Pierre et Marie Curie
5 //
6 // The Alliance Project is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License as
8 // published by the Free Software Foundation; either version 2 of the
9 // License, or (at your option) any later version.
10 //
11 // The Alliance Project is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with the Alliance Project; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 //
20 //
21 // License-Tag
22 //
23 // Date : 29/01/2004
24 // Author : Christophe Alexandre <Christophe.Alexandre@lip6.fr>
25 //
26 // Authors-Tag
27 #include <string.h>
28 #include "PPlacement.h"
29 #include "PConstants.h"
30 #include "PBBox.h"
31
32 #include "PRow.h"
33
PRow(unsigned nbofsubrows)34 PRow::PRow(unsigned nbofsubrows)
35 : PContainer(), _subRows(nbofsubrows)
36 {
37 for (PSubRows::iterator srit=_subRows.begin();
38 srit!=_subRows.end();
39 srit++)
40 {
41 *srit = new PSubRow();
42 }
43 }
44
PRow(PPlacement & placement,const double ymin,const double xmax,const unsigned nbofsubrows,const bool orientation)45 PRow::PRow(PPlacement& placement,
46 const double ymin, const double xmax,
47 const unsigned nbofsubrows,
48 const bool orientation)
49 : PContainer(PBBox(PPos(0.0, ymin), PPos(xmax, ymin + ROWHEIGHT))),
50 _placement(&placement),
51 _subRows(nbofsubrows),
52 _orientation(orientation)
53 {
54 for (PSubRows::iterator srit=_subRows.begin();
55 srit!=_subRows.end();
56 srit++)
57 *srit = new PSubRow();
58 }
59
~PRow()60 PRow::~PRow()
61 {
62 for (PSubRows::iterator srit=_subRows.begin();
63 srit!=_subRows.end();
64 srit++)
65 delete *srit;
66 }
67
68 void
Init(double y,double minx,PPlacement & placement,const bool orientation)69 PRow::Init(double y, double minx, PPlacement &placement, const bool orientation)
70 {
71 _placement = &placement;
72 _orientation = orientation;
73
74 _bBox.SetMinY(y);
75 _bBox.SetMaxY(y);
76 _bBox.SetMinX(minx);
77 _bBox.SetMaxX(minx);
78 }
79
80 #ifndef Abs
81 #define Abs(x) ((x) < 0.0 ? -(x) : (x))
82 #endif
83
84 double
GetBinCost() const85 PRow::GetBinCost() const
86 {
87 double bincost = 0.0;
88 for (PSubRows::const_iterator srit = _subRows.begin(); srit != _subRows.end(); srit++)
89 {
90 bincost += (*srit)->GetBinCost();
91 }
92 return bincost;
93 }
94
95 double
GetSubRowCost() const96 PRow::GetSubRowCost() const
97 {
98 double subrowcost = 0.0;
99 for (PSubRows::const_iterator srit = _subRows.begin(); srit != _subRows.end(); srit++)
100 {
101 subrowcost += Abs((*srit)->GetSize() - (*srit)->GetCapa());
102 }
103 return subrowcost;
104 }
105
106 PSubRow&
GetSubRow(const double X)107 PRow::GetSubRow(const double X)
108 {
109 // s'il y a un seul subrow on le renvoie direct
110 if (_subRows.size() == 1)
111 return *_subRows[0];
112
113 // si il n'y a rien a droite
114 PSubRowsXMax::iterator right = _subRowsXMax.lower_bound(X);
115 PSubRowsXMax::iterator left = _subRowsXMaxInv.lower_bound(X);
116
117 if (right == _subRowsXMax.end())
118 {
119 if (left == _subRowsXMaxInv.end())
120 {
121 cerr << " o INTERNAL ERROR: GetSubRow()" << endl;
122 exit(1);
123 }
124 return *_subRows[left->second];
125 }
126
127 // si on est tombe direct dans un subrow...
128 double rightminx = _subRows[right->second]->GetMinX();
129 if (X > rightminx)
130 return *_subRows[right->second];
131
132
133 // si il n'y a rien a gauche...
134 if (left == _subRowsXMaxInv.end())
135 {
136 if (right == _subRowsXMax.end())
137 {
138 cerr << " o INTERNAL ERROR: GetSubRow()" << endl;
139 exit(1);
140 }
141 return *_subRows[right->second];
142 }
143
144 // on est au milieu de deux subrows, on
145 // renvoie le plus proche.
146
147 if ((X - _subRows[left->second]->GetMaxX())
148 > (_subRows[right->second]->GetMinX() - X))
149 {
150 return *_subRows[right->second];
151 }
152 else
153 {
154 return *_subRows[left->second];
155 }
156 }
157
158 ofstream&
Plot(ofstream & out) const159 PRow::Plot(ofstream& out) const
160 {
161 for (PSubRows::const_iterator srit=_subRows.begin(); srit!=_subRows.end(); srit++)
162 {
163 (*srit)->Plot(out);
164 }
165 return out;
166 }
167
168 ofstream&
PlotLabel(ofstream & out,unsigned TotalMoves) const169 PRow::PlotLabel(ofstream& out, unsigned TotalMoves) const
170 {
171 for (PSubRows::const_iterator srit=_subRows.begin(); srit!=_subRows.end(); srit++)
172 {
173 (*srit)->PlotLabel(out, TotalMoves);
174 }
175 return out;
176 }
177
GetBinsSize() const178 double PRow::GetBinsSize() const
179 {
180 double binsSize = 0.0;
181 for (PSubRows::const_iterator srit=_subRows.begin(); srit!=_subRows.end(); srit++)
182 {
183 binsSize += (*srit)->GetBinsSize();
184 }
185 return binsSize;
186 }
187
GetBinsCapa() const188 double PRow::GetBinsCapa() const
189 {
190 double binsCapa = 0.0;
191 for (PSubRows::const_iterator srit=_subRows.begin(); srit!=_subRows.end(); srit++)
192 {
193 binsCapa += (*srit)->GetBinsCapa();
194 }
195 return binsCapa;
196 }
197
GetSubRowsCapa() const198 double PRow::GetSubRowsCapa() const
199 {
200 double subRowsCapa = 0.0;
201 for (PSubRows::const_iterator srit=_subRows.begin(); srit!=_subRows.end(); srit++)
202 {
203 subRowsCapa += (*srit)->GetCapa();
204 }
205 return subRowsCapa;
206 }
207
Print(ostream & os) const208 ostream& PRow::Print(ostream& os) const
209 {
210 string orientation;
211 if (_orientation) {
212 orientation = "ON";
213 } else {
214 orientation = "OFF";
215 }
216 return os << "PRow: " << GetMinX() << ',' << GetMinY() <<
217 " : " << GetMaxX() << ',' << GetMaxY() << "," << orientation;
218 }
219