321 radius_p=radius_size; |
321 radius_p=radius_size; |
322 } |
322 } |
323 |
323 |
324 void GraphDisplayerCanvas::reDesignGraph() |
324 void GraphDisplayerCanvas::reDesignGraph() |
325 { |
325 { |
326 double max_coord=50000; |
326 NodeIt firstnode((mytab.mapstorage).graph); |
327 double min_dist=20; |
327 //is it not an empty graph? |
328 double init_vector_length=25; |
328 if(firstnode!=INVALID) |
329 |
329 { |
330 if(!was_redesigned) |
330 double max_coord=50000; |
331 { |
331 double min_dist=20; |
332 NodeIt i((mytab.mapstorage).graph); |
332 double init_vector_length=25; |
333 |
333 |
334 dim2::Point<double> init(init_vector_length*rnd(), |
334 if(!was_redesigned) |
335 init_vector_length*rnd()); |
335 { |
336 moveNode(init.x, init.y, nodesmap[i], i); |
336 NodeIt i((mytab.mapstorage).graph); |
337 was_redesigned=true; |
337 |
338 } |
338 dim2::Point<double> init(init_vector_length*rnd(), |
339 |
339 init_vector_length*rnd()); |
340 double attraction; |
340 moveNode(init.x, init.y, nodesmap[i], i); |
341 double propulsation; |
341 was_redesigned=true; |
342 int iterations; |
342 } |
343 |
343 |
344 (mytab.mapstorage).get_design_data(attraction, propulsation, iterations); |
344 double attraction; |
345 |
345 double propulsation; |
346 //iteration counter |
346 int iterations; |
347 for(int l=0;l<iterations;l++) |
347 |
348 { |
348 (mytab.mapstorage).get_design_data(attraction, propulsation, iterations); |
349 Graph::NodeMap<double> x(mytab.mapstorage.graph); |
349 |
350 Graph::NodeMap<double> y(mytab.mapstorage.graph); |
350 //iteration counter |
351 XYMap<Graph::NodeMap<double> > actual_forces; |
351 for(int l=0;l<iterations;l++) |
352 actual_forces.setXMap(x); |
352 { |
353 actual_forces.setYMap(y); |
353 Graph::NodeMap<double> x(mytab.mapstorage.graph); |
354 |
354 Graph::NodeMap<double> y(mytab.mapstorage.graph); |
355 //count actual force for each nodes |
355 XYMap<Graph::NodeMap<double> > actual_forces; |
356 for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i) |
356 actual_forces.setXMap(x); |
357 { |
357 actual_forces.setYMap(y); |
358 //propulsation of nodes |
358 |
359 for (NodeIt j((mytab.mapstorage).graph); j!=INVALID; ++j) |
359 //count actual force for each nodes |
360 { |
360 for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i) |
361 if(i!=j) |
361 { |
|
362 //propulsation of nodes |
|
363 for (NodeIt j((mytab.mapstorage).graph); j!=INVALID; ++j) |
|
364 { |
|
365 if(i!=j) |
|
366 { |
|
367 lemon::dim2::Point<double> delta = |
|
368 ((mytab.mapstorage).coords[i]- |
|
369 (mytab.mapstorage).coords[j]); |
|
370 |
|
371 const double length_sqr=std::max(delta.normSquare(),min_dist); |
|
372 |
|
373 //normalize vector |
|
374 delta/=sqrt(length_sqr); |
|
375 |
|
376 //calculating propulsation strength |
|
377 //greater distance menas smaller propulsation strength |
|
378 delta*=propulsation/length_sqr; |
|
379 |
|
380 actual_forces.set(i,(actual_forces[i]+delta)); |
|
381 } |
|
382 } |
|
383 //attraction of nodes, to which actual node is bound |
|
384 for(OutEdgeIt ei((mytab.mapstorage).graph,i);ei!=INVALID;++ei) |
362 { |
385 { |
363 lemon::dim2::Point<double> delta = |
386 lemon::dim2::Point<double> delta = |
364 ((mytab.mapstorage).coords[i]- |
387 ((mytab.mapstorage).coords[i]- |
365 (mytab.mapstorage).coords[j]); |
388 (mytab.mapstorage).coords[mytab.mapstorage. |
366 |
389 graph.target(ei)]); |
367 const double length_sqr=std::max(delta.normSquare(),min_dist); |
|
368 |
|
369 //normalize vector |
|
370 delta/=sqrt(length_sqr); |
|
371 |
|
372 //calculating propulsation strength |
|
373 //greater distance menas smaller propulsation strength |
|
374 delta*=propulsation/length_sqr; |
|
375 |
|
376 actual_forces.set(i,(actual_forces[i]+delta)); |
|
377 } |
|
378 } |
|
379 //attraction of nodes, to which actual node is bound |
|
380 for(OutEdgeIt ei((mytab.mapstorage).graph,i);ei!=INVALID;++ei) |
|
381 { |
|
382 lemon::dim2::Point<double> delta = |
|
383 ((mytab.mapstorage).coords[i]- |
|
384 (mytab.mapstorage).coords[mytab.mapstorage. |
|
385 graph.target(ei)]); |
|
386 |
390 |
387 //calculating attraction strength |
391 //calculating attraction strength |
388 //greater distance means greater strength |
392 //greater distance means greater strength |
389 delta*=attraction; |
393 delta*=attraction; |
390 |
394 |
391 actual_forces.set(i,actual_forces[i]-delta); |
395 actual_forces.set(i,actual_forces[i]-delta); |
392 } |
396 } |
393 for(InEdgeIt ei((mytab.mapstorage).graph,i);ei!=INVALID;++ei) |
397 for(InEdgeIt ei((mytab.mapstorage).graph,i);ei!=INVALID;++ei) |
394 { |
398 { |
395 lemon::dim2::Point<double> delta = |
399 lemon::dim2::Point<double> delta = |
396 ((mytab.mapstorage).coords[i]- |
400 ((mytab.mapstorage).coords[i]- |
397 (mytab.mapstorage).coords[mytab.mapstorage. |
401 (mytab.mapstorage).coords[mytab.mapstorage. |
398 graph.source(ei)]); |
402 graph.source(ei)]); |
399 |
403 |
400 //calculating attraction strength |
404 //calculating attraction strength |
401 //greater distance means greater strength |
405 //greater distance means greater strength |
402 delta*=attraction; |
406 delta*=attraction; |
403 |
407 |
404 actual_forces.set(i,actual_forces[i]-delta); |
408 actual_forces.set(i,actual_forces[i]-delta); |
405 } |
409 } |
406 } |
410 } |
407 for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i) |
411 for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i) |
408 { |
412 { |
409 if(((mytab.mapstorage).coords[i].x)+actual_forces[i].x>max_coord) |
413 if(((mytab.mapstorage).coords[i].x)+actual_forces[i].x>max_coord) |
410 { |
414 { |
411 actual_forces[i].x=max_coord-((mytab.mapstorage).coords[i].x); |
415 actual_forces[i].x=max_coord-((mytab.mapstorage).coords[i].x); |
412 std::cout << "Correction! " << (((mytab.mapstorage).coords[i].x)+actual_forces[i].x) << std::endl; |
416 std::cout << "Correction! " << (((mytab.mapstorage).coords[i].x)+actual_forces[i].x) << std::endl; |
413 } |
417 } |
414 else if(((mytab.mapstorage).coords[i].x)+actual_forces[i].x<(0-max_coord)) |
418 else if(((mytab.mapstorage).coords[i].x)+actual_forces[i].x<(0-max_coord)) |
415 { |
419 { |
416 actual_forces[i].x=0-max_coord-((mytab.mapstorage).coords[i].x); |
420 actual_forces[i].x=0-max_coord-((mytab.mapstorage).coords[i].x); |
417 std::cout << "Correction! " << (((mytab.mapstorage).coords[i].x)+actual_forces[i].x) << std::endl; |
421 std::cout << "Correction! " << (((mytab.mapstorage).coords[i].x)+actual_forces[i].x) << std::endl; |
418 } |
422 } |
419 if(((mytab.mapstorage).coords[i].y)+actual_forces[i].y>max_coord) |
423 if(((mytab.mapstorage).coords[i].y)+actual_forces[i].y>max_coord) |
420 { |
424 { |
421 actual_forces[i].y=max_coord-((mytab.mapstorage).coords[i].y); |
425 actual_forces[i].y=max_coord-((mytab.mapstorage).coords[i].y); |
422 std::cout << "Correction! " << (((mytab.mapstorage).coords[i].y)+actual_forces[i].y) << std::endl; |
426 std::cout << "Correction! " << (((mytab.mapstorage).coords[i].y)+actual_forces[i].y) << std::endl; |
423 } |
427 } |
424 else if(((mytab.mapstorage).coords[i].y)+actual_forces[i].y<(0-max_coord)) |
428 else if(((mytab.mapstorage).coords[i].y)+actual_forces[i].y<(0-max_coord)) |
425 { |
429 { |
426 actual_forces[i].y=0-max_coord-((mytab.mapstorage).coords[i].y); |
430 actual_forces[i].y=0-max_coord-((mytab.mapstorage).coords[i].y); |
427 std::cout << "Correction! " << (((mytab.mapstorage).coords[i].y)+actual_forces[i].y) << std::endl; |
431 std::cout << "Correction! " << (((mytab.mapstorage).coords[i].y)+actual_forces[i].y) << std::endl; |
428 } |
432 } |
429 moveNode(actual_forces[i].x, actual_forces[i].y, nodesmap[i], i); |
433 moveNode(actual_forces[i].x, actual_forces[i].y, nodesmap[i], i); |
430 } |
434 } |
431 } |
435 } |
432 } |
436 } |
433 |
437 } |
|
438 |