Skip to content

Commit b183b27

Browse files
authored
Rename network movement types (#181)
* Rename travel to walk. * Rename snap to jump. * Rename step to teleport. * Rename network_type to network_movement.
1 parent 3dc7f61 commit b183b27

File tree

5 files changed

+49
-48
lines changed

5 files changed

+49
-48
lines changed

include/pops/anthropogenic_kernel.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ std::unique_ptr<KernelInterface<Generator>> create_anthro_kernel(
5959
else if (anthro_kernel == DispersalKernelType::Network) {
6060
using Kernel =
6161
DynamicWrapperKernel<NetworkDispersalKernel<RasterIndex>, Generator>;
62-
if (config.network_type == "step")
62+
if (config.network_movement == "teleport")
6363
return std::unique_ptr<Kernel>(new Kernel(network));
64-
bool snap = config.network_type == "snap" ? true : false;
64+
bool jump = config.network_movement == "jump" ? true : false;
6565
return std::unique_ptr<Kernel>(new Kernel(
66-
network, config.network_min_distance, config.network_max_distance, snap));
66+
network, config.network_min_distance, config.network_max_distance, jump));
6767
}
6868
else if (config.deterministic) {
6969
using Kernel = DynamicWrapperKernel<

include/pops/config.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class Config
7171
std::string anthro_kernel_type;
7272
double anthro_scale{0};
7373
std::string anthro_direction;
74-
std::string network_type; ///< travel, snap, step
74+
std::string network_movement; ///< walk, jump, teleport
7575
double network_min_distance{0};
7676
double network_max_distance{0};
7777
double anthro_kappa{0};

include/pops/network.hpp

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -157,16 +157,16 @@ class EdgeGeometryView : public ContainerView<EdgeGeomertyType>
157157
* The network consists of nodes connected by edges. Edges are spatially represented
158158
* as segments. Edges themselves don't carry cost and have meaning only as indicators of
159159
* existence of a connection between nodes. Cost for each edge is a travel distance
160-
* determined by advancing through cells in a segment.
160+
* (cost) determined by advancing through all cells in a segment.
161161
*
162162
* Nodes are the hop-on locations for dispersers. The dispersers can hop-off anywhere.
163163
*
164164
* The general workflow is contructing the object (with the constructor) and loading the
165165
* data (with the load() function). Then the network is ready to be used for simulating
166-
* trips over the network (with the travel() function).
166+
* trips over the network (with the walk() or teleport() functions).
167167
*
168-
* When the travel() function is used from a kernel, user of the network directly calls
169-
* only the setup functions.
168+
* When the walk() or teleport() functions are used from a kernel, user of the network
169+
* directly calls only the setup functions.
170170
*
171171
* The class exposes number of functions as public which are meant for testing or other
172172
* special workflows.
@@ -449,7 +449,7 @@ class Network
449449
}
450450

451451
/**
452-
* Travel given distance in the network from given row and column.
452+
* Walk a given distance (cost) in the network from given row and column.
453453
*
454454
* All previously visited nodes are tracked and, if possible, excluded
455455
* from further traveling.
@@ -458,20 +458,20 @@ class Network
458458
* the decision to call this function was based on the caller knowing there is a
459459
* node. If there is no node, an std::invalid_argument exception is thrown.
460460
* If there is more than one node at the given *row* and *column*, a random node is
461-
* picked and used for traveling.
461+
* picked and used as a next walking destination.
462462
*
463-
* If *snap* is true, then results are snapped to the closest node, otherwise
463+
* If *jump* is true, then results are snapped to the closest node, otherwise
464464
* result can be anywhere in between the nodes based on the edge geomerty (segment).
465465
*
466466
* @returns Final row and column pair
467467
*/
468468
template<typename Generator>
469-
std::tuple<int, int> travel(
469+
std::tuple<int, int> walk(
470470
RasterIndex row,
471471
RasterIndex col,
472472
double distance,
473473
Generator& generator,
474-
bool snap = false) const
474+
bool jump = false) const
475475
{
476476
auto node_id = get_random_node_at(row, col, generator);
477477
std::set<NodeId> visited_nodes;
@@ -494,26 +494,27 @@ class Network
494494
distance -= segment.cost();
495495
continue;
496496
}
497-
if (snap) {
497+
if (jump) {
498498
if (distance < segment.cost() / 2) {
499499
// Less than half snaps to the start node.
500500
return segment.front();
501501
}
502502
// Half or more snaps to the end node.
503503
return segment.back();
504504
}
505-
// No snapping, advance in a segment.
505+
// No jumping (snapping), advance in a segment.
506506
// This includes the special cases when distance is 0 or total segment cost.
507507
return segment.cell_by_cost(distance);
508508
}
509509
throw std::invalid_argument("Distance must be greater than or equal to zero");
510510
}
511511

