how to write code to ceate population of individuals that has three parameters namely location, type of equipment and it rating

how to write code to ceate population of individuals that has three parameters namely location, type of equipment and its rating , the single individulal is as follow for example
location = 12 3 7 number of locations is 200 site
type = 1 2 3 4 number of type of equipments to be placed in the above location is is 5
rating = 0.1 0.8 0.5 0.2 ( rating of equipment value between 0-1)

Answers (1)

randi(200), randi(5), rand()

15 Comments

In other words I did not complete your homework assignment for you.
You can use randi(200) to place a population member in one of the 200 locations. You can use randi(5) to select from the 5 possibilities for the same second condition. You can use rand() to generate a rating in the required range.
I could not understand your question about whether the 5 referred to the number of tools the person would have or if it refers to the random selection from 5 different tools. If it is the number of tools then that affects your choice of data representation.
it is 4 this is error. Actually there is 4 type of 4 equipment to be placed at 4 locations. In facts I want place Facts devices (equipment) at different location optimally in terms of location, types and rating in electrical network attached on diagram showing the network
If you have 4 types of equipment at 4 locations, then where does the "12" and "7" and "200" enter in to this, and why does the diagram show "9" as a possible location value?
Actual location it can be more than 100 locations, but my intention is to place 4 only at optimal location in order to achieve best objective. I am waiting for your help Thank you for you patient
Each FACT appears to have 4 items, with each item represented by a Location, a Type, and an Encoded Rate. You have indicated that the Encoded Rate is in the range 0 to 1. What are the valid possible Type? What are the valid possible Location?
How many FACT are to be generated?
The valid possible types are 4 types which can be coded as 1, 2, 3 and 4. The encoded rate is between 0-1 and later will be multiply by 100 to get the actual rating of the FACT device. As shown in the attached diagram there are 13 location, numbered as L1, L2,........L13, but only 4 types I want to locate in 4 best location to achieve my optimal objective function
Well, I cannot tell which of these two you are looking for:
FACT = struct('location', randi(13,1,4), 'type', randi(4,1,4), 'rate', rand(1,4));
or
for K = 1 : 4
FACT(K) = struct('location', randi(13,1,4), 'type', randi(4,1,4), 'rate', rand(1,4));
end
I have understood from the second code, the loop is for selecting of 4 location among 13 location for Facts devices, please correct me if I am wrong. Secondly the above code is only for one individual, if I want create 100 individuals to form a population in order to utilize it for evolutionary algorithm how to modify it.

No, the first form I gave creates one individual in the population, with each individual having 4 locations and 4 types and 4 rates. The second form I gave, with the loop, creates 4 individuals.

I specifically asked you "How many FACT are to be generated?" and you did not answer that clearly. If the answer is 100, then

for K = 1 : 100
  FACT(K) = struct('location', randi(13,1,4), 'type', randi(4,1,4), 'rate', rand(1,4));
end

If you need this more clearly:

locations_per_FACT = 4;
number_of_types = 4;
number_of_locations = 13;
population_size = 100;
for K = 1 : population_size
  FACT(K) = struct('location', randi(number_of_locations,1,locations_per_FACT), 'type', randi(number_of_types,1,locations_per_FACT), 'rate', rand(1,locations_per_FACT));
end

Question: do the locations need to be different for any given FACT ? If they do then:

locations_per_FACT = 4;
number_of_types = 4;
number_of_locations = 13;
population_size = 100;
for K = population_size : -1 : 1
  FACT(K) = struct('location', randperm(number_of_locations,locations_per_FACT), 'type', randi(number_of_types,1,locations_per_FACT), 'rate', rand(1,locations_per_FACT));
end

I can see from the diagram that the types can be duplicates within any one FACT.

Thank you very much for your support. but also I want that there should be only one FACT at one location, for example at location 9 there should be only one FACT whether type, 1,2,3 or 4 ie ( 2 FACT in one location is not allowed).
Also as an option as you mentioned If we would not like to duplicate the FACT type in the 4 location, even though it will not affect problem how the code it will look.
When you say that there should only be one FACT at one location, do you mean that within the individual population member (one of 100) that the location should not be duplicated? If so then the last set of code I posted above, the version with randperm, takes care of that.
If though you mean that out of the population of 100 individuals, only 1 of the individuals should be associated with any given location, then you cannot do that unless you have at least locations_per_FACT * population_size = 4 * 100 = 400 different locations.
If the type should not be duplicated in any one individual, then as there are only 4 different types, you will just be taking pure permutations in the population:
locations_per_FACT = 4;
number_of_types = 4;
number_of_locations = 13;
population_size = 100;
for K = population_size : -1 : 1
FACT(K) = struct('location', randperm(number_of_locations,locations_per_FACT), 'type', randperm(number_of_types,locations_per_FACT), 'rate', rand(1,locations_per_FACT));
end
I note that your diagram above in part b) shows the types as "2 2 1 1", so according to the diagram it is okay for there to be duplicate types within the same population member.
I mean for one individual, we should not place more than one FACT at one location.
Then I already took care of that with the "randperm". You can test the code, you know.

This question is closed.

Tags

Asked:

on 13 Oct 2015

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!