gravatar
alpar (Alpar Juttner)
alpar@cs.elte.hu
Option for lgf-gen to draw the edges only
0 1 0
default
1 file changed with 2 insertions and 1 deletions:
↑ Collapse diff ↑
Ignore white space 192 line context
... ...
@@ -606,229 +606,230 @@
606 606
    if(countIncEdges(g,n)%2 || countIncEdges(g,n)==0 )
607 607
      std::cout << "GEBASZ!!!" << std::endl;
608 608

	
609 609
  for(EdgeIt e(g);e!=INVALID;++e)
610 610
    if(g.u(e)==g.v(e))
611 611
      std::cout << "LOOP GEBASZ!!!" << std::endl;
612 612

	
613 613
  std::cout << "Number of arcs : " << countEdges(g) << std::endl;
614 614

	
615 615
  std::cout << "Total arc length (euler) : " << totalLen() << std::endl;
616 616

	
617 617
  ListGraph::EdgeMap<Arc> enext(g);
618 618
  {
619 619
    EulerIt<ListGraph> e(g);
620 620
    Arc eo=e;
621 621
    Arc ef=e;
622 622
//     std::cout << "Tour arc: " << g.id(Edge(e)) << std::endl;
623 623
    for(++e;e!=INVALID;++e)
624 624
      {
625 625
//         std::cout << "Tour arc: " << g.id(Edge(e)) << std::endl;
626 626
        enext[eo]=e;
627 627
        eo=e;
628 628
      }
629 629
    enext[eo]=ef;
630 630
  }
631 631

	
632 632
  std::cout << "Creating a tour from that..." << std::endl;
633 633

	
634 634
  int nnum = countNodes(g);
635 635
  int ednum = countEdges(g);
636 636

	
637 637
  for(Arc p=enext[EdgeIt(g)];ednum>nnum;p=enext[p])
638 638
    {
639 639
//       std::cout << "Checking arc " << g.id(p) << std::endl;
640 640
      Arc e=enext[p];
641 641
      Arc f=enext[e];
642 642
      Node n2=g.source(f);
643 643
      Node n1=g.oppositeNode(n2,e);
644 644
      Node n3=g.oppositeNode(n2,f);
645 645
      if(countIncEdges(g,n2)>2)
646 646
        {
647 647
//           std::cout << "Remove an Arc" << std::endl;
648 648
          Arc ff=enext[f];
649 649
          g.erase(e);
650 650
          g.erase(f);
651 651
          if(n1!=n3)
652 652
            {
653 653
              Arc ne=g.direct(g.addEdge(n1,n3),n1);
654 654
              enext[p]=ne;
655 655
              enext[ne]=ff;
656 656
              ednum--;
657 657
            }
658 658
          else {
659 659
            enext[p]=ff;
660 660
            ednum-=2;
661 661
          }
662 662
        }
663 663
    }
664 664

	
665 665
  std::cout << "Total arc length (tour) : " << totalLen() << std::endl;
666 666

	
667 667
  std::cout << "2-opt the tour..." << std::endl;
668 668

	
669 669
  tsp_improve();
670 670

	
671 671
  std::cout << "Total arc length (2-opt tour) : " << totalLen() << std::endl;
