Effacer les filtres
Effacer les filtres

Distribute randomly robots in the workspace

2 vues (au cours des 30 derniers jours)
Veronika Mazulina
Veronika Mazulina le 30 Jan 2020
I have a set of robots N. The workspace where robots operate is divided on compartments. How to distribute robots uniformly between compartments.
For example,
If I have 16 robots and 4 compartments, than after distribution every compartment will have 4 robots.
If I have 17 robots and 4 compartments, than after distribution 3 random compartments will contain 4 robots and 1 compartment will contain 5 robots.

Réponses (2)

KSSV
KSSV le 30 Jan 2020
N = 16 ;
d = reshape(randperm(N),4,4)
  1 commentaire
Veronika Mazulina
Veronika Mazulina le 30 Jan 2020
In this case I have 16 results in the interval from 1 to 16. I need 16 results in the interval from 1 to 4. But anyway thank you, think I found a solution:
All_Robots = 1:RobotsNum;
Robots_Compartment = zeros(1,RobotsNum);
Number_of_Compartments = 4;
% Number of Robots in Every Compartment
Integer = floor(RobotsNum/Number_of_Compartments);
% Number of Compartments With One More Robot
Rest = mod(RobotsNum,Number_of_Compartments);
%% Distribute vehicles between compartments
for ii = 1:Integer
Robots_pos = randperm(length(All_Robots),Number_of_Compartments);
Robots = All_Robots(Robots_pos);
Comp = randperm(Number_of_Compartments,Number_of_Compartments);
for jj = 1:Number_of_Compartments
Find1 = Robots(jj);
Find2 = Comp(jj);
Robots_Compartment(Find1) = Find2;
end
All_Robots(Robots_pos) = [];
end

Connectez-vous pour commenter.


KSSV
KSSV le 30 Jan 2020
N = 16 ;
d = reshape(randperm(N),4,4)

Catégories

En savoir plus sur Robotics dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by