2_objective_functions.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 
8 import math
9 import fields2cover as f2c
10 
11 print("####### Tutorial 2.1.1 Remaining Area ######");
12 
13 total_field = f2c.Cells(f2c.Cell(f2c.LinearRing(f2c.VectorPoint([
14  f2c.Point(-2,-2), f2c.Point(6,-2), f2c.Point(6,6),
15  f2c.Point(-2,6), f2c.Point(-2,-2)]))));
16 field = f2c.Cells(f2c.Cell(f2c.LinearRing(f2c.VectorPoint([
17  f2c.Point(0,0), f2c.Point(4,0), f2c.Point(4,4),
18  f2c.Point(0,4), f2c.Point(0,0)]))));
19 
20 rem_area = f2c.OBJ_RemArea();
21 print("The remaining area is ",
22  rem_area.computeCost(total_field, field), ", and with sign is ",
23  rem_area.computeCostWithMinimizingSign(total_field, field));
24 
25 
26 
27 
28 print("\n\n####### Tutorial 2.2.1 Field Coverage ######");
29 width = 2.0;
30 swath1 = f2c.Swath(f2c.LineString(f2c.VectorPoint([
31  f2c.Point(0.0, 1.0), f2c.Point(4.0, 1.0)])), width);
32 swath2 = f2c.Swath(f2c.LineString(f2c.VectorPoint([
33  f2c.Point(0.0, 3.0), f2c.Point(4.0, 3.0)])), width);
34 swath3 = f2c.Swath(f2c.LineString(f2c.VectorPoint([
35  f2c.Point(0.0, 2.0), f2c.Point(4.0, 2.0)])), width);
36 
37 swaths1 = f2c.Swaths();
38 swaths1.push_back(swath1);
39 swaths3 = f2c.Swaths();
40 [swaths3.push_back(s) for s in [swath1, swath2, swath3]];
41 
42 field_cov = f2c.OBJ_FieldCoverage();
43 print("The field coverage with swath1 is ",
44  field_cov.computeCost(field, swaths1), " and with all of the swaths ",
45  field_cov.computeCost(field, swaths3));
46 print("The field coverage with sign for all of the swaths is ",
47  field_cov.computeCostWithMinimizingSign(field, swaths3));
48 
49 print("\n####### Tutorial 2.2.2 Number of swaths ######");
50 n_swaths = f2c.OBJ_NSwath();
51 print("The number of swaths with swath1 is ",
52  n_swaths.computeCost(swaths1), " and with all of the swaths ",
53  n_swaths.computeCost(field, swaths3));
54 
55 print("\n####### Tutorial 2.2.3 Overlap ######");
56 overlaps = f2c.OBJ_Overlaps();
57 print("The field overlapping with swath1 is ",
58  overlaps.computeCost(field, swaths1), " and with all of the swaths ",
59  overlaps.computeCost(field, swaths3));
60 
61 print("\n####### Tutorial 2.2.4 Swath length ######");
62 swath_length = f2c.OBJ_SwathLength();
63 print("The swath length with swath1 is ",
64  swath_length.computeCost(field, swaths1), " and with all of the swaths ",
65  swath_length.computeCost(field, swaths3));
66 
67 
68 print("\n\n####### Tutorial 2.3.1 Distance with turns ######");
69 line1 = f2c.LineString(f2c.VectorPoint([f2c.Point(0.0, 0.0), f2c.Point(0.0, 1.0)]));
70 swath1 = f2c.Swath(line1);
71 line2 = f2c.LineString(f2c.VectorPoint([f2c.Point(1.0, 1.0), f2c.Point(1.0, 0.0)]));
72 swath2 = f2c.Swath(line2);
73 swaths_path = f2c.Swaths();
74 swaths_path.push_back(swath1);
75 swaths_path.push_back(swath2);
76 robot = f2c.Robot(2.0, 3.0);
77 robot.setMinTurningRadius(0.5);
78 complete_length = f2c.OBJ_CompleteTurnPathObj_Dubins(robot);
79 print("The complete length is: ", complete_length.computeCost(swaths_path),
80  " =~= ", 1 + 1 + math.pi/2.0);
81 
82 print("\n####### Tutorial 2.3.2 Direct distance without turns ######");
83 direct_dist = f2c.OBJ_DirectDistPathObj();
84 print("The aproximated length is: ", direct_dist.computeCost(swaths_path));
85 
86 
87 print("\n\n####### Tutorial 2.4.1 Path length ######");
88 path = f2c.Path()
89 path.appendSwath(swaths_path.at(0), 1);
90 path.appendSwath(swaths_path.at(1), 1);
91 
92 path_length = f2c.OBJ_PathLength();
93 print("The path length is: ", path_length.computeCost(path));
94 
95 
96 
97 
98 


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