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 <algorithm>
28 using namespace std;
29
30 #include "PSubRow.h"
31 #include "PBin.h"
32 #include "PDetPlacement.h"
33
34 #include "PDetSubRow.h"
35
~PDetSubRow()36 PDetSubRow::~PDetSubRow()
37 {
38 for (PDetInsVector::iterator iit = _detInsVector.begin();
39 iit != _detInsVector.end(); iit++)
40 delete *iit;
41 }
42
PDetSubRow(PSubRow & subrow)43 PDetSubRow::PDetSubRow(PSubRow& subrow):
44 PContainer(subrow.GetBBox()),
45 _orientation(subrow.GetOrientation())
46 {
47 unsigned nbins = 0;
48 // on compte le nombre d'instances dans la sousrow
49 for (PSubRow::PBins::iterator bit = subrow.GetBins().begin();
50 bit != subrow.GetBins().end();
51 bit++)
52 {
53 nbins += (*bit)->GetToPlaceInss().size();
54 }
55 _detInsVector.reserve(nbins);
56
57 // maintenant on cree les instances
58 for (PSubRow::PBins::iterator bit = subrow.GetBins().begin();
59 bit != subrow.GetBins().end();
60 bit++)
61 {
62 for (PBin::PToPlaceInss::iterator iit = (*bit)->GetToPlaceInss().begin();
63 iit != (*bit)->GetToPlaceInss().end();
64 iit++)
65 {
66 _detInsVector.push_back(new PDetToPlaceIns(*iit));
67 }
68 }
69 }
70
71 void
ExpandInstances(const bool eqmargin)72 PDetSubRow::ExpandInstances(const bool eqmargin)
73 {
74 unsigned nins = _detInsVector.size();
75 double totalinssize = 0;
76 for (PDetInsVector::iterator iit = _detInsVector.begin();
77 iit != _detInsVector.end();
78 iit++)
79 {
80 totalinssize += (*iit)->GetWidth();
81 }
82 //xtof: 06 05 2002
83 //changing the white space repartition
84 //We want the maximum 2-pitch spaces for bodie-tie insertion
85
86 double whitespace = GetWidth() - totalinssize;
87 double inswhitespace = 0.0;
88 double whitespaceremain = 0.0;
89 if (eqmargin)
90 {
91 inswhitespace = (double)(int)(whitespace / nins);
92 whitespaceremain = (double)(int)(whitespace
93 - nins * inswhitespace + 0.5);
94 }
95 else
96 {
97 inswhitespace = (double)(int)(whitespace / (2 * nins));
98 inswhitespace *= 2;
99 whitespaceremain = (double)(int)(whitespace
100 - nins * inswhitespace + 0.5);
101 }
102 for (PDetInsVector::iterator iit = _detInsVector.begin();
103 iit != _detInsVector.end();
104 iit++)
105 {
106 (*iit)->SetMarginWidth((*iit)->GetWidth() + inswhitespace);
107 }
108 PDetInsVector::iterator iit = _detInsVector.begin();
109 if (eqmargin)
110 {
111 while (whitespaceremain-- > 0.0)
112 {
113 (*iit++)->AddWhiteSpace();
114 }
115 }
116 else
117 {
118 while (whitespaceremain >= 2.0)
119 {
120 (*iit++)->AddDoubleWhiteSpace();
121 whitespaceremain -= 2.0;
122 }
123 if (whitespaceremain > 0.0)
124 {
125 (*iit)->AddWhiteSpace();
126 }
127 }
128
129 double XPos = GetMinX();
130 for (PDetInsVector::iterator iit = _detInsVector.begin();
131 iit != _detInsVector.end();
132 iit++)
133 {
134 (*iit)->SetLeftCornerX(XPos);
135 XPos += (*iit)->GetMarginWidth();
136 }
137 }
138
139 class CompareInsPosition
140 {
141 vector<PDetToPlaceIns*>& _insvector;
142 public:
CompareInsPosition(vector<PDetToPlaceIns * > & insvector)143 CompareInsPosition(vector<PDetToPlaceIns*>& insvector):
144 _insvector(insvector) {}
145
operator ()(const PDetToPlaceIns * ins1,const PDetToPlaceIns * ins2) const146 bool operator()(const PDetToPlaceIns* ins1, const PDetToPlaceIns* ins2) const
147 { return ins1->GetLeftCornerX() < ins2->GetLeftCornerX(); }
148 };
149
150 bool
FinalOptimize()151 PDetSubRow::FinalOptimize()
152 {
153 unsigned ninsinproblem = 0;
154 unsigned nins = _detInsVector.size();
155 if (_detInsVector.size() == 0)
156 return false;
157 unsigned decal = 2;
158 bool optimisation = false;
159
160 vector<PDetToPlaceIns*> insvector;
161 insvector.reserve(nins);
162 for (PDetInsVector::iterator iit = _detInsVector.begin();
163 iit != _detInsVector.end(); iit++)
164 {
165 insvector.push_back(*iit);
166 }
167 sort(insvector.begin(), insvector.end(), CompareInsPosition(insvector));
168 PDetPlacement::Problem problem;
169 problem.reserve(6);
170 vector<PDetToPlaceIns*>::iterator ifirst = insvector.begin();
171 vector<PDetToPlaceIns*>::iterator ilast = insvector.end();
172 while (1)
173 {
174 while (1)
175 {
176 if (ifirst == ilast)
177 break;
178 problem.push_back(*ifirst++);
179 ++ninsinproblem;
180 if (ninsinproblem >= 6)
181 {
182 ninsinproblem = 0;
183 break;
184 }
185 }
186 PDetPlacement detplace(problem);
187 if (detplace.Optimize())
188 optimisation = true;
189
190 if (ifirst == ilast)
191 break;
192
193 sort(insvector.begin(), insvector.end(), CompareInsPosition(insvector));
194 if ((6 + decal) <= nins)
195 {
196 ifirst = insvector.begin() + decal;
197 }
198 else
199 {
200 ifirst = insvector.begin() + decal - 1;
201 }
202 ilast = insvector.end();
203
204 decal += 2;
205 problem.clear();
206 }
207 return optimisation;
208 }
209
210 ofstream&
Plot(ofstream & out) const211 PDetSubRow::Plot(ofstream& out) const
212 {
213 out << GetMinX() + 0.2 << " " << GetMinY() + 0.2 << endl
214 << GetMinX() + 0.2 << " " << GetMaxY() - 0.2 << endl
215 << GetMaxX() - 0.2 << " " << GetMaxY() - 0.2 << endl
216 << GetMaxX() - 0.2 << " " << GetMinY() + 0.2 << endl
217 << GetMinX() + 0.2 << " " << GetMinY() + 0.2 << endl << endl;
218
219 return out;
220 }
221
222 ostream&
Print(ostream & os) const223 PDetSubRow::Print(ostream& os) const
224 {
225 return os << "PDetSubRow: " << GetMinX() << ',' << GetMinY() << " : " << GetMaxX() << ',' << GetMaxY();
226 }
227