v.net.salesman.html 11.1 KB
Newer Older
xuebingbing's avatar
xuebingbing committed
1 2 3
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
xuebingbing's avatar
xuebingbing committed
4
<title>v.net.salesman - GRASS GIS manual</title>
xuebingbing's avatar
xuebingbing committed
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="grassdocs.css" type="text/css">
</head>
<body bgcolor="white">
<div id="container">

<a href="index.html"><img src="grass_logo.png" alt="GRASS logo"></a>
<hr class="header">

<h2>NAME</h2>
<em><b>v.net.salesman</b></em>  - Creates a cycle connecting given nodes (Traveling salesman problem).<BR>
Note that TSP is NP-hard, heuristic algorithm is used by this module and created cycle may be sub optimal
<h2>KEYWORDS</h2>
<a href="vector.html">vector</a>, <a href="topic_network.html">network</a>, <a href="keywords.html#salesman">salesman</a>
<h2>SYNOPSIS</h2>
<div id="name"><b>v.net.salesman</b><br></div>
<b>v.net.salesman --help</b><br>
<div id="synopsis"><b>v.net.salesman</b> [-<b>tg</b>] <b>input</b>=<em>name</em> <b>output</b>=<em>name</em> <b>center_cats</b>=<em>range</em> <b>arc_layer</b>=<em>string</em> <b>arc_type</b>=<em>string</em>[,<i>string</i>,...] <b>node_layer</b>=<em>string</em>  [<b>arc_column</b>=<em>string</em>]   [<b>arc_backward_column</b>=<em>string</em>]   [<b>turn_layer</b>=<em>string</em>]   [<b>turn_cat_layer</b>=<em>string</em>]   [<b>sequence</b>=<em>name</em>]   [--<b>overwrite</b>]  [--<b>help</b>]  [--<b>verbose</b>]  [--<b>quiet</b>]  [--<b>ui</b>] 
</div>

<div id="flags">
<h3>Flags:</h3>
<dl>
<dt><b>-t</b></dt>
<dd>Use turntable</dd>

<dt><b>-g</b></dt>
<dd>Use geodesic calculation for longitude-latitude locations</dd>

<dt><b>--overwrite</b></dt>
<dd>Allow output files to overwrite existing files</dd>
<dt><b>--help</b></dt>
<dd>Print usage summary</dd>
<dt><b>--verbose</b></dt>
<dd>Verbose module output</dd>
<dt><b>--quiet</b></dt>
<dd>Quiet module output</dd>
<dt><b>--ui</b></dt>
<dd>Force launching GUI dialog</dd>
</dl>
</div>

<div id="parameters">
<h3>Parameters:</h3>
<dl>
<dt><b>input</b>=<em>name</em>&nbsp;<b>[required]</b></dt>
<dd>Name of input vector map</dd>
<dd>Or data source for direct OGR access</dd>

<dt><b>output</b>=<em>name</em>&nbsp;<b>[required]</b></dt>
<dd>Name for output vector map</dd>

<dt><b>center_cats</b>=<em>range</em>&nbsp;<b>[required]</b></dt>
<dd>Category values</dd>
<dd>Categories of points ('cities') on nodes (layer is specified by nlayer)</dd>

<dt><b>arc_layer</b>=<em>string</em>&nbsp;<b>[required]</b></dt>
<dd>Arc layer</dd>
<dd>Vector features can have category values in different layers. This number determines which layer to use. When used with direct OGR access this is the layer name.</dd>
<dd>Default: <em>1</em></dd>

<dt><b>arc_type</b>=<em>string[,<i>string</i>,...]</em>&nbsp;<b>[required]</b></dt>
<dd>Arc type</dd>
<dd>Input feature type</dd>
<dd>Options: <em>line, boundary</em></dd>
<dd>Default: <em>line,boundary</em></dd>

<dt><b>node_layer</b>=<em>string</em>&nbsp;<b>[required]</b></dt>
<dd>Node layer (used for cities)</dd>
<dd>Vector features can have category values in different layers. This number determines which layer to use. When used with direct OGR access this is the layer name.</dd>
<dd>Default: <em>2</em></dd>

<dt><b>arc_column</b>=<em>string</em></dt>
<dd>Arc forward/both direction(s) cost column (number)</dd>

<dt><b>arc_backward_column</b>=<em>string</em></dt>
<dd>EXPERIMENTAL: Arc backward direction cost column (number)</dd>

