Filter löschen
Filter löschen

Distribute randomly robots in the workspace

2 Ansichten (letzte 30 Tage)
Veronika Mazulina
Veronika Mazulina am 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.

Antworten (2)

KSSV
KSSV am 30 Jan. 2020
N = 16 ;
d = reshape(randperm(N),4,4)
  1 Kommentar
Veronika Mazulina
Veronika Mazulina am 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

Melden Sie sich an, um zu kommentieren.


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

Kategorien

Mehr zu Robotics finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by