.TH v.net.salesman 1grass "" "GRASS 6.4.4" "Grass 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 [\-\fBg\fR] \fBinput\fR=\fIname\fR \fBoutput\fR=\fIname\fR [\fBtype\fR=\fIstring\fR[,\fIstring\fR,...]] [\fBalayer\fR=\fIinteger\fR] [\fBnlayer\fR=\fIinteger\fR] [\fBacolumn\fR=\fIstring\fR] \fBccats\fR=\fIrange\fR [\-\-\fBoverwrite\fR] [\-\-\fBverbose\fR] [\-\-\fBquiet\fR] .SS Flags: .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\-\-verbose\fR" 4m .br Verbose module output .IP "\fB\-\-quiet\fR" 4m .br Quiet module output .PP .SS Parameters: .IP "\fBinput\fR=\fIname\fR" 4m .br Name of input vector map .IP "\fBoutput\fR=\fIname\fR" 4m .br Name for output vector map .IP "\fBtype\fR=\fIstring[,\fIstring\fR,...]\fR" 4m .br Arc type .br Options: \fIline,boundary\fR .br Default: \fIline,boundary\fR .IP "\fBalayer\fR=\fIinteger\fR" 4m .br Layer number .br Arc layer .br Default: \fI1\fR .IP "\fBnlayer\fR=\fIinteger\fR" 4m .br Layer number .br Node layer (used for cities) .br Default: \fI2\fR .IP "\fBacolumn\fR=\fIstring\fR" 4m .br Arcs' cost column (for both directions) .IP "\fBccats\fR=\fIrange\fR" 4m .br Category values .br Categories of points ('cities') on nodes (layer is specified by nlayer) .PP .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. .SH NOTES Arcs can be closed using cost = -1. .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: \fC .DS .br # Spearfish .br .br g.copy vect=roads,myroads .br .br # we have 6 locations to visit on our trip .br echo "1|601653.5|4922869.2|a .br 2|608284|4923776.6|b .br 3|601845|4914981.9|c .br 4|596270|4917456.3|d .br 5|593330.8|4924096.6|e .br 6|598005.5|4921439.2|f" | v.in.ascii in=- cat=1 x=2 y=3 out=centers col="cat integer, \(rs .br east double precision, north double precision, label varchar(43)" .br .br # verify data preparation .br v.db.select centers .br v.category centers op=report .br # type count min max .br # point 6 1 6 .br .br .br # create lines map connecting points to network (on layer 2) .br v.net myroads points=centers out=myroads_net op=connect thresh=500 .br v.category myroads_net op=report .br # Layer / table: 1 / myroads_net .br # type count min max .br # line 837 1 5 .br # .br # Layer: 2 .br # type count min max .br # point 6 1 5 .br .br # find the shortest path .br v.net.salesman myroads_net ccats=1-6 out=mysalesman_distance .br .br # set up costs as traveling time .br .br # create unique categories for each road in layer 3 .br v.category in=myroads_net out=myroads_net_time opt=add cat=1 layer=3 type=line .br .br # add new table for layer 3 .br v.db.addtable myroads_net_time layer=3 col="cat integer,label varchar(43),length double precision,speed double precision,cost double precision" .br .br # copy road type to layer 3 .br v.to.db myroads_net_time layer=3 qlayer=1 opt=query qcolumn=label columns=label .br .br # upload road length in miles .br v.to.db myroads_net_time layer=3 type=line option=length col=length unit=miles .br .br # set speed limits in miles / hour .br v.db.update myroads_net_time layer=3 col=speed val="5.0" .br v.db.update myroads_net_time layer=3 col=speed val="75.0" where="label='interstate'" .br v.db.update myroads_net_time layer=3 col=speed val="75.0" where="label='primary highway, hard surface'" .br v.db.update myroads_net_time layer=3 col=speed val="50.0" where="label='secondary highway, hard surface'" .br v.db.update myroads_net_time layer=3 col=speed val="25.0" where="label='light-duty road, improved surface'" .br v.db.update myroads_net_time layer=3 col=speed val="5.0" where="label='unimproved road'" .br .br # define traveling costs as traveling time in minutes: .br v.db.update myroads_net_time layer=3 col=cost val="length / speed * 60" .br .br # find the fastest path .br v.net.salesman myroads_net_time alayer=3 nlayer=2 acol=cost ccats=1-6 out=mysalesman_time .br .DE \fR To display the result, run for example: \fC .DS .br # Display the results .br g.region vect=myroads_net .br .br # shortest path .br d.mon x0 .br d.vect myroads_net .br d.vect centers \-c icon=basic/triangle .br d.vect mysalesman_distance col=green width=2 .br d.font Vera .br d.vect centers col=red disp=attr attrcol=label lsize=12 .br .br # fastest path .br d.mon x1 .br d.vect myroads_net .br d.vect centers \-c icon=basic/triangle .br d.vect mysalesman_time col=green width=2 .br d.font Vera .br d.vect centers col=red disp=attr attrcol=label lsize=12 .br .DE \fR .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 Documentation: Markus Neteler, Markus Metz .PP \fILast changed: $Date: 2013-05-23 22:01:55 +0200 (Thu, 23 May 2013) $\fR .PP Full index .PP © 2003-2014 GRASS Development Team