<dt><b>turn_layer</b>=<em>string</em></dt>
<dd>Layer with turntable</dd>
<dd>Relevant only with -t flag</dd>
<dd>Default: <em>3</em></dd>

<dt><b>turn_cat_layer</b>=<em>string</em></dt>
<dd>Layer with unique categories used in turntable</dd>
<dd>Relevant only with -t flag</dd>
<dd>Default: <em>4</em></dd>

<dt><b>sequence</b>=<em>name</em></dt>
<dd>Name for output file holding node sequence ("-" for stdout)</dd>

</dl>
</div>
<div class="toc">
<h4 class="toc">Table of contents</h4>
<ul class="toc">
    <li class="toc"><a href="#description" class="toc">DESCRIPTION</a></li>
    <li class="toc"><a href="#notes" class="toc">NOTES</a></li>
    <li class="toc"><a href="#example" class="toc">EXAMPLE</a></li>
    <li class="toc"><a href="#see-also" class="toc">SEE ALSO</a></li>
    <li class="toc"><a href="#author" class="toc">AUTHOR</a>
    <ul class="toc">
        <li class="toc"><a href="#turns-support" class="toc">TURNS SUPPORT</a></li>
</ul>
</div>
<h2><a name="description">DESCRIPTION</a></h2>

<em>v.net.salesman</em> calculates the optimal route to visit nodes on a
vector network.

<p>Costs may be either line lengths, or attributes saved in a database 
table. These attribute values are taken as costs of whole segments, not 
as costs to traverse a length unit (e.g. meter) of the segment. 
For example, if the speed limit is 100 km / h, the cost to traverse a 
10 km long road segment must be calculated as
<br>
length / speed = 10 km / (100 km/h) = 0.1 h.
<br>
Supported are cost assignments for arcs, 
and also different costs for both directions of a vector line. 
For areas, costs will be calculated along boundary lines.
<p>The input vector needs to be prepared with <em>v.net operation=connect</em> 
in order to connect points representing center nodes to the network.

<p>Points specified by category must be exactly on network nodes, and the 
input vector map needs to be prepared with <em>v.net operation=connect</em>.

<p>Application of flag <b>-t</b> enables a turntable support. 
This flag requires additional parameters <b>turn_layer</b> and <b>turn_cat_layer</b> 
that are otherwise ignored.
 The turntable allows 
to model e.g. traffic code, where some turns may be prohibited. 
This means that the input layer is expanded by 
turntable with costs of every possible turn on any possible node 
(intersection) in both directions. 
 Turntable can be created by 
 the <em><a href="v.net.html">v.net</a></em> module. 
For more information about turns in the vector network analyses see
<a href="http://grasswiki.osgeo.org/wiki/Turns_in_the_vector_network_analysis">wiki page</a>.

<h2><a name="notes">NOTES</a></h2>
Arcs can be closed using cost = -1. 
Turns support: The costs of turns on visiting nodes are not taken in account.

<h2><a name="example">EXAMPLE</a></h2>

Traveling salesman for 6 digitized nodes (Spearfish):

<p>Shortest path, along unimproved roads:
<p><img src="vnetsalesman.png" alt="v.net.salesman example using distance" border="1">

<p>Fastest path, along highways:
<p><img src="vnetsalesmantime.png" alt="v.net.salesman example using time" border="1">

<p>Searching for the shortest path using distance and the fastest path using 
traveling time according to the speed limits of different road types:

<div class="code"><pre>
# Spearfish

g.copy vect=roads,myroads

# we have 6 locations to visit on our trip
echo "1|601653.5|4922869.2|a
2|608284|4923776.6|b
3|601845|4914981.9|c
4|596270|4917456.3|d
5|593330.8|4924096.6|e
6|598005.5|4921439.2|f" | v.in.ascii in=- cat=1 x=2 y=3 out=centers col="cat integer, \
                         east double precision, north double precision, label varchar(43)"

# verify data preparation
v.db.select centers
v.category centers op=report
# type       count        min        max
# point          6          1          6


# create lines map connecting points to network (on layer 2)
v.net myroads points=centers out=myroads_net op=connect thresh=500
v.category myroads_net op=report
# Layer / table: 1 / myroads_net
# type       count        min        max
# line         837          1          5
#
# Layer: 2
# type       count        min        max
# point          6          1          5

# find the shortest path
v.net.salesman myroads_net center_cats=1-6 out=mysalesman_distance