512512
/**
513-
* Step to a different node in the network from given row and column.
513+
* Teleport to a different node in the network from given row and column.
514514
*
515515
* Returns any node of the nodes connected to the start node possibly based on the
516-
* edge probability if probability was assigned to the edges.
516+
* edge probability if probability was assigned to the edges without considering
517+
* cost to travel from one node to the next one.
517518
*
518519
* If *num_steps* is greater than 1, multiple steps are perfomed and the last node
519520
* is returned. In each node, the probability of picking a specific connection is
@@ -526,12 +527,12 @@ class Network
526527
* was either checked beforehand or otherwise ensured. If there is no node, an
527528
* std::invalid_argument exception is thrown.
528529
* If there is more than one node at the given *row* and *column*, a random node is
529-
* picked and used for traveling.
530+
* picked and used.
530531
*
531532
* @returns Destination row and column pair
532533
*/
533534
template<typename Generator>
534-
std::tuple<int, int> step(
535+
std::tuple<int, int> teleport(
535536
RasterIndex row, RasterIndex col, Generator& generator, int num_steps = 1) const
536537
{
537538
auto node_id = get_random_node_at(row, col, generator);
@@ -1092,7 +1093,7 @@ class Network
10921093
double ns_res_; ///< North-south resolution of the grid
10931094
RasterIndex max_row_; ///< Maximum row index in the grid
10941095
RasterIndex max_col_; ///< Maximum column index in the grid
1095-
double distance_per_cell_; ///< Distance to travel through one cell (cost)
1096+
double distance_per_cell_; ///< Distance (cost) to walk through one cell
10961097
/** Node IDs stored by row and column (multiple nodes per cell) */
10971098
std::map<std::pair<RasterIndex, RasterIndex>, std::set<NodeId>> nodes_by_row_col_;
10981099
NodeMatrix node_matrix_; ///< List of node neighbors by node ID (edges)

include/pops/network_kernel.hpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,39 +33,39 @@ class NetworkDispersalKernel
3333
{
3434
public:
3535
/**
36-
* @brief Create kernel which travels through the network including edges.
36+
* @brief Create kernel which travels through a network.
3737
*
3838
* The kernel assumes that the *network* is already initialized. It does not modify
3939
* the network.
4040
*
4141
* The *min_distance* and *max_distance* parameters are used as a range for uniform
42-
* real distribution which determines the travel distance through the network for
43-
* one trip.
42+
* real distribution which determines the travel distance (cost) through the network
43+
* for one trip if the network movement is walking (and not teleporting).
4444
*
4545
* @param network Existing network
46-
* @param min_distance Minimum travel distance
47-
* @param max_distance Maximum travel distance
48-
* @param snap Snap result to the closest node
46+
* @param min_distance Minimum travel distance (cost)
47+
* @param max_distance Maximum travel distance (cost)
48+
* @param jump End always on a node (snaps result to the closest node)
4949
*/
5050
NetworkDispersalKernel(
5151
const Network<RasterIndex>& network,
5252
double min_distance,
5353
double max_distance,
54-
bool snap = false)
54+
bool jump = false)
5555
: network_(network),
5656
distance_distribution_(min_distance, max_distance),
57-
snap_(snap)
57+
jump_(jump)
5858
{}
5959
/**
60-
* @brief Create kernel which steps from one node to another.
60+
* @brief Create kernel which teleports from one node to another.
6161
*
6262
* The kernel assumes that the *network* is already initialized. It does not modify
6363
* the network.
6464
*
6565
* @param network Existing network
6666
*/
6767
NetworkDispersalKernel(const Network<RasterIndex>& network)
68-
: network_(network), step_{true}
68+
: network_(network), teleport_{true}
6969
{}
7070

7171
/*! \copybrief RadialDispersalKernel::operator()()
@@ -76,11 +76,11 @@ class NetworkDispersalKernel
7676
template<typename Generator>
7777
std::tuple<int, int> operator()(Generator& generator, int row, int col)
7878
{
79-
if (step_) {
80-
return network_.step(row, col, generator);
79+
if (teleport_) {
80+
return network_.teleport(row, col, generator);
8181
}
8282
double distance = distance_distribution_(generator);
83-
std::tie(row, col) = network_.travel(row, col, distance, generator);
83+
std::tie(row, col) = network_.walk(row, col, distance, generator);
8484

8585
return std::make_tuple(row, col);
8686
}
@@ -107,12 +107,12 @@ class NetworkDispersalKernel
107107
protected:
108108
/** Reference to the network */
109109
const Network<RasterIndex>& network_;
110-
/** Travel distance distribution */
110+
/** Travel distance (cost) distribution */
111111
std::uniform_real_distribution<double> distance_distribution_;
112112
/** Step through network instead of traveling between nodes */
113-
bool step_{false};
113+
bool teleport_{false};
114114
/** Snap to nodes when traveling between nodes */
115-
bool snap_{false};
115+
bool jump_{false};
116116
};
117117

118118
} // namespace pops