672 672
}
673 673

	
674 674

	
675 675
int main(int argc,const char **argv)
676 676
{
677 677
  ArgParser ap(argc,argv);
678 678

	
679 679
//   bool eps;
680 680
  bool disc_d, square_d, gauss_d;
681 681
//   bool tsp_a,two_a,tree_a;
682 682
  int num_of_cities=1;
683 683
  double area=1;
684 684
  N=100;
685 685
//   girth=10;
686 686
  std::string ndist("disc");
687 687
  ap.refOption("n", "Number of nodes (default is 100)", N)
688 688
    .intOption("g", "Girth parameter (default is 10)", 10)
689 689
    .refOption("cities", "Number of cities (default is 1)", num_of_cities)
690 690
    .refOption("area", "Full relative area of the cities (default is 1)", area)
691 691
    .refOption("disc", "Nodes are evenly distributed on a unit disc (default)",disc_d)
692 692
    .optionGroup("dist", "disc")
693 693
    .refOption("square", "Nodes are evenly distributed on a unit square", square_d)
694 694
    .optionGroup("dist", "square")
695 695
    .refOption("gauss",
696 696
            "Nodes are located according to a two-dim gauss distribution",
697 697
            gauss_d)
698 698
    .optionGroup("dist", "gauss")
699 699
//     .mandatoryGroup("dist")
700 700
    .onlyOneGroup("dist")
701 701
    .boolOption("eps", "Also generate .eps output (prefix.eps)")
702
    .boolOption("nonodes", "Draw the edges only in the generated .eps")
702 703
    .boolOption("dir", "Directed digraph is generated (each arcs are replaced by two directed ones)")
703 704
    .boolOption("2con", "Create a two connected planar digraph")
704 705
    .optionGroup("alg","2con")
705 706
    .boolOption("tree", "Create a min. cost spanning tree")
706 707
    .optionGroup("alg","tree")
707 708
    .boolOption("tsp", "Create a TSP tour")
708 709
    .optionGroup("alg","tsp")
709 710
    .boolOption("tsp2", "Create a TSP tour (tree based)")
710 711
    .optionGroup("alg","tsp2")
711 712
    .boolOption("dela", "Delaunay triangulation digraph")
712 713
    .optionGroup("alg","dela")
713 714
    .onlyOneGroup("alg")
714 715
    .boolOption("rand", "Use time seed for random number generator")
715 716
    .optionGroup("rand", "rand")
716 717
    .intOption("seed", "Random seed", -1)
717 718
    .optionGroup("rand", "seed")
718 719
    .onlyOneGroup("rand")
719 720
    .other("[prefix]","Prefix of the output files. Default is 'lgf-gen-out'")
720 721
    .run();
721 722

	
722 723
  if (ap["rand"]) {
723 724
    int seed = time(0);
724 725
    std::cout << "Random number seed: " << seed << std::endl;
725 726
    rnd = Random(seed);
726 727
  }
727 728
  if (ap.given("seed")) {
728 729
    int seed = ap["seed"];
729 730
    std::cout << "Random number seed: " << seed << std::endl;
730 731
    rnd = Random(seed);
731 732
  }
732 733

	
733 734
  std::string prefix;
734 735
  switch(ap.files().size())
735 736
    {
736 737
    case 0:
737 738
      prefix="lgf-gen-out";
738 739
      break;
739 740
    case 1:
740 741
      prefix=ap.files()[0];
741 742
      break;
742 743
    default:
743 744
      std::cerr << "\nAt most one prefix can be given\n\n";
744 745
      exit(1);
745 746
    }
746 747

	
747 748
  double sum_sizes=0;
748 749
  std::vector<double> sizes;
749 750
  std::vector<double> cum_sizes;
750 751
  for(int s=0;s<num_of_cities;s++)
751 752
    {
752 753
      //         sum_sizes+=rnd.exponential();
753 754
      double d=rnd();
754 755
      sum_sizes+=d;
755 756
      sizes.push_back(d);
756 757
      cum_sizes.push_back(sum_sizes);
757 758
    }
758 759
  int i=0;
759 760
  for(int s=0;s<num_of_cities;s++)
760 761
    {
761 762
      Point center=(num_of_cities==1?Point(0,0):rnd.disc());
762 763
      if(gauss_d)
763 764
        for(;i<N*(cum_sizes[s]/sum_sizes);i++) {
764 765
          Node n=g.addNode();
765 766
          nodes.push_back(n);
766 767
          coords[n]=center+rnd.gauss2()*area*
767 768
            std::sqrt(sizes[s]/sum_sizes);
768 769
        }
769 770
      else if(square_d)
770 771
        for(;i<N*(cum_sizes[s]/sum_sizes);i++) {
771 772
          Node n=g.addNode();
772 773
          nodes.push_back(n);
773 774
          coords[n]=center+Point(rnd()*2-1,rnd()*2-1)*area*
774 775
            std::sqrt(sizes[s]/sum_sizes);
775 776
        }
776 777
      else if(disc_d || true)
777 778
        for(;i<N*(cum_sizes[s]/sum_sizes);i++) {
778 779
          Node n=g.addNode();
779 780
          nodes.push_back(n);
780 781
          coords[n]=center+rnd.disc()*area*
781 782
            std::sqrt(sizes[s]/sum_sizes);
782 783
        }
783 784
    }
784 785

	
785 786
//   for (ListGraph::NodeIt n(g); n != INVALID; ++n) {
786 787
//     std::cerr << coords[n] << std::endl;
787 788
//   }
788 789

	
789 790
  if(ap["tsp"]) {
790 791
    tsp();
791 792
    std::cout << "#2-opt improvements: " << tsp_impr_num << std::endl;
792 793
  }
793 794
  if(ap["tsp2"]) {
794 795
    tsp2();
795 796
    std::cout << "#2-opt improvements: " << tsp_impr_num << std::endl;
796 797
  }
797 798
  else if(ap["2con"]) {
798 799
    std::cout << "Make triangles\n";
799 800
    //   triangle();
800 801
    sparseTriangle(ap["g"]);
801 802
    std::cout << "Make it sparser\n";
802 803
    sparse2(ap["g"]);
803 804
  }
804 805
  else if(ap["tree"]) {
805 806
    minTree();
806 807
  }
807 808
  else if(ap["dela"]) {
808 809
    delaunay();
809 810
  }
810 811

	
811 812

	
812 813
  std::cout << "Number of nodes    : " << countNodes(g) << std::endl;
813 814
  std::cout << "Number of arcs    : " << countEdges(g) << std::endl;
814 815
  double tlen=0;
815 816
  for(EdgeIt e(g);e!=INVALID;++e)
816 817
    tlen+=sqrt((coords[g.v(e)]-coords[g.u(e)]).normSquare());
817 818
  std::cout << "Total arc length  : " << tlen << std::endl;
818 819

	
819 820
  if(ap["eps"])
820 821
    graphToEps(g,prefix+".eps").scaleToA4().
821 822
      scale(600).nodeScale(.005).arcWidthScale(.001).preScale(false).
822
      coords(coords).run();
823
      coords(coords).hideNodes(ap.given("nonodes")).run();
823 824

	
824 825
  if(ap["dir"])
825 826
    DigraphWriter<ListGraph>(g,prefix+".lgf").
826 827
      nodeMap("coordinates_x",scaleMap(xMap(coords),600)).
827 828
      nodeMap("coordinates_y",scaleMap(yMap(coords),600)).
828 829
      run();
829 830
  else GraphWriter<ListGraph>(g,prefix+".lgf").
830 831
         nodeMap("coordinates_x",scaleMap(xMap(coords),600)).
831 832
         nodeMap("coordinates_y",scaleMap(yMap(coords),600)).
832 833
         run();
833 834
}
834 835

	
0 comments (0 inline)