# set up costs as traveling time

# create unique categories for each road in layer 3
v.category in=myroads_net out=myroads_net_time opt=add cat=1 layer=3 type=line

# add new table for layer 3
v.db.addtable myroads_net_time layer=3 col="cat integer,label varchar(43),length double precision,speed double precision,cost double precision,bcost double precision"

# copy road type to layer 3
v.to.db myroads_net_time layer=3 qlayer=1 opt=query qcolumn=label columns=label

# upload road length in miles
v.to.db myroads_net_time layer=3 type=line option=length col=length unit=miles

# set speed limits in miles / hour
v.db.update myroads_net_time layer=3 col=speed val="5.0"
v.db.update myroads_net_time layer=3 col=speed val="75.0" where="label='interstate'"
v.db.update myroads_net_time layer=3 col=speed val="75.0" where="label='primary highway, hard surface'"
v.db.update myroads_net_time layer=3 col=speed val="50.0" where="label='secondary highway, hard surface'"
v.db.update myroads_net_time layer=3 col=speed val="25.0" where="label='light-duty road, improved surface'"
v.db.update myroads_net_time layer=3 col=speed val="5.0" where="label='unimproved road'"

# define traveling costs as traveling time in minutes:

# set forward costs
v.db.update myroads_net_time layer=3 col=cost val="length / speed * 60"
# set backward costs
v.db.update myroads_net_time layer=3 col=bcost val="length / speed * 60"

# find the fastest path
v.net.salesman myroads_net_time arc_layer=3 node_layer=2 arc_column=cost arc_backward_column=bcost center_cats=1-6 out=mysalesman_time
</pre></div>

To display the result, run for example:

<div class="code"><pre>
# Display the results
g.region vector=myroads_net

# shortest path
d.mon x0
d.vect myroads_net
d.vect centers -c icon=basic/triangle
d.vect mysalesman_distance col=green width=2
d.font Vera
d.vect centers col=red disp=attr attrcol=label lsize=12

# fastest path
d.mon x1
d.vect myroads_net
d.vect centers -c icon=basic/triangle
d.vect mysalesman_time col=green width=2
d.font Vera
d.vect centers col=red disp=attr attrcol=label lsize=12
</pre></div>


<h2><a name="see-also">SEE ALSO</a></h2>

<em><a href="d.path.html">d.path</a></em>,
<em><a href="v.net.html">v.net</a></em>,
<em><a href="v.net.alloc.html">v.net.alloc</a></em>,
<em><a href="v.net.iso.html">v.net.iso</a></em>,
<em><a href="v.net.path.html">v.net.path</a></em>,
<em><a href="v.net.steiner.html">v.net.steiner</a></em>

<h2><a name="author">AUTHOR</a></h2>

Radim Blazek, ITC-Irst, Trento, Italy<br>
Markus Metz<br>
Documentation: Markus Neteler, Markus Metz

<h3><a name="turns-support">TURNS SUPPORT</a></h3>

The turns support was implemnented as part of GRASS GIS turns cost project at Czech Technical University in Prague, Czech Republic.  
Eliska Kyzlikova, Stepan Turek, Lukas Bocan and Viera Bejdova participated at the project.

Implementation: Stepan Turek 
Documentation: Lukas Bocan
Mentor: Martin Landa

<!--
<p>
<i>Last changed: $Date$</i>
--><h2>SOURCE CODE</h2>
<p>Available at: <a href="https://github.com/OSGeo/grass/tree/master/vector/v.net.salesman">v.net.salesman source code</a> (<a href="https://github.com/OSGeo/grass/commits/master/vector/v.net.salesman">history</a>)</p>
<hr class="header">
<p>
<a href="index.html">Main index</a> |
<a href="vector.html">Vector index</a> |
<a href="topics.html">Topics index</a> |
<a href="keywords.html">Keywords index</a> |
<a href="graphical_index.html">Graphical index</a> |
<a href="full_index.html">Full index</a>
</p>
<p>
xuebingbing's avatar
xuebingbing committed
293
&copy; 2003-2020
xuebingbing's avatar
xuebingbing committed
294
<a href="http://grass.osgeo.org">GRASS Development Team</a>,
xuebingbing's avatar
xuebingbing committed
295
GRASS GIS 7.8.3 Reference Manual
xuebingbing's avatar
xuebingbing committed
296 297 298 299 300
</p>

</div>
</body>
</html>