v.net.salesman(1grass)
β¨ v.net.salesman β¨
okay so bestie, welcome to v.net.salesman from the GRASS User's Manual π this one creates a cycle connecting given nodes β which is literally the Traveling salesman problem ππ¨
no cap, TSP is NP-hard π so this module uses a heuristic algorithm, and that means the cycle it makes may be sub optimal. not a bug, just vibes. it's giving "good enough, queen" π
KEYWORDS: vector, network, salesman π¦
πΈ SYNOPSIS πΈ
v.net.salesman
v.net.salesman --help
v.net.salesman [-tg] input=name output=name center_cats=range
arc_layer=string arc_type=string[,string,...] node_layer=string
[arc_column=string] [arc_backward_column=string] [turn_layer=string]
[turn_cat_layer=string] [sequence=name] [--overwrite] [--help]
[--verbose] [--quiet] [--ui]
π Flags
-tβ Use turntable-gβ Use geodesic calculation for longitude-latitude projects--overwriteβ Allow output files to overwrite existing files--helpβ Print usage summary--verboseβ Verbose module output--quietβ Quiet module output--uiβ Force launching GUI dialog
π«Ά Parameters
input=name[required] β Name of input vector map. Or data source for direct OGR access.output=name[required] β Name for output vector mapcenter_cats=range[required] β Category values. Categories of points (βcitiesβ) on nodes (layer is specified bynlayer).arc_layer=string[required] β Arc layer. 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. Default:1arc_type=string[,string,...][required] β Arc type. Input feature type. Options:line,boundary. Default:line,boundarynode_layer=string[required] β Node layer (used for cities). 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. Default:2arc_column=stringβ Arc forward/both direction(s) cost column (number)arc_backward_column=stringβ EXPERIMENTAL: Arc backward direction cost column (number)turn_layer=stringβ Layer with turntable. Relevant only with-tflag. Default:3turn_cat_layer=stringβ Layer with unique categories used in turntable. Relevant only with-tflag. Default:4sequence=nameβ Name for output file holding node sequence ("-"for stdout)
π DESCRIPTION π
v.net.salesman calculates the optimal route to visit nodes on a vector network. obsessed. π₯
Costs may be either line lengths or attributes saved in a database table. Heads up though: these attribute values are taken as costs of whole segments, NOT as costs to traverse a length unit (e.g. meter) of the segment. So like, if the speed limit is 100 km / h, the cost to traverse a 10 km long road segment must be calculated as
length / speed = 10 km / (100 km/h) = 0.1 h.
no shortcuts, bestie, do the math π
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.
The input vector needs to be prepared with v.net operation=connect in order to connect points representing center nodes to the network.
Points specified by category must be exactly on network nodes, and the input vector map needs to be prepared with v.net operation=connect. fr fr, exactly on the nodes. π
The flag -t enables turntable support. This flag requires additional parameters, turn_layer and turn_cat_layer, 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 v.net module. For more information about turns in the vector network analyses see wiki page. π§
β NOTES β
Arcs can be closed using cost = -1. π
Turns support: The costs of turns on visiting nodes are not taken in account.
π₯ EXAMPLE π₯
Traveling salesman for 6 digitized nodes (Spearfish):
Shortest path, along unimproved roads:
Fastest path, along highways:
Searching for the shortest path using distance and the fastest path using traveling time according to the speed limits of different road types:
# 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
To display the result, run for example:
# 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
π¦ SEE ALSO π¦
d.path, v.net, v.net.alloc, v.net.iso, v.net.path, v.net.steiner
π AUTHORS π
- Radim Blazek, ITC-Irst, Trento, Italy
- Markus Metz
- Documentation: Markus Neteler, Markus Metz
π TURNS SUPPORT
The turns support was implemented 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 in the project.
- Implementation: Stepan Turek
- Documentation: Lukas Bocan
- Mentor: Martin Landa
π SOURCE CODE π
Available at: v.net.salesman source code (history)
Latest change: Thursday Feb 13 14:10:24 2025 in commit: c0fe7d746d0e4b334ec160652469b3ced51e03b2
Main index | Vector index | Topics index | Keywords index | Graphical index | Full index
Β© 2003-2026 GRASS Development Team, GRASS 8.5.0 Reference Manual
okay that's the whole thing bestie, you ate that π«Ά this was GRASS 8.5.0, last touched Thursday Feb 13 14:10:24 2025, and the whole saga lives under v.net.salesman(1grass) πβ¨ no cap, go close some cycles. π
π¦ where this page comes from
- alpine 3.24: grass-gis-doc 8.5.0-r1 Β· GPL-2.0-or-later
- ubuntu stonking: grass-doc 8.5.0-1ubuntu1 Β· GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms