Course Hero Logo

BGA_template.m - function [fitness, total_profit,...

Course Hero uses AI to attempt to automatically extract content from documents to surface to you and others so you can study better, e.g., in search results, to enrich docs, and more. This preview shows page 1 - 2 out of 2 pages.

function [fitness, total_profit, total_cons_vio, best_solution] = BGA_template% Solving project selection problme using Binary GA% Generate 4 bits are enough for our problem: 4 projectsnum_bit = 4;% Parameterscrossover_prob = 0.85;mutation_prob = 1/num_bit;num_ind = 5;max_iter = 100;num_parents = floor(num_ind * 0.3);% Generate initial solution% Calculate fitness for the initial populationfitness = [];fitness = cal_fitness(pop);% Sort the individuals in the population according to their fitness values% Note: we are maximising profit (the more profit, the better the% individual)[~, sorted_idx] = sort(fitness, 'descend');pop = pop(sorted_idx,:);termination_flag = false;t=1;while termination_flag == false%Select parents from the population based on their fitness using truncationselectionparents = pop(1:num_parents,:);offerspring = parents;%% apply crossoverfor j=1:floor(num_parents/2)if rand(1) <crossover_prob% Randomly select two individuals from parents% Randomly select a bit as cross point% Swap the bits beyond the cross pointendend%% apply mutation.

Upload your study docs or become a

Course Hero member to access this document

End of preview. Want to read all 2 pages?

Upload your study docs or become a

Course Hero member to access this document

Term
Spring
Professor
miss ayesha

Newly uploaded documents

Show More

Newly uploaded documents

Show More

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture