swath_length_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  path1 = f2c.LineString();
16  path2 = f2c.LineString();
17  path3 = f2c.LineString();
18  path1.addPoint( 0.0, 1.0);
19  path1.addPoint( 4.0, 1.0);
20  path2.addPoint( 0.0, 3.0);
21  path2.addPoint( 4.0, 3.0);
22  path3.addPoint( 0.0, 0.0);
23  path3.addPoint( 1.0, 1.0);
24  swath1 = f2c.Swath(path1);
25  swath2 = f2c.Swath(path2);
26  swath3 = f2c.Swath(path3);
27 
28  swaths1 = f2c.Swaths();
29  [swaths1.push_back(i) for i in [swath1]]
30  swaths2 = f2c.Swaths();
31  [swaths2.push_back(i) for i in [swath3]]
32  swaths3 = f2c.Swaths();
33  [swaths3.push_back(i) for i in [swath1, swath2]]
34  swaths4 = f2c.Swaths();
35  [swaths4.push_back(i) for i in [swath1, swath2, swath1, swath2]]
36 
37  length = f2c.OBJ_SwathLength();
38 
39 
40  near(length.computeCost(swath1), 4.0);
41 
42  near(length.computeCost(swaths1), 4.0);
43  near(length.computeCostWithMinimizingSign(swaths1), length.computeCost(swaths1));
44 
45  near(length.computeCost(swaths2)*length.computeCost(swaths2), 2.0, 0.001);
46  near(length.computeCostWithMinimizingSign(swaths2), length.computeCost(swaths2));
47 
48  near(length.computeCost(swaths3), 8.0);
49  near(length.computeCostWithMinimizingSign(swaths3), length.computeCost(swaths3));
50 
51  near(length.computeCost(swaths4), 16.0);
52  near(length.computeCostWithMinimizingSign(swaths4), length.computeCost(swaths4));
53 
55  objective = f2c.OBJ_SwathLength();
56 
57  assert not (objective.isMaximizing());
58  assert (objective.isMinimizing());
59 
swath_length_test.test_fields2cover_obj_swath_length_params_check
def test_fields2cover_obj_swath_length_params_check()
Definition: swath_length_test.py:54
swath_length_test.test_fields2cover_obj_swath_length_computeCost
def test_fields2cover_obj_swath_length_computeCost()
Definition: swath_length_test.py:14
swath_length_test.near
def near(a, b, error=1e-7)
Definition: swath_length_test.py:10


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