tests/test_network.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ int test_bbox_functions()
9999
return ret;
100100
}
101101

102-
int test_travel_network()
102+
int test_walk_network()
103103
{
104104
int ret = 0;
105105
BBox<double> bbox;
@@ -152,7 +152,7 @@ int test_travel_network()
152152
int end_row;
153153
int end_col;
154154
std::tie(end_row, end_col) =
155-
network.travel(start_row, start_col, distance, generator);
155+
network.walk(start_row, start_col, distance, generator);
156156
if (correct->first != end_row || correct->second != end_col) {
157157
std::cerr << "from (" << start_row << ", " << start_col << ") to ("
158158
<< end_row << ", " << end_col << ") in " << distance
@@ -169,7 +169,7 @@ int test_travel_network()
169169
return ret;
170170
}
171171

172-
int test_snap_network()
172+
int test_jump_network()
173173
{
174174
int ret = 0;
175175
BBox<double> bbox;
@@ -204,7 +204,7 @@ int test_snap_network()
204204
}
205205
int end_row;
206206
int end_col;
207-
std::tie(end_row, end_col) = network.travel(
207+
std::tie(end_row, end_col) = network.walk(
208208
start_row, start_col, std::get<0>(destination), generator, true);
209209
if (std::get<1>(destination) != end_row
210210
|| std::get<2>(destination) != end_col) {
@@ -264,7 +264,7 @@ int test_cost_network()
264264
int end_row;
265265
int end_col;
266266
std::tie(end_row, end_col) =
267-
network.travel(start_row, start_col, std::get<0>(destination), generator);
267+
network.walk(start_row, start_col, std::get<0>(destination), generator);
268268
if (std::get<1>(destination) != end_row
269269
|| std::get<2>(destination) != end_col) {
270270
std::cerr << "from (" << start_row << ", " << start_col << ") to ("
@@ -463,7 +463,7 @@ int test_network_probability_last()
463463
return 0;
464464
}
465465

466-
int test_step_network()
466+
int test_teleport_network()
467467
{
468468
int ret = 0;
469469
BBox<double> bbox;
@@ -499,7 +499,7 @@ int test_step_network()
499499
int end_row;
500500
int end_col;
501501
std::tie(end_row, end_col) =
502-
network.step(start_row, start_col, generator, std::get<0>(destination));
502+
network.teleport(start_row, start_col, generator, std::get<0>(destination));
503503
if (std::get<1>(destination) != end_row
504504
|| std::get<2>(destination) != end_col) {
505505
std::cerr << "from (" << start_row << ", " << start_col << ") to ("
@@ -761,7 +761,7 @@ int create_network_from_files(int argc, char** argv)
761761
if (trips || trace) {
762762
double min_distance = config.get("min_distance", 1.);
763763
double max_distance = config.get("max_distance", 1.);
764-
bool snap = config.get("snap", false);
764+
bool jump = config.get("jump", false);
765765
double distance_increment = config.get("distance_increment", 1.);
766766
int seed = config.get("seed", 1);
767767
std::default_random_engine generator;
@@ -794,7 +794,7 @@ int create_network_from_files(int argc, char** argv)
794794
int end_row;
795795
int end_col;
796796
std::tie(end_row, end_col) =
797-
network.travel(start_row, start_col, distance, generator, snap);
797+
network.walk(start_row, start_col, distance, generator, jump);
798798
trips.emplace_back(end_row, end_col, distance);
799799
}
800800
if (trace) {
@@ -840,10 +840,10 @@ int run_tests()
840840

841841
ret += test_bbox_functions();
842842
ret += test_create_network();
843-
ret += test_travel_network();
844-
ret += test_snap_network();
843+
ret += test_walk_network();
844+
ret += test_jump_network();
845845
ret += test_cost_network();
846-
ret += test_step_network();
846+
ret += test_teleport_network();
847847
ret += test_network_probability_0_100();
848848
ret += test_network_probability_0_1();
849849
ret += test_network_negative_probability();

0 commit comments

Comments
 (0)