direct_dist_path_obj_test.py
Go to the documentation of this file.
1 #==============================================================================
2 # Copyright (C) 2021-2024 Wageningen University - All Rights Reserved
3 # Author: Gonzalo Mier
4 # BSD-3 License
5 #==============================================================================
6 
7 import pytest
8 import fields2cover as f2c
9 
10 def near(a, b, error = 1e-7):
11  assert abs(a - b) < error
12 
13 
15  swath1 = f2c.Swath(f2c.LineString(f2c.VectorPoint(
16  [f2c.Point(0.0, 1.0), f2c.Point(4.0, 1.0)])));
17  swath2 = f2c.Swath(f2c.LineString(f2c.VectorPoint(
18  [f2c.Point(4.0, 3.0), f2c.Point(0.0, 3.0)])));
19  swath3 = f2c.Swath(f2c.LineString(f2c.VectorPoint(
20  [f2c.Point(0.0, 0.0), f2c.Point(1.0, 1.0)])));
21 
22  def createRoute(s):
23  route = f2c.Route();
24  route.addConnection();
25  route.addSwaths(s);
26  route.addConnection();
27  return route;
28 
29  swaths1 = f2c.Swaths();
30  [swaths1.push_back(i) for i in [swath1]]
31  swaths2 = f2c.Swaths();
32  [swaths2.push_back(i) for i in [swath2]]
33  swaths4 = f2c.Swaths();
34  [swaths4.push_back(i) for i in [swath1, swath2, swath1, swath2]]
35 
36  r1 = createRoute(swaths1);
37  r2 = createRoute(swaths2);
38  r4 = createRoute(swaths4);
39 
40  length = f2c.OBJ_DirectDistPathObj();
41 
42  p1 = f2c.Point(0, 0);
43  p2 = f2c.Point(4, 0);
44 
45  near(length.computeCost(p1, p2), 4.0);
46 
47  ps1 = f2c.VectorPoint([p1, p2]);
48  ps2 = f2c.MultiPoint();
49  ps2.addGeometry(p1);
50  ps2.addGeometry(p2);
51 
52  near(length.computeCost(ps1), 4.0);
53  near(length.computeCost(ps2), 4.0);
54  near(length.computeCost(p1, p2, 0.0), 4.0);
55  near(length.computeCost(p1, 0.0, p2), 4.0);
56  near(length.computeCost(p1, 0.0, p2, 0.0), 4.0);
57  near(length.computeCost(p1, swath2), 5.0);
58  near(length.computeCost(swath2, p1), 3.0);
59  near(length.computeCost(p1, 0.0, swath2), 5.0);
60  near(length.computeCost(swath2, p1, 0.0), 3.0);
61 
62  near(length.computeCost(swath2, ps2), 3.0);
63  near(length.computeCost(swaths2, ps2), 3.0);
64  near(length.computeCost(ps2, swath2), 3.0);
65  near(length.computeCost(ps2, swaths2), 3.0);
66 
67  near(length.computeCost(swath2), 4.0);
68  near(length.computeCost(swaths4), 22.0);
69 
70  near(length.computeCost(f2c.MultiPoint(), swath2), 0.0);
71  near(length.computeCost(swath2, f2c.MultiPoint()), 0.0);
72 
73  near(length.computeCost(r1), 4.0);
74  near(length.computeCostWithMinimizingSign(r1), length.computeCost(r1));
75  near(length.computeCost(r2), 4.0);
76  near(length.computeCostWithMinimizingSign(r2), length.computeCost(r2));
77  near(length.computeCost(r4), 22.0);
78  near(length.computeCostWithMinimizingSign(r4), length.computeCost(r4));
79 
81  objective = f2c.OBJ_DirectDistPathObj();
82 
83  assert not (objective.isMaximizing());
84  assert (objective.isMinimizing());
85 
direct_dist_path_obj_test.test_fields2cover_obj_direct_dist_path_obj_computeCost
def test_fields2cover_obj_direct_dist_path_obj_computeCost()
Definition: direct_dist_path_obj_test.py:14
direct_dist_path_obj_test.test_fields2cover_obj_direct_dist_path_obj_paramsCheck
def test_fields2cover_obj_direct_dist_path_obj_paramsCheck()
Definition: direct_dist_path_obj_test.py:80
direct_dist_path_obj_test.near
def near(a, b, error=1e-7)
Definition: direct_dist_path_obj_test.py:10


fields2cover
Author(s):
autogenerated on Fri Apr 25 2025 02:18:31