2 |
3 |
4 |
5 |
6 |
7 | Polygon on map
8 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
117 |
120 |
121 |
--------------------------------------------------------------------------------
/src/main/resources/visualizeWGS84.m:
--------------------------------------------------------------------------------
1 | clear;
2 | clc;
3 | close all;
4 |
5 |
6 |
7 | %% Polygon ROI - coverage paths - coverage distance
8 |
9 | polygonWGS84 = [40.873884282708275, 24.312673846131773;
10 | 40.873728114416515, 24.31273330177858;
11 | 40.87360034008555, 24.3129215034581;
12 | 40.873545579582554, 24.313190171408067;
13 | 40.873555720419844, 24.313501754702273;
14 | 40.87359222742132, 24.313648158617823;
15 | 40.873661185035814, 24.313783833697315;
16 | 40.873758536839944, 24.313891904372284;
17 | 40.87386400113278, 24.313978517375133;
18 | 40.87399785941641, 24.31410804572222;
19 | 40.8740647884567, 24.314237182912123;
20 | 40.87409622480081, 24.314341984642297;
21 | 40.87411143592965, 24.31448970171671;
22 | 40.8739248458407, 24.316089192386542;
23 | 40.875318779965916, 24.316346684451972;
24 | 40.87574062618736, 24.312577286607237;
25 | 40.87517412533149, 24.312598744279356;
26 | 40.8749767391839, 24.312829414254637;
27 | 40.87408775656638, 24.312657752877683];
28 |
29 | obstacles = {[40.87435937003009, 24.313325920763702;
30 | 40.87430866644355, 24.31344781227139;
31 | 40.87428230056317, 24.313612619123276;
32 | 40.874245793942215, 24.31376267382558;
33 | 40.87410787985927, 24.314191678265473;
34 | 40.87490857822834, 24.31438747952356;
35 | 40.87499375945969, 24.31393180199605;
36 | 40.874996167856025, 24.3138444811903;
37 | 40.874974238770626, 24.313762524802627;
38 | 40.87495332374008, 24.313698002773506;
39 | 40.87492023995101, 24.31362006969931;
40 | 40.87490071924024, 24.31354601092592;
41 | 40.87489742353518, 24.313482680988585;
42 | 40.87491516963704, 24.313404300876144;
43 | 40.87494102823421, 24.313331285181732;
44 | 40.874623834026536, 24.31324813670227;
45 | 40.874463208213406, 24.31324411338875]};
46 |
47 | path = [40.87511606353929, 24.31620760355072;
48 | 40.8752938771259, 24.31624525463758;
49 | 40.875722508208646, 24.312731338258402;
50 | 40.87518906400966, 24.31261841297073;
51 | 40.875131919836605, 24.313086934114185;
52 | 40.87370940222757, 24.312785799110443;
53 | 40.87362368419745, 24.31348856472302;
54 | 40.87380149874874, 24.31352620772088;
55 | 40.873858644728095, 24.313057696296713;
56 | 40.874036459407904, 24.313095338278785;
57 | 40.873922165245325, 24.314032362757327;
58 | 40.87409997960375, 24.31407000737295;
59 | 40.87421427406625, 24.313132980461504;
60 | 40.875103347036074, 24.313321194384923;
61 | 40.874960475893324, 24.31449249272835;
62 | 40.87424921906012, 24.31434190902361;
63 | 40.87404918156848, 24.315981701244166;
64 | 40.87422699528397, 24.31601935112686;
65 | 40.87439845786906, 24.31461381189068;
66 | 40.87457627201311, 24.314651458324757;
67 | 40.874404808977985, 24.316057001210247;
68 | 40.87458262265053, 24.31609465149432;
69 | 40.87475408613569, 24.31468910495951;
70 | 40.87493190023679, 24.314726751794936;
71 | 40.8747604363016, 24.31613230197909;
72 | 40.87493824993119, 24.31616995266456;
73 | 40.875338306840646, 24.312890315812947;
74 | 40.87551612149866, 24.312927958183753;
75 | 40.87511606353929, 24.31620760355072];
76 |
77 |
78 |
79 | %% Transform to NED
80 | % Transformation for polygon
81 | [n,m] = size(polygonWGS84);
82 | polygonNED = zeros(n,m);
83 | wgs84 = wgs84Ellipsoid;
84 | fprintf(' ~~~ Polygon hull: ~~~ \n\n');
85 | for i=1:n
86 | [polygonNED(i,1), polygonNED(i,2)] = geodetic2ned(polygonWGS84(i,1),polygonWGS84(i,2),0,polygonWGS84(1,1),polygonWGS84(1,2),0,wgs84);
87 | fprintf('- {x: %f, y: %f, z: %f}\n', polygonNED(i,2), polygonNED(i,1), 4.0);
88 | end
89 |
90 | % Transformation for obstacles
91 | if (~isempty(obstacles))
92 | fprintf('\n\n ~~~ Obstacles: ~~~ \n');
93 | for i = 1:length(obstacles)
94 | fprintf('\n - NFZ %d: \n',i);
95 | [o1,o2] = size(obstacles{i});
96 | obNED = zeros(o1,o2);
97 | for j=1:o1
98 | [obNED(j,1), obNED(j,2)] = geodetic2ned(obstacles{i}(j,1),obstacles{i}(j,2),0,polygonWGS84(1,1),polygonWGS84(1,2),0,wgs84);
99 | fprintf('- {x: %f, y: %f, z: %f}\n', obNED(j,2), obNED(j,1), 4.0);
100 | end
101 | obstNED{i} = obNED;
102 | end
103 | end
104 |
105 | % Transformation for path
106 | [k,l] = size(path);
107 | pathNED = zeros(k,l);
108 | for i=1:k
109 | [pathNED(i,1), pathNED(i,2)] = geodetic2ned(path(i,1),path(i,2),0,polygonWGS84(1,1),polygonWGS84(1,2),0,wgs84);
110 | end
111 |
112 | %% Plot paths in poly
113 | figure;
114 |
115 | hold on;
116 |
117 | title('Polygon ROI with paths')
118 | axis equal;
119 | axis off;
120 |
121 | fill(polygonNED(:,2),polygonNED(:,1),'g'); % polygon
122 |
123 | if (~isempty(obstacles)) % obstacles
124 | for i=1:length(obstacles)
125 | fill(obstNED{i}(:,2), obstNED{i}(:,1),'r')
126 | end
127 | end
128 |
129 | plot(pathNED(:,2),pathNED(:,1),'k --'); % paths
130 |
131 | hold off;
132 |
--------------------------------------------------------------------------------
/src/test/java/DARPTester.java:
--------------------------------------------------------------------------------
1 | import pathPlanning.darp.ConnectComponent;
2 | import pathPlanning.darp.DARP;
3 |
4 | import java.awt.*;
5 |
6 |
7 | public class DARPTester {
8 |
9 | public static void main (String[] args) {
10 | // -------------------------------------------------------------------------------------------------------------
11 | // DARP parameters
12 | // -------------------------------------------------------------------------------------------------------------
13 | int droneNo = 4; // #UAVs
14 | boolean notEqualPortions = false; // # For proportional area allocation --> true
15 | double[] Rportions = new double[]{}; // When proportional area allocation is asked, provide portions
16 |
17 |
18 | // Grid size
19 | int l = 20;
20 | int m = 20;
21 |
22 |
23 | // Grid that will be given as input to DARP
24 | int[][] DARPgrid;
25 |
26 | //----------------------------------------------
27 | // Initianize GRID (or give grid as input)
28 | //----------------------------------------------
29 | // In DARPgrid 0 stands for free space
30 | // 1 stands for Obstacle
31 | // 2 stands for Drone
32 | DARPgrid = new int[l][m];
33 | // Grid representation
34 | for (int i = 0; i < l; i++) {
35 | for (int j = 0; j < m; j++) {
36 | DARPgrid[i][j] = 0;
37 | }
38 | }
39 | //----------------------------------------------
40 |
41 |
42 | // Check for grid connectivity
43 | ConnectComponent G2G = new ConnectComponent();
44 | int[][] connectivityTest = new int[l][m];
45 | for (int i = 0; i < l; i++) {
46 | for (int j = 0; j < m; j++) {
47 | connectivityTest[i][j] = Math.abs(DARPgrid[i][j] - 1);
48 | }
49 | }
50 | G2G.compactLabeling(connectivityTest, new Dimension(m, l), true);
51 | if (G2G.getMaxLabel() > 1) {
52 | System.out.println("\n\n !!! The environment grid MUST not have" +
53 | " unreachable and/or closed shape regions !!! \n\n");
54 | return;
55 | }
56 |
57 |
58 | //initial positions of drone(s)
59 | DARPgrid[0][1] = 2;
60 | DARPgrid[2][10] = 2;
61 | DARPgrid[3][16] = 2;
62 | DARPgrid[4][3] = 2;
63 |
64 |
65 | // Parameters to run DARP
66 | int MaxIter = 80000;
67 | double CCvariation = 0.01;
68 | double randomLevel = 0.0001;
69 | int dcells = 2;
70 | boolean importance = false;
71 |
72 |
73 | // If user has not defined custom portions divide area equally for all drones
74 | if (!notEqualPortions) {
75 | Rportions = new double[droneNo];
76 | for (int i = 0; i < droneNo; i++) {
77 | Rportions[i] = 1.0/droneNo;
78 | }
79 | }
80 |
81 | System.out.println("Portion of the total area assigned to each drone:");
82 | for (int i = 0; i < droneNo; i++) {
83 | System.out.println(" - "+Rportions[i]*100+" %");
84 | }
85 | System.out.println();
86 |
87 | // Perform operational area division (run DARP)
88 | DARP problem = new DARP(l, m, DARPgrid, MaxIter, CCvariation, randomLevel, dcells, importance, Rportions);
89 |
90 | // Warn when no drone is defined
91 | System.out.println("Number of drones: " + problem.getNr());
92 | if (problem.getNr() <= 0) {
93 | System.out.println("\n\n !!! You should use at least one drone !!!\n");
94 | return;
95 | }
96 |
97 | // Run DARP
98 | int[][] DARPAssignmentMatrix = new int[0][];
99 | problem.constructAssignmentM();
100 | if (problem.getSuccess()) {
101 | DARPAssignmentMatrix = problem.getAssignmentMatrix();
102 | } else {
103 | System.out.println("\nDARP did not manage to find a solution for the given configuration!");
104 | return;
105 | }
106 |
107 | System.out.println("\nTotal iterations needed: "+problem.getIter());
108 | System.out.println("\nAssignment matrix: ");
109 | for (int i=0; i paths strictly in polygon mode/false --> better coverage mode
38 |
39 | double[][] initialPos = new double[][] // initial positions of the vehicles (WGS84 coordinates)
40 | {{40.93267,24.40603}, {40.93131,24.41342}, {40.93534,24.41271}};
41 | // double[][] initialPos = new double[][]{};
42 |
43 | double[] rPortions = new double[]{.3, .6, .1 }; // percentage of the region that each vehicle should undertake (sum should always be 1)
44 | // double[] rPortions = new double[]{};
45 | //--------------------------------------------------------------------------------------------------------------
46 |
47 |
48 |
49 | //--------------------------------------------------------------------------------------------------------------
50 | // Run optimized DARP mCPP algorithm
51 | //--------------------------------------------------------------------------------------------------------------
52 | DARPinPoly mission = new DARPinPoly();
53 | if(initialPos.length > 0){
54 | if (rPortions.length > 0){
55 | mission.waypointsDARP(droneNo, scanningDensity, polygon, obstacles, pathsStrictlyInPoly, initialPos, rPortions);
56 | } else {
57 | mission.waypointsDARP(droneNo, scanningDensity, polygon, obstacles, pathsStrictlyInPoly, initialPos);
58 | }
59 | } else {
60 | if (rPortions.length > 0){
61 | mission.waypointsDARP(droneNo, scanningDensity, polygon, obstacles, pathsStrictlyInPoly, rPortions);
62 | } else {
63 | mission.waypointsDARP(droneNo, scanningDensity, polygon, obstacles, pathsStrictlyInPoly);
64 | }
65 | }
66 | mission.printWaypointsWGS84();
67 |
68 | ArrayList> missionWaypoints = mission.getMissionWaypointsWGS84();
69 | //--------------------------------------------------------------------------------------------------------------
70 |
71 | }
72 |
73 | }
74 |
--------------------------------------------------------------------------------