.TH v.net.salesman 1grass "" "GRASS 7.8.5" "GRASS GIS User's Manual" .SH NAME \fI\fBv.net.salesman\fR\fR \- 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 .SH KEYWORDS vector, network, salesman .SH SYNOPSIS \fBv.net.salesman\fR .br \fBv.net.salesman \-\-help\fR .br \fBv.net.salesman\fR [\-\fBtg\fR] \fBinput\fR=\fIname\fR \fBoutput\fR=\fIname\fR \fBcenter_cats\fR=\fIrange\fR \fBarc_layer\fR=\fIstring\fR \fBarc_type\fR=\fIstring\fR[,\fIstring\fR,...] \fBnode_layer\fR=\fIstring\fR [\fBarc_column\fR=\fIstring\fR] [\fBarc_backward_column\fR=\fIstring\fR] [\fBturn_layer\fR=\fIstring\fR] [\fBturn_cat_layer\fR=\fIstring\fR] [\fBsequence\fR=\fIname\fR] [\-\-\fBoverwrite\fR] [\-\-\fBhelp\fR] [\-\-\fBverbose\fR] [\-\-\fBquiet\fR] [\-\-\fBui\fR] .SS Flags: .IP "\fB\-t\fR" 4m .br Use turntable .IP "\fB\-g\fR" 4m .br Use geodesic calculation for longitude\-latitude locations .IP "\fB\-\-overwrite\fR" 4m .br Allow output files to overwrite existing files .IP "\fB\-\-help\fR" 4m .br Print usage summary .IP "\fB\-\-verbose\fR" 4m .br Verbose module output .IP "\fB\-\-quiet\fR" 4m .br Quiet module output .IP "\fB\-\-ui\fR" 4m .br Force launching GUI dialog .SS Parameters: .IP "\fBinput\fR=\fIname\fR \fB[required]\fR" 4m .br Name of input vector map .br Or data source for direct OGR access .IP "\fBoutput\fR=\fIname\fR \fB[required]\fR" 4m .br Name for output vector map .IP "\fBcenter_cats\fR=\fIrange\fR \fB[required]\fR" 4m .br Category values .br Categories of points (\(cqcities\(cq) on nodes (layer is specified by nlayer) .IP "\fBarc_layer\fR=\fIstring\fR \fB[required]\fR" 4m .br Arc layer .br 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. .br Default: \fI1\fR .IP "\fBarc_type\fR=\fIstring[,\fIstring\fR,...]\fR \fB[required]\fR" 4m .br Arc type .br Input feature type .br Options: \fIline, boundary\fR .br Default: \fIline,boundary\fR .IP "\fBnode_layer\fR=\fIstring\fR \fB[required]\fR" 4m .br Node layer (used for cities) .br 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. .br Default: \fI2\fR .IP "\fBarc_column\fR=\fIstring\fR" 4m .br Arc forward/both direction(s) cost column (number) .IP "\fBarc_backward_column\fR=\fIstring\fR" 4m .br EXPERIMENTAL: Arc backward direction cost column (number) .IP "\fBturn_layer\fR=\fIstring\fR" 4m .br Layer with turntable .br Relevant only with \-t flag .br Default: \fI3\fR .IP "\fBturn_cat_layer\fR=\fIstring\fR" 4m .br Layer with unique categories used in turntable .br Relevant only with \-t flag .br Default: \fI4\fR .IP "\fBsequence\fR=\fIname\fR" 4m .br Name for output file holding node sequence (\(dq\-\(dq for stdout) .SH DESCRIPTION \fIv.net.salesman\fR calculates the optimal route to visit nodes on a vector network. .PP 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. .PP The input vector needs to be prepared with \fIv.net operation=connect\fR in order to connect points representing center nodes to the network. .PP Points specified by category must be exactly on network nodes, and the input vector map needs to be prepared with \fIv.net operation=connect\fR. .PP Application of flag \fB\-t\fR enables a turntable support. This flag requires additional parameters \fBturn_layer\fR and \fBturn_cat_layer\fR 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 \fIv.net\fR module. For more information about turns in the vector network analyses see wiki page. .SH NOTES Arcs can be closed using cost = \-1. Turns support: The costs of turns on visiting nodes are not taken in account. .SH EXAMPLE Traveling salesman for 6 digitized nodes (Spearfish): .PP Shortest path, along unimproved roads: .PP .PP Fastest path, along highways: .PP .PP Searching for the shortest path using distance and the fastest path using traveling time according to the speed limits of different road types: .br .nf \fC # Spearfish g.copy vect=roads,myroads # we have 6 locations to visit on our trip echo \(dq1|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\(dq | v.in.ascii in=\- cat=1 x=2 y=3 out=centers col=\(dqcat integer, \(rs east double precision, north double precision, label varchar(43)\(dq # 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=\(dqcat integer,label varchar(43),length double precision,speed double precision,cost double precision,bcost double precision\(dq # 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=\(dq5.0\(dq v.db.update myroads_net_time layer=3 col=speed val=\(dq75.0\(dq where=\(dqlabel=\(cqinterstate\(cq\(dq v.db.update myroads_net_time layer=3 col=speed val=\(dq75.0\(dq where=\(dqlabel=\(cqprimary highway, hard surface\(cq\(dq v.db.update myroads_net_time layer=3 col=speed val=\(dq50.0\(dq where=\(dqlabel=\(cqsecondary highway, hard surface\(cq\(dq v.db.update myroads_net_time layer=3 col=speed val=\(dq25.0\(dq where=\(dqlabel=\(cqlight\-duty road, improved surface\(cq\(dq v.db.update myroads_net_time layer=3 col=speed val=\(dq5.0\(dq where=\(dqlabel=\(cqunimproved road\(cq\(dq # define traveling costs as traveling time in minutes: # set forward costs v.db.update myroads_net_time layer=3 col=cost val=\(dqlength / speed * 60\(dq # set backward costs v.db.update myroads_net_time layer=3 col=bcost val=\(dqlength / speed * 60\(dq # 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 \fR .fi To display the result, run for example: .br .nf \fC # 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 \fR .fi .SH SEE ALSO \fId.path\fR, \fIv.net\fR, \fIv.net.alloc\fR, \fIv.net.iso\fR, \fIv.net.path\fR, \fIv.net.steiner\fR .SH AUTHOR Radim Blazek, ITC\-Irst, Trento, Italy .br Markus Metz .br Documentation: Markus Neteler, Markus Metz .SS TURNS SUPPORT 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 .SH SOURCE CODE .PP Available at: v.net.salesman source code (history) .PP Main index | Vector index | Topics index | Keywords index | Graphical index | Full index .PP © 2003\-2020 GRASS Development Team, GRASS GIS 7.8.5 Reference Manual