0
3
0
... | ... |
@@ -173,25 +173,25 @@ |
173 | 173 |
arcColors(composeMap(palette,acolors)). |
174 | 174 |
arcWidthScale(.3).arcWidths(widths). |
175 | 175 |
nodeTexts(id).nodeTextSize(3). |
176 | 176 |
enableParallel().parArcDist(1). |
177 | 177 |
drawArrows().arrowWidth(1).arrowLength(1). |
178 | 178 |
run(); |
179 | 179 |
|
180 | 180 |
// Create an .eps file showing the colors of a default Palette |
181 | 181 |
ListDigraph h; |
182 | 182 |
ListDigraph::NodeMap<int> hcolors(h); |
183 | 183 |
ListDigraph::NodeMap<Point> hcoords(h); |
184 | 184 |
|
185 |
int cols=int(sqrt(double(palette.size()))); |
|
185 |
int cols=int(std::sqrt(double(palette.size()))); |
|
186 | 186 |
for(int i=0;i<int(paletteW.size());i++) { |
187 | 187 |
Node n=h.addNode(); |
188 | 188 |
hcoords[n]=Point(1+i%cols,1+i/cols); |
189 | 189 |
hcolors[n]=i; |
190 | 190 |
} |
191 | 191 |
|
192 | 192 |
cout << "Create 'graph_to_eps_demo_out_7_colors.eps'" << endl; |
193 | 193 |
graphToEps(h,"graph_to_eps_demo_out_7_colors.eps"). |
194 | 194 |
scale(60). |
195 | 195 |
title("Sample .eps figure (Palette demo)"). |
196 | 196 |
copyright("(C) 2003-2009 LEMON Project"). |
197 | 197 |
coords(hcoords). |
... | ... |
@@ -372,25 +372,26 @@ |
372 | 372 |
public: |
373 | 373 |
|
374 | 374 |
// Constructor |
375 | 375 |
BlockSearchPivotRule(NetworkSimplex &ns) : |
376 | 376 |
_source(ns._source), _target(ns._target), |
377 | 377 |
_cost(ns._cost), _state(ns._state), _pi(ns._pi), |
378 | 378 |
_in_arc(ns.in_arc), _arc_num(ns._arc_num), _next_arc(0) |
379 | 379 |
{ |
380 | 380 |
// The main parameters of the pivot rule |
381 | 381 |
const double BLOCK_SIZE_FACTOR = 2.0; |
382 | 382 |
const int MIN_BLOCK_SIZE = 10; |
383 | 383 |
|
384 |
_block_size = std::max( int(BLOCK_SIZE_FACTOR * |
|
384 |
_block_size = std::max( int(BLOCK_SIZE_FACTOR * |
|
385 |
std::sqrt(double(_arc_num))), |
|
385 | 386 |
MIN_BLOCK_SIZE ); |
386 | 387 |
} |
387 | 388 |
|
388 | 389 |
// Find next entering arc |
389 | 390 |
bool findEnteringArc() { |
390 | 391 |
Cost c, min = 0; |
391 | 392 |
int cnt = _block_size; |
392 | 393 |
int e, min_arc = _next_arc; |
393 | 394 |
for (e = _next_arc; e < _arc_num; ++e) { |
394 | 395 |
c = _state[e] * (_cost[e] + _pi[_source[e]] - _pi[_target[e]]); |
395 | 396 |
if (c < min) { |
396 | 397 |
min = c; |
... | ... |
@@ -448,25 +449,26 @@ |
448 | 449 |
/// Constructor |
449 | 450 |
CandidateListPivotRule(NetworkSimplex &ns) : |
450 | 451 |
_source(ns._source), _target(ns._target), |
451 | 452 |
_cost(ns._cost), _state(ns._state), _pi(ns._pi), |
452 | 453 |
_in_arc(ns.in_arc), _arc_num(ns._arc_num), _next_arc(0) |
453 | 454 |
{ |
454 | 455 |
// The main parameters of the pivot rule |
455 | 456 |
const double LIST_LENGTH_FACTOR = 1.0; |
456 | 457 |
const int MIN_LIST_LENGTH = 10; |
457 | 458 |
const double MINOR_LIMIT_FACTOR = 0.1; |
458 | 459 |
const int MIN_MINOR_LIMIT = 3; |
459 | 460 |
|
460 |
_list_length = std::max( int(LIST_LENGTH_FACTOR * |
|
461 |
_list_length = std::max( int(LIST_LENGTH_FACTOR * |
|
462 |
std::sqrt(double(_arc_num))), |
|
461 | 463 |
MIN_LIST_LENGTH ); |
462 | 464 |
_minor_limit = std::max( int(MINOR_LIMIT_FACTOR * _list_length), |
463 | 465 |
MIN_MINOR_LIMIT ); |
464 | 466 |
_curr_length = _minor_count = 0; |
465 | 467 |
_candidates.resize(_list_length); |
466 | 468 |
} |
467 | 469 |
|
468 | 470 |
/// Find next entering arc |
469 | 471 |
bool findEnteringArc() { |
470 | 472 |
Cost min, c; |
471 | 473 |
int e, min_arc = _next_arc; |
472 | 474 |
if (_curr_length > 0 && _minor_count < _minor_limit) { |
... | ... |
@@ -568,25 +570,26 @@ |
568 | 570 |
AlteringListPivotRule(NetworkSimplex &ns) : |
569 | 571 |
_source(ns._source), _target(ns._target), |
570 | 572 |
_cost(ns._cost), _state(ns._state), _pi(ns._pi), |
571 | 573 |
_in_arc(ns.in_arc), _arc_num(ns._arc_num), |
572 | 574 |
_next_arc(0), _cand_cost(ns._arc_num), _sort_func(_cand_cost) |
573 | 575 |
{ |
574 | 576 |
// The main parameters of the pivot rule |
575 | 577 |
const double BLOCK_SIZE_FACTOR = 1.5; |
576 | 578 |
const int MIN_BLOCK_SIZE = 10; |
577 | 579 |
const double HEAD_LENGTH_FACTOR = 0.1; |
578 | 580 |
const int MIN_HEAD_LENGTH = 3; |
579 | 581 |
|
580 |
_block_size = std::max( int(BLOCK_SIZE_FACTOR * |
|
582 |
_block_size = std::max( int(BLOCK_SIZE_FACTOR * |
|
583 |
std::sqrt(double(_arc_num))), |
|
581 | 584 |
MIN_BLOCK_SIZE ); |
582 | 585 |
_head_length = std::max( int(HEAD_LENGTH_FACTOR * _block_size), |
583 | 586 |
MIN_HEAD_LENGTH ); |
584 | 587 |
_candidates.resize(_head_length + _block_size); |
585 | 588 |
_curr_length = 0; |
586 | 589 |
} |
587 | 590 |
|
588 | 591 |
// Find next entering arc |
589 | 592 |
bool findEnteringArc() { |
590 | 593 |
// Check the current candidate list |
591 | 594 |
int e; |
592 | 595 |
for (int i = 0; i < _curr_length; ++i) { |
... | ... |
@@ -1216,25 +1219,25 @@ |
1216 | 1219 |
_thread[_root] = 0; |
1217 | 1220 |
_rev_thread[0] = _root; |
1218 | 1221 |
_succ_num[_root] = all_node_num; |
1219 | 1222 |
_last_succ[_root] = _root - 1; |
1220 | 1223 |
_supply[_root] = -sum_supply; |
1221 | 1224 |
if (sum_supply < 0) { |
1222 | 1225 |
_pi[_root] = -art_cost; |
1223 | 1226 |
} else { |
1224 | 1227 |
_pi[_root] = art_cost; |
1225 | 1228 |
} |
1226 | 1229 |
|
1227 | 1230 |
// Store the arcs in a mixed order |
1228 |
int k = std::max(int(sqrt(_arc_num)), 10); |
|
1231 |
int k = std::max(int(std::sqrt(double(_arc_num))), 10); |
|
1229 | 1232 |
int i = 0; |
1230 | 1233 |
for (ArcIt e(_graph); e != INVALID; ++e) { |
1231 | 1234 |
_arc_ref[i] = e; |
1232 | 1235 |
if ((i += k) >= _arc_num) i = (i % k) + 1; |
1233 | 1236 |
} |
1234 | 1237 |
|
1235 | 1238 |
// Initialize arc maps |
1236 | 1239 |
if (_pupper && _pcost) { |
1237 | 1240 |
for (int i = 0; i != _arc_num; ++i) { |
1238 | 1241 |
Arc e = _arc_ref[i]; |
1239 | 1242 |
_source[i] = _node_id[_graph.source(e)]; |
1240 | 1243 |
_target[i] = _node_id[_graph.target(e)]; |
... | ... |
@@ -56,25 +56,25 @@ |
56 | 56 |
int N; |
57 | 57 |
// int girth; |
58 | 58 |
|
59 | 59 |
ListGraph g; |
60 | 60 |
|
61 | 61 |
std::vector<Node> nodes; |
62 | 62 |
ListGraph::NodeMap<Point> coords(g); |
63 | 63 |
|
64 | 64 |
|
65 | 65 |
double totalLen(){ |
66 | 66 |
double tlen=0; |
67 | 67 |
for(EdgeIt e(g);e!=INVALID;++e) |
68 |
tlen+=sqrt((coords[g.v(e)]-coords[g.u(e)]).normSquare()); |
|
68 |
tlen+=std::sqrt((coords[g.v(e)]-coords[g.u(e)]).normSquare()); |
|
69 | 69 |
return tlen; |
70 | 70 |
} |
71 | 71 |
|
72 | 72 |
int tsp_impr_num=0; |
73 | 73 |
|
74 | 74 |
const double EPSILON=1e-8; |
75 | 75 |
bool tsp_improve(Node u, Node v) |
76 | 76 |
{ |
77 | 77 |
double luv=std::sqrt((coords[v]-coords[u]).normSquare()); |
78 | 78 |
Node u2=u; |
79 | 79 |
Node v2=v; |
80 | 80 |
do { |
... | ... |
@@ -179,43 +179,43 @@ |
179 | 179 |
double d = (p.x * p.x + p.y * p.y) * (q.y - r.y) + |
180 | 180 |
(q.x * q.x + q.y * q.y) * (r.y - p.y) + |
181 | 181 |
(r.x * r.x + r.y * r.y) * (p.y - q.y); |
182 | 182 |
|
183 | 183 |
double e = (p.x * p.x + p.y * p.y) * (q.x - r.x) + |
184 | 184 |
(q.x * q.x + q.y * q.y) * (r.x - p.x) + |
185 | 185 |
(r.x * r.x + r.y * r.y) * (p.x - q.x); |
186 | 186 |
|
187 | 187 |
double f = (p.x * p.x + p.y * p.y) * (q.x * r.y - r.x * q.y) + |
188 | 188 |
(q.x * q.x + q.y * q.y) * (r.x * p.y - p.x * r.y) + |
189 | 189 |
(r.x * r.x + r.y * r.y) * (p.x * q.y - q.x * p.y); |
190 | 190 |
|
191 |
return d / (2 * a) + sqrt((d * d + e * e) / (4 * a * a) + f / a); |
|
191 |
return d / (2 * a) + std::sqrt((d * d + e * e) / (4 * a * a) + f / a); |
|
192 | 192 |
} |
193 | 193 |
|
194 | 194 |
inline bool circle_form(const Point& p, const Point& q, const Point& r) { |
195 | 195 |
return rot90(q - p) * (r - q) < 0.0; |
196 | 196 |
} |
197 | 197 |
|
198 | 198 |
inline double intersection(const Point& p, const Point& q, double sx) { |
199 | 199 |
const double epsilon = 1e-8; |
200 | 200 |
|
201 | 201 |
if (p.x == q.x) return (p.y + q.y) / 2.0; |
202 | 202 |
|
203 | 203 |
if (sx < p.x + epsilon) return p.y; |
204 | 204 |
if (sx < q.x + epsilon) return q.y; |
205 | 205 |
|
206 | 206 |
double a = q.x - p.x; |
207 | 207 |
double b = (q.x - sx) * p.y - (p.x - sx) * q.y; |
208 | 208 |
double d = (q.x - sx) * (p.x - sx) * (p - q).normSquare(); |
209 |
return (b - sqrt(d)) / a; |
|
209 |
return (b - std::sqrt(d)) / a; |
|
210 | 210 |
} |
211 | 211 |
|
212 | 212 |
struct YLess { |
213 | 213 |
|
214 | 214 |
|
215 | 215 |
YLess(const std::vector<Point>& points, double& sweep) |
216 | 216 |
: _points(points), _sweep(sweep) {} |
217 | 217 |
|
218 | 218 |
bool operator()(const Part& l, const Part& r) const { |
219 | 219 |
const double epsilon = 1e-8; |
220 | 220 |
|
221 | 221 |
// std::cerr << l << " vs " << r << std::endl; |
... | ... |
@@ -804,25 +804,25 @@ |
804 | 804 |
else if(ap["tree"]) { |
805 | 805 |
minTree(); |
806 | 806 |
} |
807 | 807 |
else if(ap["dela"]) { |
808 | 808 |
delaunay(); |
809 | 809 |
} |
810 | 810 |
|
811 | 811 |
|
812 | 812 |
std::cout << "Number of nodes : " << countNodes(g) << std::endl; |
813 | 813 |
std::cout << "Number of arcs : " << countEdges(g) << std::endl; |
814 | 814 |
double tlen=0; |
815 | 815 |
for(EdgeIt e(g);e!=INVALID;++e) |
816 |
tlen+=sqrt((coords[g.v(e)]-coords[g.u(e)]).normSquare()); |
|
816 |
tlen+=std::sqrt((coords[g.v(e)]-coords[g.u(e)]).normSquare()); |
|
817 | 817 |
std::cout << "Total arc length : " << tlen << std::endl; |
818 | 818 |
|
819 | 819 |
if(ap["eps"]) |
820 | 820 |
graphToEps(g,prefix+".eps").scaleToA4(). |
821 | 821 |
scale(600).nodeScale(.005).arcWidthScale(.001).preScale(false). |
822 | 822 |
coords(coords).hideNodes(ap.given("nonodes")).run(); |
823 | 823 |
|
824 | 824 |
if(ap["dir"]) |
825 | 825 |
DigraphWriter<ListGraph>(g,prefix+".lgf"). |
826 | 826 |
nodeMap("coordinates_x",scaleMap(xMap(coords),600)). |
827 | 827 |
nodeMap("coordinates_y",scaleMap(yMap(coords),600)). |
828 | 828 |
run(); |
0 comments (0 inline)