how to write code to ceate population of individuals that has three parameters namely location, type of equipment and it rating
Info
This question is closed. Reopen it to edit or answer.
Show older comments
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)
Walter Roberson
on 13 Oct 2015
0 votes
randi(200), randi(5), rand()
15 Comments
omer Elsiddig
on 13 Oct 2015
Walter Roberson
on 13 Oct 2015
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.
omer Elsiddig
on 13 Oct 2015
Walter Roberson
on 13 Oct 2015
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?
omer Elsiddig
on 13 Oct 2015
Edited: omer Elsiddig
on 14 Oct 2015
Walter Roberson
on 14 Oct 2015
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?
omer Elsiddig
on 14 Oct 2015
Walter Roberson
on 14 Oct 2015
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
omer Elsiddig
on 14 Oct 2015
Walter Roberson
on 15 Oct 2015
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.
omer Elsiddig
on 15 Oct 2015
Edited: omer Elsiddig
on 15 Oct 2015
Walter Roberson
on 15 Oct 2015
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.
omer Elsiddig
on 15 Oct 2015
Walter Roberson
on 15 Oct 2015
Then I already took care of that with the "randperm". You can test the code, you know.
omer Elsiddig
on 16 Oct 2015
This question is closed.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!