COIN-OR::LEMON - Graph Library

Ticket #57: grid_0438942f8930.patch

File grid_0438942f8930.patch, 48.0 KB (added by Peter Kovacs, 16 years ago)

New (merged) improvement changeset

  • doc/CMakeLists.txt

    # HG changeset patch
    # User Balazs Dezso <deba@inf.elte.hu>
    # Date 1224501056 -7200
    # Node ID 0438942f893073ff353d7cbbdc246029ad9f6931
    # Parent  ada5f74d1c9e874b24256426f1c5c0e141fcbc2d
    Improvements on grid graph
    
     - The indexing of the nodes is changed according to integer points
       of the plane.
     - The graph type does not depend on the UndirDigraphExtender.
     - Improve documentation.
     - Improve image generation.
    
    diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt
    a b  
    1313    ADD_CUSTOM_TARGET(html
    1414      COMMAND rm -rf gen-images
    1515      COMMAND mkdir gen-images
    16       COMMAND ${GHOSTSCRIPT_EXECUTABLE} -dNOPAUSE -dBATCH -q -dEPSCrop -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sDEVICE=pngalpha -r18 -sOutputFile=gen-images/nodeshape_0.png ${CMAKE_CURRENT_SOURCE_DIR}/images/nodeshape_0.eps
    17       COMMAND ${GHOSTSCRIPT_EXECUTABLE} -dNOPAUSE -dBATCH -q -dEPSCrop -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sDEVICE=pngalpha -r18 -sOutputFile=gen-images/nodeshape_1.png ${CMAKE_CURRENT_SOURCE_DIR}/images/nodeshape_1.eps
    18       COMMAND ${GHOSTSCRIPT_EXECUTABLE} -dNOPAUSE -dBATCH -q -dEPSCrop -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sDEVICE=pngalpha -r18 -sOutputFile=gen-images/nodeshape_2.png ${CMAKE_CURRENT_SOURCE_DIR}/images/nodeshape_2.eps
    19       COMMAND ${GHOSTSCRIPT_EXECUTABLE} -dNOPAUSE -dBATCH -q -dEPSCrop -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sDEVICE=pngalpha -r18 -sOutputFile=gen-images/nodeshape_3.png ${CMAKE_CURRENT_SOURCE_DIR}/images/nodeshape_3.eps
    20       COMMAND ${GHOSTSCRIPT_EXECUTABLE} -dNOPAUSE -dBATCH -q -dEPSCrop -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sDEVICE=pngalpha -r18 -sOutputFile=gen-images/nodeshape_4.png ${CMAKE_CURRENT_SOURCE_DIR}/images/nodeshape_4.eps
     16      COMMAND ${GHOSTSCRIPT_EXECUTABLE} -dNOPAUSE -dBATCH -q -dEPSCrop -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sDEVICE=pngalpha -r36 -sOutputFile=gen-images/nodeshape_0.png ${CMAKE_CURRENT_SOURCE_DIR}/images/nodeshape_0.eps
     17      COMMAND ${GHOSTSCRIPT_EXECUTABLE} -dNOPAUSE -dBATCH -q -dEPSCrop -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sDEVICE=pngalpha -r36 -sOutputFile=gen-images/nodeshape_1.png ${CMAKE_CURRENT_SOURCE_DIR}/images/nodeshape_1.eps
     18      COMMAND ${GHOSTSCRIPT_EXECUTABLE} -dNOPAUSE -dBATCH -q -dEPSCrop -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sDEVICE=pngalpha -r36 -sOutputFile=gen-images/nodeshape_2.png ${CMAKE_CURRENT_SOURCE_DIR}/images/nodeshape_2.eps
     19      COMMAND ${GHOSTSCRIPT_EXECUTABLE} -dNOPAUSE -dBATCH -q -dEPSCrop -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sDEVICE=pngalpha -r36 -sOutputFile=gen-images/nodeshape_3.png ${CMAKE_CURRENT_SOURCE_DIR}/images/nodeshape_3.eps
     20      COMMAND ${GHOSTSCRIPT_EXECUTABLE} -dNOPAUSE -dBATCH -q -dEPSCrop -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sDEVICE=pngalpha -r36 -sOutputFile=gen-images/nodeshape_4.png ${CMAKE_CURRENT_SOURCE_DIR}/images/nodeshape_4.eps
     21      COMMAND ${GHOSTSCRIPT_EXECUTABLE} -dNOPAUSE -dBATCH -q -dEPSCrop -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sDEVICE=pngalpha -r36 -sOutputFile=gen-images/grid_graph.png ${CMAKE_CURRENT_SOURCE_DIR}/images/grid_graph.eps
    2122      COMMAND rm -rf html
    2223      COMMAND ${DOXYGEN_EXECUTABLE} Doxyfile
    2324      WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
     
    2526    ADD_CUSTOM_TARGET(html
    2627      COMMAND if exist gen-images rmdir /s /q gen-images
    2728      COMMAND mkdir gen-images
    28       COMMAND ${GHOSTSCRIPT_EXECUTABLE} -dNOPAUSE -dBATCH -q -dEPSCrop -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sDEVICE=pngalpha -r18 -sOutputFile=gen-images/nodeshape_0.png ${CMAKE_CURRENT_SOURCE_DIR}/images/nodeshape_0.eps
    29       COMMAND ${GHOSTSCRIPT_EXECUTABLE} -dNOPAUSE -dBATCH -q -dEPSCrop -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sDEVICE=pngalpha -r18 -sOutputFile=gen-images/nodeshape_1.png ${CMAKE_CURRENT_SOURCE_DIR}/images/nodeshape_1.eps
    30       COMMAND ${GHOSTSCRIPT_EXECUTABLE} -dNOPAUSE -dBATCH -q -dEPSCrop -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sDEVICE=pngalpha -r18 -sOutputFile=gen-images/nodeshape_2.png ${CMAKE_CURRENT_SOURCE_DIR}/images/nodeshape_2.eps
    31       COMMAND ${GHOSTSCRIPT_EXECUTABLE} -dNOPAUSE -dBATCH -q -dEPSCrop -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sDEVICE=pngalpha -r18 -sOutputFile=gen-images/nodeshape_3.png ${CMAKE_CURRENT_SOURCE_DIR}/images/nodeshape_3.eps
    32       COMMAND ${GHOSTSCRIPT_EXECUTABLE} -dNOPAUSE -dBATCH -q -dEPSCrop -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sDEVICE=pngalpha -r18 -sOutputFile=gen-images/nodeshape_4.png ${CMAKE_CURRENT_SOURCE_DIR}/images/nodeshape_4.eps
     29      COMMAND ${GHOSTSCRIPT_EXECUTABLE} -dNOPAUSE -dBATCH -q -dEPSCrop -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sDEVICE=pngalpha -r36 -sOutputFile=gen-images/nodeshape_0.png ${CMAKE_CURRENT_SOURCE_DIR}/images/nodeshape_0.eps
     30      COMMAND ${GHOSTSCRIPT_EXECUTABLE} -dNOPAUSE -dBATCH -q -dEPSCrop -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sDEVICE=pngalpha -r36 -sOutputFile=gen-images/nodeshape_1.png ${CMAKE_CURRENT_SOURCE_DIR}/images/nodeshape_1.eps
     31      COMMAND ${GHOSTSCRIPT_EXECUTABLE} -dNOPAUSE -dBATCH -q -dEPSCrop -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sDEVICE=pngalpha -r36 -sOutputFile=gen-images/nodeshape_2.png ${CMAKE_CURRENT_SOURCE_DIR}/images/nodeshape_2.eps
     32      COMMAND ${GHOSTSCRIPT_EXECUTABLE} -dNOPAUSE -dBATCH -q -dEPSCrop -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sDEVICE=pngalpha -r36 -sOutputFile=gen-images/nodeshape_3.png ${CMAKE_CURRENT_SOURCE_DIR}/images/nodeshape_3.eps
     33      COMMAND ${GHOSTSCRIPT_EXECUTABLE} -dNOPAUSE -dBATCH -q -dEPSCrop -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sDEVICE=pngalpha -r36 -sOutputFile=gen-images/nodeshape_4.png ${CMAKE_CURRENT_SOURCE_DIR}/images/nodeshape_4.eps
     34      COMMAND ${GHOSTSCRIPT_EXECUTABLE} -dNOPAUSE -dBATCH -q -dEPSCrop -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sDEVICE=pngalpha -r36 -sOutputFile=gen-images/grid_graph.png ${CMAKE_CURRENT_SOURCE_DIR}/images/grid_graph.eps
    3335      COMMAND if exist html rmdir /s /q html
    3436      COMMAND ${DOXYGEN_EXECUTABLE} Doxyfile
    3537      WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
  • doc/Makefile.am

    diff --git a/doc/Makefile.am b/doc/Makefile.am
    a b  
    1515        nodeshape_1.eps \
    1616        nodeshape_2.eps \
    1717        nodeshape_3.eps \
    18         nodeshape_4.eps
     18        nodeshape_4.eps \
     19        grid_graph.eps
    1920
    2021DOC_EPS_IMAGES = \
    2122        $(DOC_EPS_IMAGES18)
     
    3334$(DOC_EPS_IMAGES18:%.eps=doc/gen-images/%.png): doc/gen-images/%.png: doc/images/%.eps
    3435        -mkdir doc/gen-images
    3536        if test ${gs_found} = yes; then \
    36           $(GS_COMMAND) -sDEVICE=pngalpha -r18 -sOutputFile=$@ $<; \
     37          $(GS_COMMAND) -sDEVICE=pngalpha -r36 -sOutputFile=$@ $<; \
    3738        else \
    3839          echo; \
    3940          echo "Ghostscript not found."; \
  • new file doc/images/grid_graph.eps

    diff --git a/doc/images/grid_graph.eps b/doc/images/grid_graph.eps
    new file mode 100644
    - +  
     1%!PS-Adobe-2.0 EPSF-2.0
     2%%Title: Grid undirected graph
     3%%Copyright: (C) 2006 LEMON Project
     4%%Creator: LEMON, graphToEps()
     5%%CreationDate: Fri Sep 29 11:55:56 2006
     6%%BoundingBox: 0 0 596 842
     7%%DocumentPaperSizes: a4
     8%%EndComments
     9/lb { setlinewidth setrgbcolor newpath moveto
     10      4 2 roll 1 index 1 index curveto stroke } bind def
     11/l { setlinewidth setrgbcolor newpath moveto lineto stroke } bind def
     12/c { newpath dup 3 index add 2 index moveto 0 360 arc closepath } bind def
     13/sq { newpath 2 index 1 index add 2 index 2 index add moveto
     14      2 index 1 index sub 2 index 2 index add lineto
     15      2 index 1 index sub 2 index 2 index sub lineto
     16      2 index 1 index add 2 index 2 index sub lineto
     17      closepath pop pop pop} bind def
     18/di { newpath 2 index 1 index add 2 index moveto
     19      2 index             2 index 2 index add lineto
     20      2 index 1 index sub 2 index             lineto
     21      2 index             2 index 2 index sub lineto
     22      closepath pop pop pop} bind def
     23/nc { 0 0 0 setrgbcolor 5 index 5 index 5 index c fill
     24     setrgbcolor 1.1 div c fill
     25   } bind def
     26/arrl 1 def
     27/arrw 0.3 def
     28/lrl { 2 index mul exch 2 index mul exch rlineto pop} bind def
     29/arr { setrgbcolor /y1 exch def /x1 exch def /dy exch def /dx exch def
     30       /w exch def /len exch def
     31       newpath x1 dy w 2 div mul add y1 dx w 2 div mul sub moveto
     32       len w sub arrl sub dx dy lrl
     33       arrw dy dx neg lrl
     34       dx arrl w add mul dy w 2 div arrw add mul sub
     35       dy arrl w add mul dx w 2 div arrw add mul add rlineto
     36       dx arrl w add mul neg dy w 2 div arrw add mul sub
     37       dy arrl w add mul neg dx w 2 div arrw add mul add rlineto
     38       arrw dy dx neg lrl
     39       len w sub arrl sub neg dx dy lrl
     40       closepath fill } bind def
     41/cshow { 2 index 2 index moveto dup stringwidth pop
     42         neg 2 div fosi .35 mul neg rmoveto show pop pop} def
     43
     44gsave
     45100 150 translate
     465.5000 5.5000 scale
     471.14018 1.14018 translate
     48%Edges:
     49gsave
     5070 80 70 90 0 0 0 0.5000 l
     5170 70 70 80 0 0 0 0.5000 l
     5270 60 70 70 0 0 0 0.5000 l
     5370 50 70 60 0 0 0 0.5000 l
     5470 40 70 50 0 0 0 0.5000 l
     5570 30 70 40 0 0 0 0.5000 l
     5670 20 70 30 0 0 0 0.5000 l
     5770 10 70 20 0 0 0 0.5000 l
     5870 0 70 10 0 0 0 0.5000 l
     5960 80 60 90 0 0 0 0.5000 l
     6060 70 60 80 0 0 0 0.5000 l
     6160 60 60 70 0 0 0 0.5000 l
     6260 50 60 60 0 0 0 0.5000 l
     6360 40 60 50 0 0 0 0.5000 l
     6460 30 60 40 0 0 0 0.5000 l
     6560 20 60 30 0 0 0 0.5000 l
     6660 10 60 20 0 0 0 0.5000 l
     6760 0 60 10 0 0 0 0.5000 l
     6850 80 50 90 0 0 0 0.5000 l
     6950 70 50 80 0 0 0 0.5000 l
     7050 60 50 70 0 0 0 0.5000 l
     7150 50 50 60 0 0 0 0.5000 l
     7250 40 50 50 0 0 0 0.5000 l
     7350 30 50 40 0 0 0 0.5000 l
     7450 20 50 30 0 0 0 0.5000 l
     7550 10 50 20 0 0 0 0.5000 l
     7650 0 50 10 0 0 0 0.5000 l
     7740 80 40 90 0 0 0 0.5000 l
     7840 70 40 80 0 0 0 0.5000 l
     7940 60 40 70 0 0 0 0.5000 l
     8040 50 40 60 0 0 0 0.5000 l
     8140 40 40 50 0 0 0 0.5000 l
     8240 30 40 40 0 0 0 0.5000 l
     8340 20 40 30 0 0 0 0.5000 l
     8440 10 40 20 0 0 0 0.5000 l
     8540 0 40 10 0 0 0 0.5000 l
     8630 80 30 90 0 0 0 0.5000 l
     8730 70 30 80 0 0 0 0.5000 l
     8830 60 30 70 0 0 0 0.5000 l
     8930 50 30 60 0 0 0 0.5000 l
     9030 40 30 50 0 0 0 0.5000 l
     9130 30 30 40 0 0 0 0.5000 l
     9230 20 30 30 0 0 0 0.5000 l
     9330 10 30 20 0 0 0 0.5000 l
     9430 0 30 10 0 0 0 0.5000 l
     9520 80 20 90 0 0 0 0.5000 l
     9620 70 20 80 0 0 0 0.5000 l
     9720 60 20 70 0 0 0 0.5000 l
     9820 50 20 60 0 0 0 0.5000 l
     9920 40 20 50 0 0 0 0.5000 l
     10020 30 20 40 0 0 0 0.5000 l
     10120 20 20 30 0 0 0 0.5000 l
     10220 10 20 20 0 0 0 0.5000 l
     10320 0 20 10 0 0 0 0.5000 l
     10410 80 10 90 0 0 0 0.5000 l
     10510 70 10 80 0 0 0 0.5000 l
     10610 60 10 70 0 0 0 0.5000 l
     10710 50 10 60 0 0 0 0.5000 l
     10810 40 10 50 0 0 0 0.5000 l
     10910 30 10 40 0 0 0 0.5000 l
     11010 20 10 30 0 0 0 0.5000 l
     11110 10 10 20 0 0 0 0.5000 l
     11210 0 10 10 0 0 0 0.5000 l
     1130 80 0 90 0 0 0 0.5000 l
     1140 70 0 80 0 0 0 0.5000 l
     1150 60 0 70 0 0 0 0.5000 l
     1160 50 0 60 0 0 0 0.5000 l
     1170 40 0 50 0 0 0 0.5000 l
     1180 30 0 40 0 0 0 0.5000 l
     1190 20 0 30 0 0 0 0.5000 l
     1200 10 0 20 0 0 0 0.5000 l
     1210 0 0 10 0 0 0 0.5000 l
     12260 90 70 90 0 0 0 0.5000 l
     12360 80 70 80 0 0 0 0.5000 l
     12460 70 70 70 0 0 0 0.5000 l
     12560 60 70 60 0 0 0 0.5000 l
     12660 50 70 50 0 0 0 0.5000 l
     12760 40 70 40 0 0 0 0.5000 l
     12860 30 70 30 0 0 0 0.5000 l
     12960 20 70 20 0 0 0 0.5000 l
     13060 10 70 10 0 0 0 0.5000 l
     13160 0 70 0 0 0 0 0.5000 l
     13250 90 60 90 0 0 0 0.5000 l
     13350 80 60 80 0 0 0 0.5000 l
     13450 70 60 70 0 0 0 0.5000 l
     13550 60 60 60 0 0 0 0.5000 l
     13650 50 60 50 0 0 0 0.5000 l
     13750 40 60 40 0 0 0 0.5000 l
     13850 30 60 30 0 0 0 0.5000 l
     13950 20 60 20 0 0 0 0.5000 l
     14050 10 60 10 0 0 0 0.5000 l
     14150 0 60 0 0 0 0 0.5000 l
     14240 90 50 90 0 0 0 0.5000 l
     14340 80 50 80 0 0 0 0.5000 l
     14440 70 50 70 0 0 0 0.5000 l
     14540 60 50 60 0 0 0 0.5000 l
     14640 50 50 50 0 0 0 0.5000 l
     14740 40 50 40 0 0 0 0.5000 l
     14840 30 50 30 0 0 0 0.5000 l
     14940 20 50 20 0 0 0 0.5000 l
     15040 10 50 10 0 0 0 0.5000 l
     15140 0 50 0 0 0 0 0.5000 l
     15230 90 40 90 0 0 0 0.5000 l
     15330 80 40 80 0 0 0 0.5000 l
     15430 70 40 70 0 0 0 0.5000 l
     15530 60 40 60 0 0 0 0.5000 l
     15630 50 40 50 0 0 0 0.5000 l
     15730 40 40 40 0 0 0 0.5000 l
     15830 30 40 30 0 0 0 0.5000 l
     15930 20 40 20 0 0 0 0.5000 l
     16030 10 40 10 0 0 0 0.5000 l
     16130 0 40 0 0 0 0 0.5000 l
     16220 90 30 90 0 0 0 0.5000 l
     16320 80 30 80 0 0 0 0.5000 l
     16420 70 30 70 0 0 0 0.5000 l
     16520 60 30 60 0 0 0 0.5000 l
     16620 50 30 50 0 0 0 0.5000 l
     16720 40 30 40 0 0 0 0.5000 l
     16820 30 30 30 0 0 0 0.5000 l
     16920 20 30 20 0 0 0 0.5000 l
     17020 10 30 10 0 0 0 0.5000 l
     17120 0 30 0 0 0 0 0.5000 l
     17210 90 20 90 0 0 0 0.5000 l
     17310 80 20 80 0 0 0 0.5000 l
     17410 70 20 70 0 0 0 0.5000 l
     17510 60 20 60 0 0 0 0.5000 l
     17610 50 20 50 0 0 0 0.5000 l
     17710 40 20 40 0 0 0 0.5000 l
     17810 30 20 30 0 0 0 0.5000 l
     17910 20 20 20 0 0 0 0.5000 l
     18010 10 20 10 0 0 0 0.5000 l
     18110 0 20 0 0 0 0 0.5000 l
     1820 90 10 90 0 0 0 0.5000 l
     1830 80 10 80 0 0 0 0.5000 l
     1840 70 10 70 0 0 0 0.5000 l
     1850 60 10 60 0 0 0 0.5000 l
     1860 50 10 50 0 0 0 0.5000 l
     1870 40 10 40 0 0 0 0.5000 l
     1880 30 10 30 0 0 0 0.5000 l
     1890 20 10 20 0 0 0 0.5000 l
     1900 10 10 10 0 0 0 0.5000 l
     1910 0 10 0 0 0 0 0.5000 l
     192grestore
     193%Nodes:
     194gsave
     19570 90 1.4000 0 0 0 nc
     19670 80 1.4000 1 1 1 nc
     19770 70 1.4000 1 1 1 nc
     19870 60 1.4000 1 1 1 nc
     19970 50 1.4000 1 1 1 nc
     20070 40 1.4000 1 1 1 nc
     20170 30 1.4000 1 1 1 nc
     20270 20 1.4000 1 1 1 nc
     20370 10 1.4000 1 1 1 nc
     20470 0 1.4000 0 0 0 nc
     20560 90 1.4000 1 1 1 nc
     20660 80 1.4000 1 1 1 nc
     20760 70 1.4000 1 1 1 nc
     20860 60 1.4000 1 1 1 nc
     20960 50 1.4000 1 1 1 nc
     21060 40 1.4000 1 1 1 nc
     21160 30 1.4000 1 1 1 nc
     21260 20 1.4000 1 1 1 nc
     21360 10 1.4000 1 1 1 nc
     21460 0 1.4000 1 1 1 nc
     21550 90 1.4000 1 1 1 nc
     21650 80 1.4000 1 1 1 nc
     21750 70 1.4000 1 1 1 nc
     21850 60 1.4000 1 1 1 nc
     21950 50 1.4000 1 1 1 nc
     22050 40 1.4000 1 1 1 nc
     22150 30 1.4000 1 1 1 nc
     22250 20 1.4000 1 1 1 nc
     22350 10 1.4000 1 1 1 nc
     22450 0 1.4000 1 1 1 nc
     22540 90 1.4000 1 1 1 nc
     22640 80 1.4000 1 1 1 nc
     22740 70 1.4000 1 1 1 nc
     22840 60 1.4000 1 1 1 nc
     22940 50 1.4000 1 1 1 nc
     23040 40 1.4000 1 1 1 nc
     23140 30 1.4000 1 1 1 nc
     23240 20 1.4000 1 1 1 nc
     23340 10 1.4000 1 1 1 nc
     23440 0 1.4000 1 1 1 nc
     23530 90 1.4000 1 1 1 nc
     23630 80 1.4000 1 1 1 nc
     23730 70 1.4000 1 1 1 nc
     23830 60 1.4000 1 1 1 nc
     23930 50 1.4000 1 1 1 nc
     24030 40 1.4000 1 1 1 nc
     24130 30 1.4000 1 1 1 nc
     24230 20 1.4000 1 1 1 nc
     24330 10 1.4000 1 1 1 nc
     24430 0 1.4000 1 1 1 nc
     24520 90 1.4000 1 1 1 nc
     24620 80 1.4000 1 1 1 nc
     24720 70 1.4000 1 1 1 nc
     24820 60 1.4000 1 1 1 nc
     24920 50 1.4000 1 1 1 nc
     25020 40 1.4000 1 1 1 nc
     25120 30 1.4000 1 1 1 nc
     25220 20 1.4000 1 1 1 nc
     25320 10 1.4000 1 1 1 nc
     25420 0 1.4000 1 1 1 nc
     25510 90 1.4000 1 1 1 nc
     25610 80 1.4000 1 1 1 nc
     25710 70 1.4000 1 1 1 nc
     25810 60 1.4000 1 1 1 nc
     25910 50 1.4000 1 1 1 nc
     26010 40 1.4000 1 1 1 nc
     26110 30 1.4000 1 1 1 nc
     26210 20 1.4000 1 1 1 nc
     26310 10 1.4000 1 1 1 nc
     26410 0 1.4000 1 1 1 nc
     2650 90 1.4000 0 0 0 nc
     2660 80 1.4000 1 1 1 nc
     2670 70 1.4000 1 1 1 nc
     2680 60 1.4000 1 1 1 nc
     2690 50 1.4000 1 1 1 nc
     2700 40 1.4000 1 1 1 nc
     2710 30 1.4000 1 1 1 nc
     2720 20 1.4000 1 1 1 nc
     2730 10 1.4000 1 1 1 nc
     2740 0 1.4000 0 0 0 nc
     275grestore
     276gsave
     277/fosi 3.5 def
     278(Helvetica) findfont fosi scalefont setfont
     2790 0 0 setrgbcolor
     2800 95 ((0,height-1)) cshow
     28167 95 ((width-1,height-1)) cshow
     2820 -5 ((0,0)) cshow
     28370 -5 ((width-1,0)) cshow
     284grestore
     285grestore
     286showpage
  • doc/images/nodeshape_0.eps

    diff --git a/doc/images/nodeshape_0.eps b/doc/images/nodeshape_0.eps
    a b  
    11%!PS-Adobe-2.0 EPSF-2.0
    22%%Title: LEMON GraphToEps figure
    33%%Creator: LEMON GraphToEps function
    4 %%BoundingBox: 0 0 200 200
     4%%BoundingBox: 0 0 100 100
    55%%EndComments
    66/lb { setlinewidth setrgbcolor newpath moveto
    77      4 2 roll 1 index 1 index curveto stroke } bind def
     
    4545         neg 2 div fosi .35 mul neg rmoveto show pop pop} def
    4646
    4747gsave
    48 100 dup scale
     4850 dup scale
    4949%Edges:
    5050gsave
    5151grestore
  • doc/images/nodeshape_1.eps

    diff --git a/doc/images/nodeshape_1.eps b/doc/images/nodeshape_1.eps
    a b  
    11%!PS-Adobe-2.0 EPSF-2.0
    22%%Title: LEMON GraphToEps figure
    33%%Creator: LEMON GraphToEps function
    4 %%BoundingBox: 0 0 200 200
     4%%BoundingBox: 0 0 100 100
    55%%EndComments
    66/lb { setlinewidth setrgbcolor newpath moveto
    77      4 2 roll 1 index 1 index curveto stroke } bind def
     
    4545         neg 2 div fosi .35 mul neg rmoveto show pop pop} def
    4646
    4747gsave
    48 100 dup scale
     4850 dup scale
    4949%Edges:
    5050gsave
    5151grestore
  • doc/images/nodeshape_2.eps

    diff --git a/doc/images/nodeshape_2.eps b/doc/images/nodeshape_2.eps
    a b  
    11%!PS-Adobe-2.0 EPSF-2.0
    22%%Title: LEMON GraphToEps figure
    33%%Creator: LEMON GraphToEps function
    4 %%BoundingBox: 0 0 200 200
     4%%BoundingBox: 0 0 100 100
    55%%EndComments
    66/lb { setlinewidth setrgbcolor newpath moveto
    77      4 2 roll 1 index 1 index curveto stroke } bind def
     
    4545         neg 2 div fosi .35 mul neg rmoveto show pop pop} def
    4646
    4747gsave
    48 100 dup scale
     4850 dup scale
    4949%Edges:
    5050gsave
    5151grestore
  • doc/images/nodeshape_3.eps

    diff --git a/doc/images/nodeshape_3.eps b/doc/images/nodeshape_3.eps
    a b  
    11%!PS-Adobe-2.0 EPSF-2.0
    22%%Title: LEMON GraphToEps figure
    33%%Creator: LEMON GraphToEps function
    4 %%BoundingBox: 0 0 256 372
     4%%BoundingBox: 0 0 128 186
    55%%EndComments
    66/lb { setlinewidth setrgbcolor newpath moveto
    77      4 2 roll 1 index 1 index curveto stroke } bind def
     
    6565         neg 2 div fosi .35 mul neg rmoveto show pop pop} def
    6666
    6767gsave
    68 100 dup scale
     6850 dup scale
    6969%Edges:
    7070gsave
    7171grestore
  • doc/images/nodeshape_4.eps

    diff --git a/doc/images/nodeshape_4.eps b/doc/images/nodeshape_4.eps
    a b  
    11%!PS-Adobe-2.0 EPSF-2.0
    22%%Title: LEMON GraphToEps figure
    33%%Creator: LEMON GraphToEps function
    4 %%BoundingBox: 0 -199 200 200
     4%%BoundingBox: 0 -100 100 100
    55%%EndComments
    66/lb { setlinewidth setrgbcolor newpath moveto
    77      4 2 roll 1 index 1 index curveto stroke } bind def
     
    6565         neg 2 div fosi .35 mul neg rmoveto show pop pop} def
    6666
    6767gsave
    68 100 dup scale
     6850 dup scale
    6969%Edges:
    7070gsave
    7171grestore
  • lemon/grid_graph.h

    diff --git a/lemon/grid_graph.h b/lemon/grid_graph.h
    a b  
    1919#ifndef GRID_GRAPH_H
    2020#define GRID_GRAPH_H
    2121
    22 #include <iostream>
    2322#include <lemon/core.h>
     23#include <lemon/bits/graph_extender.h>
     24#include <lemon/dim2.h>
    2425#include <lemon/assert.h>
    25 
    26 #include <lemon/bits/base_extender.h>
    27 #include <lemon/bits/graph_extender.h>
    28 
    29 #include <lemon/dim2.h>
    3026
    3127///\ingroup graphs
    3228///\file
     
    4137    typedef GridGraphBase Graph;
    4238
    4339    class Node;
     40    class Edge;
    4441    class Arc;
    4542
    4643  public:
     
    4946
    5047  protected:
    5148
    52     void construct(int w, int h) {
    53       _height = h; _width = w;
    54       _nodeNum = h * w; _arcNum = 2 * _nodeNum - w - h;
    55       _arcLimit = _nodeNum - w;
    56     }
    57 
    58     Arc _down(Node n) const {
    59       if (n.id < _nodeNum - _width) {
    60         return Arc(n.id);
    61       } else {
    62         return INVALID;
    63       }
    64     }
    65 
    66     Arc _up(Node n) const {
    67       if (n.id >= _width) {
    68         return Arc(n.id - _width);
    69       } else {
    70         return INVALID;
    71       }
    72     }
    73 
    74     Arc _right(Node n) const {
    75       if (n.id % _width < _width - 1) {
    76         return _arcLimit + n.id % _width + (n.id / _width) * (_width - 1);
    77       } else {
    78         return INVALID;
    79       }
    80     }
    81 
    82     Arc _left(Node n) const {
    83       if (n.id % _width > 0) {
    84         return _arcLimit + n.id % _width + (n.id / _width) * (_width - 1) - 1;
    85       } else {
    86         return INVALID;
    87       }
     49    void construct(int width, int height) {
     50       _width = width; _height = height;
     51      _node_num = width * height;
     52      _edge_num = 2 * _node_num - width - height;
     53      _edge_limit = _node_num - _width;
    8854    }
    8955
    9056  public:
    9157
    9258    Node operator()(int i, int j) const {
    93       LEMON_ASSERT(0 <= i && i < width() &&
    94                    0 <= j && j < height(), "lemon::GridGraph::IndexError");
     59      LEMON_DEBUG(0 <= i && i < _width &&
     60                  0 <= j  && j < _height, "Index out of range");
    9561      return Node(i + j * _width);
    9662    }
    9763
    98     int row(Node n) const {
    99       return n.id / _width;
     64    int col(Node n) const {
     65      return n._id % _width;
    10066    }
    10167
    102     int col(Node n) const {
    103       return n.id % _width;
     68    int row(Node n) const {
     69      return n._id / _width;
     70    }
     71
     72    dim2::Point<int> pos(Node n) const {
     73      return dim2::Point<int>(col(n), row(n));
    10474    }
    10575
    10676    int width() const {
     
    11484    typedef True NodeNumTag;
    11585    typedef True ArcNumTag;
    11686
    117     int nodeNum() const { return _nodeNum; }
    118     int arcNum() const { return _arcNum; }
     87    int nodeNum() const { return _node_num; }
     88    int edgeNum() const { return _edge_num; }
     89    int arcNum() const { return 2 * _edge_num; }
    11990
    120     int maxNodeId() const { return nodeNum() - 1; }
    121     int maxArcId() const { return arcNum() - 1; }
    122 
    123     Node source(Arc e) const {
    124       if (e.id < _arcLimit) {
    125         return e.id;
     91    Node u(Edge edge) const {
     92      if (edge._id < _edge_limit) {
     93        return edge._id;
    12694      } else {
    127         return (e.id - _arcLimit) % (_width - 1) +
    128           (e.id - _arcLimit) / (_width - 1) * _width;
     95        return (edge._id - _edge_limit) % (_width - 1) +
     96          (edge._id - _edge_limit) / (_width - 1) * _width;
    12997      }
    13098    }
    13199
    132     Node target(Arc e) const {
    133       if (e.id < _arcLimit) {
    134         return e.id + _width;
     100    Node v(Edge edge) const {
     101      if (edge._id < _edge_limit) {
     102        return edge._id + _width;
    135103      } else {
    136         return (e.id - _arcLimit) % (_width - 1) +
    137           (e.id - _arcLimit) / (_width - 1) * _width + 1;
     104        return (edge._id - _edge_limit) % (_width - 1) +
     105          (edge._id - _edge_limit) / (_width - 1) * _width + 1;
    138106      }
    139107    }
    140108
    141     static int id(Node v) { return v.id; }
    142     static int id(Arc e) { return e.id; }
     109    Node source(Arc arc) const {
     110      return (arc._id & 1) == 1 ? u(arc) : v(arc);
     111    }
     112
     113    Node target(Arc arc) const {
     114      return (arc._id & 1) == 1 ? v(arc) : u(arc);
     115    }
     116
     117    static int id(Node node) { return node._id; }
     118    static int id(Edge edge) { return edge._id; }
     119    static int id(Arc arc) { return arc._id; }
     120
     121    int maxNodeId() const { return _node_num - 1; }
     122    int maxEdgeId() const { return _edge_num - 1; }
     123    int maxArcId() const { return 2 * _edge_num - 1; }
    143124
    144125    static Node nodeFromId(int id) { return Node(id);}
    145 
     126    static Edge edgeFromId(int id) { return Edge(id);}
    146127    static Arc arcFromId(int id) { return Arc(id);}
    147128
    148     typedef True FindArcTag;
     129    typedef True FindEdgeTag;
     130
     131    Edge findEdge(Node u, Node v, Edge prev = INVALID) const {
     132      if (prev != INVALID) return INVALID;
     133      if (v._id > u._id) {
     134        if (v._id - u._id == _width)
     135          return Edge(u._id);
     136        if (v._id - u._id == 1 && u._id % _width < _width - 1) {
     137          return Edge(u._id / _width * (_width - 1) +
     138                      u._id % _width + _edge_limit);
     139        }
     140      } else {
     141        if (u._id - v._id == _width)
     142          return Edge(v._id);
     143        if (u._id - v._id == 1 && v._id % _width < _width - 1) {
     144          return Edge(v._id / _width * (_width - 1) +
     145                      v._id % _width + _edge_limit);
     146        }
     147      }
     148      return INVALID;
     149    }
    149150
    150151    Arc findArc(Node u, Node v, Arc prev = INVALID) const {
    151152      if (prev != INVALID) return INVALID;
    152       if (v.id - u.id == _width) return Arc(u.id);
    153       if (v.id - u.id == 1 && u.id % _width < _width - 1) {
    154         return Arc(u.id / _width * (_width - 1) +
    155                    u.id % _width + _arcLimit);
     153      if (v._id > u._id) {
     154        if (v._id - u._id == _width)
     155          return Arc((u._id << 1) | 1);
     156        if (v._id - u._id == 1 && u._id % _width < _width - 1) {
     157          return Arc(((u._id / _width * (_width - 1) +
     158                       u._id % _width + _edge_limit) << 1) | 1);
     159        }
     160      } else {
     161        if (u._id - v._id == _width)
     162          return Arc(v._id << 1);
     163        if (u._id - v._id == 1 && v._id % _width < _width - 1) {
     164          return Arc((v._id / _width * (_width - 1) +
     165                       v._id % _width + _edge_limit) << 1);
     166        }
    156167      }
    157168      return INVALID;
    158169    }
     
    161172      friend class GridGraphBase;
    162173
    163174    protected:
    164       int id;
    165       Node(int _id) : id(_id) {}
     175      int _id;
     176      Node(int id) : _id(id) {}
    166177    public:
    167178      Node() {}
    168       Node (Invalid) { id = -1; }
    169       bool operator==(const Node node) const { return id == node.id; }
    170       bool operator!=(const Node node) const { return id != node.id; }
    171       bool operator<(const Node node) const { return id < node.id; }
     179      Node (Invalid) : _id(-1) {}
     180      bool operator==(const Node node) const {return _id == node._id;}
     181      bool operator!=(const Node node) const {return _id != node._id;}
     182      bool operator<(const Node node) const {return _id < node._id;}
     183    };
     184
     185    class Edge {
     186      friend class GridGraphBase;
     187      friend class Arc;
     188
     189    protected:
     190      int _id;
     191
     192      Edge(int id) : _id(id) {}
     193
     194    public:
     195      Edge() {}
     196      Edge (Invalid) : _id(-1) {}
     197      bool operator==(const Edge edge) const {return _id == edge._id;}
     198      bool operator!=(const Edge edge) const {return _id != edge._id;}
     199      bool operator<(const Edge edge) const {return _id < edge._id;}
    172200    };
    173201
    174202    class Arc {
    175203      friend class GridGraphBase;
    176204
    177205    protected:
    178       int id;
    179       Arc(int _id) : id(_id) {}
     206      int _id;
     207
     208      Arc(int id) : _id(id) {}
     209
    180210    public:
    181211      Arc() {}
    182       Arc (Invalid) { id = -1; }
    183       bool operator==(const Arc arc) const { return id == arc.id; }
    184       bool operator!=(const Arc arc) const { return id != arc.id; }
    185       bool operator<(const Arc arc) const { return id < arc.id; }
     212      Arc (Invalid) : _id(-1) {}
     213      operator Edge() const { return _id != -1 ? Edge(_id >> 1) : INVALID; }
     214      bool operator==(const Arc arc) const {return _id == arc._id;}
     215      bool operator!=(const Arc arc) const {return _id != arc._id;}
     216      bool operator<(const Arc arc) const {return _id < arc._id;}
    186217    };
    187218
     219    static bool direction(Arc arc) {
     220      return (arc._id & 1) == 1;
     221    }
     222
     223    static Arc direct(Edge edge, bool dir) {
     224      return Arc((edge._id << 1) | (dir ? 1 : 0));
     225    }
     226
    188227    void first(Node& node) const {
    189       node.id = nodeNum() - 1;
     228      node._id = _node_num - 1;
    190229    }
    191230
    192231    static void next(Node& node) {
    193       --node.id;
     232      --node._id;
     233    }
     234
     235    void first(Edge& edge) const {
     236      edge._id = _edge_num - 1;
     237    }
     238
     239    static void next(Edge& edge) {
     240      --edge._id;
    194241    }
    195242
    196243    void first(Arc& arc) const {
    197       arc.id = arcNum() - 1;
     244      arc._id = 2 * _edge_num - 1;
    198245    }
    199246
    200247    static void next(Arc& arc) {
    201       --arc.id;
     248      --arc._id;
    202249    }
    203250
    204251    void firstOut(Arc& arc, const Node& node) const {
    205       if (node.id < _nodeNum - _width) {
    206         arc.id = node.id;
    207       } else if (node.id % _width < _width - 1) {
    208         arc.id = _arcLimit + node.id % _width +
    209           (node.id / _width) * (_width - 1);
     252      if (node._id % _width < _width - 1) {
     253        arc._id = (_edge_limit + node._id % _width +
     254                   (node._id / _width) * (_width - 1)) << 1 | 1;
     255        return;
     256      }
     257      if (node._id < _node_num - _width) {
     258        arc._id = node._id << 1 | 1;
     259        return;
     260      }
     261      if (node._id % _width > 0) {
     262        arc._id = (_edge_limit + node._id % _width +
     263                   (node._id / _width) * (_width - 1) - 1) << 1;
     264        return;
     265      }
     266      if (node._id >= _width) {
     267        arc._id = (node._id - _width) << 1;
     268        return;
     269      }
     270      arc._id = -1;
     271    }
     272
     273    void nextOut(Arc& arc) const {
     274      int nid = arc._id >> 1;
     275      if ((arc._id & 1) == 1) {
     276        if (nid >= _edge_limit) {
     277          nid = (nid - _edge_limit) % (_width - 1) +
     278            (nid - _edge_limit) / (_width - 1) * _width;
     279          if (nid < _node_num - _width) {
     280            arc._id = nid << 1 | 1;
     281            return;
     282          }
     283        }
     284        if (nid % _width > 0) {
     285          arc._id = (_edge_limit + nid % _width +
     286                     (nid / _width) * (_width - 1) - 1) << 1;
     287          return;
     288        }
     289        if (nid >= _width) {
     290          arc._id = (nid - _width) << 1;
     291          return;
     292        }
    210293      } else {
    211         arc.id = -1;
     294        if (nid >= _edge_limit) {
     295          nid = (nid - _edge_limit) % (_width - 1) +
     296            (nid - _edge_limit) / (_width - 1) * _width + 1;
     297          if (nid >= _width) {
     298            arc._id = (nid - _width) << 1;
     299            return;
     300          }
     301        }
     302      }
     303      arc._id = -1;
     304    }
     305
     306    void firstIn(Arc& arc, const Node& node) const {
     307      if (node._id % _width < _width - 1) {
     308        arc._id = (_edge_limit + node._id % _width +
     309                   (node._id / _width) * (_width - 1)) << 1;
     310        return;
     311      }
     312      if (node._id < _node_num - _width) {
     313        arc._id = node._id << 1;
     314        return;
     315      }
     316      if (node._id % _width > 0) {
     317        arc._id = (_edge_limit + node._id % _width +
     318                   (node._id / _width) * (_width - 1) - 1) << 1 | 1;
     319        return;
     320      }
     321      if (node._id >= _width) {
     322        arc._id = (node._id - _width) << 1 | 1;
     323        return;
     324      }
     325      arc._id = -1;
     326    }
     327
     328    void nextIn(Arc& arc) const {
     329      int nid = arc._id >> 1;
     330      if ((arc._id & 1) == 0) {
     331        if (nid >= _edge_limit) {
     332          nid = (nid - _edge_limit) % (_width - 1) +
     333            (nid - _edge_limit) / (_width - 1) * _width;
     334          if (nid < _node_num - _width) {
     335            arc._id = nid << 1;
     336            return;
     337          }
     338        }
     339        if (nid % _width > 0) {
     340          arc._id = (_edge_limit + nid % _width +
     341                     (nid / _width) * (_width - 1) - 1) << 1 | 1;
     342          return;
     343        }
     344        if (nid >= _width) {
     345          arc._id = (nid - _width) << 1 | 1;
     346          return;
     347        }
     348      } else {
     349        if (nid >= _edge_limit) {
     350          nid = (nid - _edge_limit) % (_width - 1) +
     351            (nid - _edge_limit) / (_width - 1) * _width + 1;
     352          if (nid >= _width) {
     353            arc._id = (nid - _width) << 1 | 1;
     354            return;
     355          }
     356        }
     357      }
     358      arc._id = -1;
     359    }
     360
     361    void firstInc(Edge& edge, bool& dir, const Node& node) const {
     362      if (node._id % _width < _width - 1) {
     363        edge._id = _edge_limit + node._id % _width +
     364          (node._id / _width) * (_width - 1);
     365        dir = true;
     366        return;
     367      }
     368      if (node._id < _node_num - _width) {
     369        edge._id = node._id;
     370        dir = true;
     371        return;
     372      }
     373      if (node._id % _width > 0) {
     374        edge._id = _edge_limit + node._id % _width +
     375          (node._id / _width) * (_width - 1) - 1;
     376        dir = false;
     377        return;
     378      }
     379      if (node._id >= _width) {
     380        edge._id = node._id - _width;
     381        dir = false;
     382        return;
     383      }
     384      edge._id = -1;
     385      dir = true;
     386    }
     387
     388    void nextInc(Edge& edge, bool& dir) const {
     389      int nid = edge._id;
     390      if (dir) {
     391        if (nid >= _edge_limit) {
     392          nid = (nid - _edge_limit) % (_width - 1) +
     393            (nid - _edge_limit) / (_width - 1) * _width;
     394          if (nid < _node_num - _width) {
     395            edge._id = nid;
     396            return;
     397          }
     398        }
     399        if (nid % _width > 0) {
     400          edge._id = _edge_limit + nid % _width +
     401            (nid / _width) * (_width - 1) - 1;
     402          dir = false;
     403          return;
     404        }
     405        if (nid >= _width) {
     406          edge._id = nid - _width;
     407          dir = false;
     408          return;
     409        }
     410      } else {
     411        if (nid >= _edge_limit) {
     412          nid = (nid - _edge_limit) % (_width - 1) +
     413            (nid - _edge_limit) / (_width - 1) * _width + 1;
     414          if (nid >= _width) {
     415            edge._id = nid - _width;
     416            return;
     417          }
     418        }
     419      }
     420      edge._id = -1;
     421      dir = true;
     422    }
     423
     424    Arc right(Node n) const {
     425      if (n._id % _width < _width - 1) {
     426        return Arc(((_edge_limit + n._id % _width +
     427                    (n._id / _width) * (_width - 1)) << 1) | 1);
     428      } else {
     429        return INVALID;
    212430      }
    213431    }
    214432
    215     void nextOut(Arc& arc) const {
    216       if (arc.id >= _arcLimit) {
    217         arc.id = -1;
    218       } else if (arc.id % _width < _width - 1) {
    219         arc.id = _arcLimit + arc.id % _width +
    220           (arc.id / _width) * (_width - 1);
     433    Arc left(Node n) const {
     434      if (n._id % _width > 0) {
     435        return Arc((_edge_limit + n._id % _width +
     436                     (n._id / _width) * (_width - 1) - 1) << 1);
    221437      } else {
    222         arc.id = -1;
     438        return INVALID;
    223439      }
    224440    }
    225441
    226     void firstIn(Arc& arc, const Node& node) const {
    227       if (node.id >= _width) {
    228         arc.id = node.id - _width;
    229       } else if (node.id % _width > 0) {
    230         arc.id = _arcLimit + node.id % _width +
    231           (node.id / _width) * (_width - 1) - 1;
     442    Arc up(Node n) const {
     443      if (n._id < _edge_limit) {
     444        return Arc((n._id << 1) | 1);
    232445      } else {
    233         arc.id = -1;
     446        return INVALID;
    234447      }
    235448    }
    236449
    237     void nextIn(Arc& arc) const {
    238       if (arc.id >= _arcLimit) {
    239         arc.id = -1;
    240       } else if (arc.id % _width > 0) {
    241         arc.id = _arcLimit + arc.id % _width +
    242           (arc.id / _width + 1) * (_width - 1) - 1;
     450    Arc down(Node n) const {
     451      if (n._id >= _width) {
     452        return Arc((n._id - _width) << 1);
    243453      } else {
    244         arc.id = -1;
     454        return INVALID;
    245455      }
    246456    }
    247457
    248458  private:
    249459    int _width, _height;
    250     int _nodeNum, _arcNum;
    251     int _arcLimit;
     460    int _node_num, _edge_num;
     461    int _edge_limit;
    252462  };
    253463
    254   typedef GraphExtender<UndirDigraphExtender<GridGraphBase> >
    255     ExtendedGridGraphBase;
     464
     465  typedef GraphExtender<GridGraphBase> ExtendedGridGraphBase;
    256466
    257467  /// \ingroup graphs
    258468  ///
    259469  /// \brief Grid graph class
    260470  ///
    261471  /// This class implements a special graph type. The nodes of the
    262   /// graph can be indiced by two integer \c (i,j) value where \c i
    263   /// is in the \c [0,width) range and j is in the [0, height) range.
    264   /// Two nodes are connected in the graph if the indices differ only
    265   /// on one position and only one is the difference.
     472  /// graph can be indexed by two integer \c (i,j) value where \c i is
     473  /// in the \c [0..width()-1] range and j is in the \c
     474  /// [0..height()-1] range.  Two nodes are connected in the graph if
     475  /// the indexes differ exactly on one position and exactly one is
     476  /// the difference. The nodes of the graph can be indexed by position
     477  /// with the \c operator()() function. The positions of the nodes can be
     478  /// get with \c pos(), \c col() and \c row() members. The outgoing
     479  /// arcs can be retrieved with the \c right(), \c up(), \c left()
     480  /// and \c down() functions, where the bottom-left corner is the
     481  /// origin.
    266482  ///
    267483  /// \image html grid_graph.png
    268   /// \image latex grid_graph.eps "Grid graph" width=\textwidth
     484  /// \image latex grid_graph.eps "Grid graph" row_num=\textrow_num
    269485  ///
    270   /// The graph can be indiced in the following way:
     486  /// A short example about the basic usage:
    271487  ///\code
    272   /// GridGraph gr(w, h);
    273   /// GridGraph::NodeMap<int> val(gr);
    274   /// for (int i = 0; i < gr.width(); ++i) {
    275   ///   for (int j = 0; j < gr.height(); ++j) {
    276   ///     val[gr(i, j)] = i + j;
     488  /// GridGraph graph(rows, cols);
     489  /// GridGraph::NodeMap<int> val(graph);
     490  /// for (int i = 0; i < graph.width(); ++i) {
     491  ///   for (int j = 0; j < graph.height(); ++j) {
     492  ///     val[graph(i, j)] = i + j;
    277493  ///   }
    278494  /// }
    279495  ///\endcode
    280496  ///
    281497  /// This graph type is fully conform to the \ref concepts::Graph
    282   /// "Undirected Graph" concept, and it also has an important extra
    283   /// feature that its maps are real \ref concepts::ReferenceMap
     498  /// "Graph" concept, and it also has an important extra feature
     499  /// that its maps are real \ref concepts::ReferenceMap
    284500  /// "reference map"s.
    285501  class GridGraph : public ExtendedGridGraphBase {
    286502  public:
     
    292508    /// Map to get the indices of the nodes as dim2::Point<int>.
    293509    class IndexMap {
    294510    public:
    295       /// The key type of the map
     511      /// \brief The key type of the map
    296512      typedef GridGraph::Node Key;
    297       /// The value type of the map
     513      /// \brief The value type of the map
    298514      typedef dim2::Point<int> Value;
    299515
     516      /// \brief Constructor
     517      ///
    300518      /// Constructor
    301519      IndexMap(const GridGraph& graph) : _graph(graph) {}
    302520
    303       /// The subscript operator
    304       Value operator[](const Key& key) const {
    305         return dim2::Point<int>(_graph.row(key), _graph.col(key));
     521      /// \brief The subscript operator
     522      ///
     523      /// The subscript operator.
     524      Value operator[](Key key) const {
     525        return _graph.pos(key);
     526      }
     527
     528    private:
     529      const GridGraph& _graph;
     530    };
     531
     532    /// \brief Map to get the column of the nodes.
     533    ///
     534    /// Map to get the column of the nodes.
     535    class ColMap {
     536    public:
     537      /// \brief The key type of the map
     538      typedef GridGraph::Node Key;
     539      /// \brief The value type of the map
     540      typedef int Value;
     541
     542      /// \brief Constructor
     543      ///
     544      /// Constructor
     545      ColMap(const GridGraph& graph) : _graph(graph) {}
     546
     547      /// \brief The subscript operator
     548      ///
     549      /// The subscript operator.
     550      Value operator[](Key key) const {
     551        return _graph.col(key);
    306552      }
    307553
    308554    private:
     
    314560    /// Map to get the row of the nodes.
    315561    class RowMap {
    316562    public:
    317       /// The key type of the map
     563      /// \brief The key type of the map
    318564      typedef GridGraph::Node Key;
    319       /// The value type of the map
     565      /// \brief The value type of the map
    320566      typedef int Value;
    321567
     568      /// \brief Constructor
     569      ///
    322570      /// Constructor
    323571      RowMap(const GridGraph& graph) : _graph(graph) {}
    324572
    325       /// The subscript operator
    326       Value operator[](const Key& key) const {
     573      /// \brief The subscript operator
     574      ///
     575      /// The subscript operator.
     576      Value operator[](Key key) const {
    327577        return _graph.row(key);
    328       }
    329 
    330     private:
    331       const GridGraph& _graph;
    332     };
    333 
    334     /// \brief Map to get the column of the nodes.
    335     ///
    336     /// Map to get the column of the nodes.
    337     class ColMap {
    338     public:
    339       /// The key type of the map
    340       typedef GridGraph::Node Key;
    341       /// The value type of the map
    342       typedef int Value;
    343 
    344       /// Constructor
    345       ColMap(const GridGraph& graph) : _graph(graph) {}
    346 
    347       /// The subscript operator
    348       Value operator[](const Key& key) const {
    349         return _graph.col(key);
    350578      }
    351579
    352580    private:
     
    355583
    356584    /// \brief Constructor
    357585    ///
    358     /// Constructor.
    359     /// \param width The width of the grid.
    360     /// \param height The height of the grid.
     586    /// Construct a grid graph with given size.
    361587    GridGraph(int width, int height) { construct(width, height); }
    362588
    363589    /// \brief Resize the graph
    364590    ///
    365     /// Resize the grid.
     591    /// Resize the graph. The function will fully destroy and rebuild
     592    /// the graph.  This cause that the maps of the graph will
     593    /// reallocated automatically and the previous values will be
     594    /// lost.
    366595    void resize(int width, int height) {
    367596      Parent::notifier(Arc()).clear();
    368597      Parent::notifier(Edge()).clear();
     
    380609      return Parent::operator()(i, j);
    381610    }
    382611
     612    /// \brief Gives back the column index of the node.
     613    ///
     614    /// Gives back the column index of the node.
     615    int col(Node n) const {
     616      return Parent::col(n);
     617    }
     618
    383619    /// \brief Gives back the row index of the node.
    384620    ///
    385621    /// Gives back the row index of the node.
     
    387623      return Parent::row(n);
    388624    }
    389625
    390     /// \brief Gives back the column index of the node.
     626    /// \brief Gives back the position of the node.
    391627    ///
    392     /// Gives back the column index of the node.
    393     int col(Node n) const {
    394       return Parent::col(n);
     628    /// Gives back the position of the node, ie. the <tt>(col,row)</tt> pair.
     629    dim2::Point<int> pos(Node n) const {
     630      return Parent::pos(n);
    395631    }
    396632
    397     /// \brief Gives back the width of the grid.
     633    /// \brief Gives back the number of the columns.
    398634    ///
    399     /// Gives back the width of the grid.
     635    /// Gives back the number of the columns.
    400636    int width() const {
    401637      return Parent::width();
    402638    }
    403639
    404     /// \brief Gives back the height of the grid.
     640    /// \brief Gives back the number of the rows.
    405641    ///
    406     /// Gives back the height of the grid.
     642    /// Gives back the number of the rows.
    407643    int height() const {
    408644      return Parent::height();
     645    }
     646
     647    /// \brief Gives back the arc goes right from the node.
     648    ///
     649    /// Gives back the arc goes right from the node. If there is not
     650    /// outgoing arc then it gives back INVALID.
     651    Arc right(Node n) const {
     652      return Parent::right(n);
     653    }
     654
     655    /// \brief Gives back the arc goes left from the node.
     656    ///
     657    /// Gives back the arc goes left from the node. If there is not
     658    /// outgoing arc then it gives back INVALID.
     659    Arc left(Node n) const {
     660      return Parent::left(n);
     661    }
     662
     663    /// \brief Gives back the arc goes up from the node.
     664    ///
     665    /// Gives back the arc goes up from the node. If there is not
     666    /// outgoing arc then it gives back INVALID.
     667    Arc up(Node n) const {
     668      return Parent::up(n);
    409669    }
    410670
    411671    /// \brief Gives back the arc goes down from the node.
    412672    ///
    413673    /// Gives back the arc goes down from the node. If there is not
    414     /// outgoing arc then it gives back \c INVALID.
     674    /// outgoing arc then it gives back INVALID.
    415675    Arc down(Node n) const {
    416       Edge e = _down(n);
    417       return e != INVALID ? direct(e, true) : INVALID;
     676      return Parent::down(n);
    418677    }
    419678
    420     /// \brief Gives back the arc goes up from the node.
     679    /// \brief Index map of the grid graph
    421680    ///
    422     /// Gives back the arc goes up from the node. If there is not
    423     /// outgoing arc then it gives back \c INVALID.
    424     Arc up(Node n) const {
    425       Edge e = _up(n);
    426       return e != INVALID ? direct(e, false) : INVALID;
     681    /// Just returns an IndexMap for the grid graph.
     682    IndexMap indexMap() const {
     683      return IndexMap(*this);
    427684    }
    428685
    429     /// \brief Gives back the arc goes right from the node.
     686    /// \brief Row map of the grid graph
    430687    ///
    431     /// Gives back the arc goes right from the node. If there is not
    432     /// outgoing arc then it gives back \c INVALID.
    433     Arc right(Node n) const {
    434       Edge e = _right(n);
    435       return e != INVALID ? direct(e, true) : INVALID;
     688    /// Just returns a RowMap for the grid graph.
     689    RowMap rowMap() const {
     690      return RowMap(*this);
    436691    }
    437692
    438     /// \brief Gives back the arc goes left from the node.
     693    /// \brief Column map of the grid graph
    439694    ///
    440     /// Gives back the arc goes left from the node. If there is not
    441     /// outgoing arc then it gives back \c INVALID.
    442     Arc left(Node n) const {
    443       Edge e = _left(n);
    444       return e != INVALID ? direct(e, false) : INVALID;
     695    /// Just returns a ColMap for the grid graph.
     696    ColMap colMap() const {
     697      return ColMap(*this);
    445698    }
    446699
    447   }; // class GridGraph
     700  };
    448701
    449   /// \brief Index map of the grid graph
    450   ///
    451   /// Just returns an IndexMap for the grid graph.
    452   inline GridGraph::IndexMap indexMap(const GridGraph& graph) {
    453     return GridGraph::IndexMap(graph);
    454   }
    455 
    456   /// \brief Row map of the grid graph
    457   ///
    458   /// Just returns a RowMap for the grid graph.
    459   inline GridGraph::RowMap rowMap(const GridGraph& graph) {
    460     return GridGraph::RowMap(graph);
    461   }
    462 
    463   /// \brief Column map of the grid graph
    464   ///
    465   /// Just returns a ColMap for the grid graph.
    466   inline GridGraph::ColMap colMap(const GridGraph& graph) {
    467     return GridGraph::ColMap(graph);
    468   }
    469702}
    470 
    471 #endif // GRID_GRAPH_H
     703#endif
  • test/graph_test.cc

    diff --git a/test/graph_test.cc b/test/graph_test.cc
    a b  
    126126  }
    127127//  { // Checking FullGraph
    128128//    checkConcept<Graph, FullGraph>();
     129//    checkGraphIterators<FullGraph>();
    129130//  }
    130131  { // Checking GridGraph
    131132    checkConcept<Graph, GridGraph>();
     
    186187  check(!g.valid(g.arcFromId(-1)), "Wrong validity check");
    187188}
    188189
    189 void checkGridGraph(const GridGraph& g, int w, int h) {
    190   check(g.width() == w, "Wrong width");
    191   check(g.height() == h, "Wrong height");
     190void checkGridGraph(int width, int height) {
     191  typedef GridGraph Graph;
     192  GRAPH_TYPEDEFS(Graph);
     193  Graph G(width, height);
    192194
    193   for (int i = 0; i < w; ++i) {
    194     for (int j = 0; j < h; ++j) {
    195       check(g.col(g(i, j)) == i, "Wrong col");
    196       check(g.row(g(i, j)) == j, "Wrong row");
     195  check(G.width() == width, "Wrong column number");
     196  check(G.height() == height, "Wrong row number");
     197
     198  for (int i = 0; i < width; ++i) {
     199    for (int j = 0; j < height; ++j) {
     200      check(G.col(G(i, j)) == i, "Wrong column");
     201      check(G.row(G(i, j)) == j, "Wrong row");
     202      check(G.pos(G(i, j)).x == i, "Wrong column");
     203      check(G.pos(G(i, j)).y == j, "Wrong row");
    197204    }
    198205  }
    199206
    200   for (int i = 0; i < w; ++i) {
    201     for (int j = 0; j < h - 1; ++j) {
    202       check(g.source(g.down(g(i, j))) == g(i, j), "Wrong down");
    203       check(g.target(g.down(g(i, j))) == g(i, j + 1), "Wrong down");
     207  for (int j = 0; j < height; ++j) {
     208    for (int i = 0; i < width - 1; ++i) {
     209      check(G.source(G.right(G(i, j))) == G(i, j), "Wrong right");
     210      check(G.target(G.right(G(i, j))) == G(i + 1, j), "Wrong right");
    204211    }
    205     check(g.down(g(i, h - 1)) == INVALID, "Wrong down");
     212    check(G.right(G(width - 1, j)) == INVALID, "Wrong right");
    206213  }
    207214
    208   for (int i = 0; i < w; ++i) {
    209     for (int j = 1; j < h; ++j) {
    210       check(g.source(g.up(g(i, j))) == g(i, j), "Wrong up");
    211       check(g.target(g.up(g(i, j))) == g(i, j - 1), "Wrong up");
     215  for (int j = 0; j < height; ++j) {
     216    for (int i = 1; i < width; ++i) {
     217      check(G.source(G.left(G(i, j))) == G(i, j), "Wrong left");
     218      check(G.target(G.left(G(i, j))) == G(i - 1, j), "Wrong left");
    212219    }
    213     check(g.up(g(i, 0)) == INVALID, "Wrong up");
     220    check(G.left(G(0, j)) == INVALID, "Wrong left");
    214221  }
    215222
    216   for (int j = 0; j < h; ++j) {
    217     for (int i = 0; i < w - 1; ++i) {
    218       check(g.source(g.right(g(i, j))) == g(i, j), "Wrong right");
    219       check(g.target(g.right(g(i, j))) == g(i + 1, j), "Wrong right");
     223  for (int i = 0; i < width; ++i) {
     224    for (int j = 0; j < height - 1; ++j) {
     225      check(G.source(G.up(G(i, j))) == G(i, j), "Wrong up");
     226      check(G.target(G.up(G(i, j))) == G(i, j + 1), "Wrong up");
    220227    }
    221     check(g.right(g(w - 1, j)) == INVALID, "Wrong right");
     228    check(G.up(G(i, height - 1)) == INVALID, "Wrong up");
    222229  }
    223230
    224   for (int j = 0; j < h; ++j) {
    225     for (int i = 1; i < w; ++i) {
    226       check(g.source(g.left(g(i, j))) == g(i, j), "Wrong left");
    227       check(g.target(g.left(g(i, j))) == g(i - 1, j), "Wrong left");
     231  for (int i = 0; i < width; ++i) {
     232    for (int j = 1; j < height; ++j) {
     233      check(G.source(G.down(G(i, j))) == G(i, j), "Wrong down");
     234      check(G.target(G.down(G(i, j))) == G(i, j - 1), "Wrong down");
    228235    }
    229     check(g.left(g(0, j)) == INVALID, "Wrong left");
     236    check(G.down(G(i, 0)) == INVALID, "Wrong down");
    230237  }
    231238
    232   checkGraphNodeList(g, w*h);
    233   checkGraphArcList(g, 2*(2*w*h-w-h));
    234   checkGraphEdgeList(g, 2*w*h-w-h);
     239  checkGraphNodeList(G, width * height);
     240  checkGraphEdgeList(G, width * (height - 1) + (width - 1) * height);
     241  checkGraphArcList(G, 2 * (width * (height - 1) + (width - 1) * height));
    235242
    236   checkGraphOutArcList(g, g(0,0), 2);
    237   checkGraphOutArcList(g, g(0,1), 3);
    238   checkGraphOutArcList(g, g(w-2,h-2), 4);
     243  for (NodeIt n(G); n != INVALID; ++n) {
     244    int nb = 4;
     245    if (G.col(n) == 0) --nb;
     246    if (G.col(n) == width - 1) --nb;
     247    if (G.row(n) == 0) --nb;
     248    if (G.row(n) == height - 1) --nb;
    239249
    240   checkGraphInArcList(g, g(0,0), 2);
    241   checkGraphInArcList(g, g(0,1), 3);
    242   checkGraphInArcList(g, g(w-2,h-2), 4);
     250    checkGraphOutArcList(G, n, nb);
     251    checkGraphInArcList(G, n, nb);
     252    checkGraphIncEdgeList(G, n, nb);
     253  }
    243254
    244   checkGraphIncEdgeList(g, g(0,0), 2);
    245   checkGraphIncEdgeList(g, g(0,1), 3);
    246   checkGraphIncEdgeList(g, g(w-2,h-2), 4);
     255  checkArcDirections(G);
    247256
    248   checkGraphConArcList(g, 2*(2*w*h-w-h));
    249   checkGraphConEdgeList(g, 2*w*h-w-h);
     257  checkGraphConArcList(G, 2 * (width * (height - 1) + (width - 1) * height));
     258  checkGraphConEdgeList(G, width * (height - 1) + (width - 1) * height);
    250259
    251   checkArcDirections(g);
     260  checkNodeIds(G);
     261  checkArcIds(G);
     262  checkEdgeIds(G);
     263  checkGraphNodeMap(G);
     264  checkGraphArcMap(G);
     265  checkGraphEdgeMap(G);
    252266
    253   checkNodeIds(g);
    254   checkArcIds(g);
    255   checkEdgeIds(g);
    256   checkGraphNodeMap(g);
    257   checkGraphArcMap(g);
    258   checkGraphEdgeMap(g);
    259267}
    260268
    261269void checkGraphs() {
     
    273281//     checkGraphEdgeList(g, 10);
    274282//   }
    275283  { // Checking GridGraph
    276     GridGraph g(5, 6);
    277     checkGridGraph(g, 5, 6);
     284    checkGridGraph(5, 8);
     285    checkGridGraph(8, 5);
     286    checkGridGraph(5, 5);
     287    checkGridGraph(0, 0);
     288    checkGridGraph(1, 1);
    278289  }
    279290}
    280291