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 96 line context
... ...
@@ -654,96 +654,97 @@
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;
... ...
@@ -774,61 +775,61 @@
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)