Connecting points and finding the best possible path

5 views (last 30 days)
I have some code that randomly generates nodes for routing a UAV path. The code generates genuine and malicious nodes where genuine nodes are "refill stations" for the uav and the malicious nodes are areas to avoid. I was wondering if there is a way to connect the random points so that it can find the best and shortest path while avoding the malicious nodes. Here's what I have so far. Some parts may be redundant, but I was just focusing on getting it to work
%Generating node locations to help aid in the routing of a UAV
%Genuine Nodes represent refill stations
%Malicious Nodes represent areas to avoid
clc;
clear all;
close all;
no_nodes = input('Enter the number of nodes: ');
no_nodes_m = input('Enter the number of malicious nodes: ');
network_length = input('Enter the length of the network: ');
network_width = input('Enter the width of the network: ');
for i = 1:no_nodes
x_loc(i) = network_length*rand;
y_loc(i) = network_width*rand;
%nodes_id(i) = i;
plot(x_loc(i),y_loc(i),'b^','linestyle','none')
hold on
xlabel('Network Length');
ylabel('Network Height');
grid on
pause(.5);
end
for j = 1:no_nodes_m
x_loc_m(j) = network_length*rand;
y_loc_m(j) = network_width*rand;
%nodes_id_m(j) = j;
plot(x_loc_m(j),y_loc_m(j),'ro','linestyle','none')
hold on;
xlabel('Network Length');
ylabel('Network Height');
grid on
pause(.5);
end
source = rem(round((no_nodes+no_nodes_m)*rand),no_nodes);
if source == 0
source = 15;
end
destination = rem(round((no_nodes+no_nodes_m)*rand),no_nodes);
if destination == 0
destination = 16;
end
figure(1)
plot(x_loc(source),y_loc(source),'b^','linewidth',2);
text(x_loc(source),y_loc(source), 'SRC')
hold on
plot(x_loc(destination),y_loc(destination),'g^','linewidth',2);
text(x_loc(destination),y_loc(destination), 'Destination')
% Connecting source and destination
source_loc = [x_loc(source), y_loc(source)];
destination_loc = [x_loc(destination), y_loc(destination)];
p1 = [source_loc(1) destination_loc(1)];
p2 = [source_loc(2) destination_loc(2)];
x = [p1(1) p2(1)];
y = [p1(2) p2(2)];
plot([x(1) y(1)],[x(2) y(2)])

Answers (0)

Categories

Find more on UAV in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!