Add Heuristic a b C D E 1 5 3 7 2 9 4 6 8 10 11 12 13 Switch Cost 𝜹 𝒊, 𝒋 = 𝟏 𝒊𝒇 𝒖𝒔𝒆𝒓 𝒊 𝒄𝒐𝒏𝒏𝒆𝒄𝒕𝒆𝒅 𝒕𝒐 𝒔𝒘𝒊𝒕𝒄𝒉 𝒋 𝟎 𝑶𝒕𝒉𝒆𝒓𝒘𝒊𝒔𝒆 𝜶 𝒋 = 𝟏 𝒊𝒇 𝒔𝒘𝒊𝒕𝒄𝒉 𝒋 𝒊𝒔 𝒊𝒏𝒔𝒕𝒂𝒍𝒍𝒆𝒅 𝟎 𝑶𝑾 ∁ 𝒋 =𝒄𝒐𝒔𝒕 𝒐𝒇 𝒊𝒏𝒔𝒕𝒂𝒍𝒍𝒊𝒏𝒈 𝒔𝒘𝒊𝒕𝒄𝒉 𝒋 𝜷 𝒊, 𝒋 = cost of connecting user I to switch j 𝑲 𝒋 = maximum number of users connected switch j (13 in this case for all switches) 𝑴𝒊𝒏 𝒊 𝒋 𝜷 𝒊, 𝒋 𝜹 𝒊, 𝒋 + 𝒋 ∁ 𝒋 𝜶 𝒋 𝒔𝒕 𝒊 𝜹 𝒊, 𝒋 ≤ 𝑲 𝒋 𝜶 𝒋 𝒋 𝜹 𝒊, 𝒋 =𝟏 ∀𝒊
1st Iteration S = {a} a b C D E 1 5 3 7 2 9 4 6 8 10 11 12 13 Switch Cost Total Cost = Cost of installing switch a + cost of connecting all users to switch a = 51
2nd Iteration S = {a, b} a b C D E 1 5 3 7 2 9 4 6 8 10 11 12 13 Switch Cost Total Cost = 51 – 2 – 2 – 6 – 4 – 4 + 8 = 41 < 51
2nd Iteration S = {a, c} a b C D E 1 5 3 7 2 9 4 6 8 10 11 12 13 Switch Cost Total cost = 51 – 1 – 5 – 1 – 1 – 6 – 1 + 4 = 40 < 51
2nd Iteration S = {a, d} a b C D E 1 5 3 7 2 9 4 6 8 10 11 12 13 Switch Cost Total cost = 51 – 3 – 3 – 1 – 5 – 2 – 1 – 2 + 3 = 37< 51
2nd Iteration S = {a, e} a b C D E 1 5 3 7 2 9 4 6 8 10 11 12 13 Switch Cost Total cost = 51 – 4 – 5 – 2 – 1 – 7 – 5 + 2 = 29 < 51 Cost of {a, b} = 41 Cost of {a, c} = 40 Cost of {a, d} = 37 Cost of {a, e} = 29 (highest reduction)
3rd Iteration S = {a, e, b} a b C D E 1 5 3 7 2 9 4 6 8 10 11 12 13 Switch Cost Total cost = 29 – 1 – 2 + 8 = 34> 29 (Rejected)
3rd Iteration S = {a, e, c} a b C D E 1 5 3 7 2 9 4 6 8 10 11 12 13 Switch Cost Total cost = 29 – 1 – 1 + 4 = 31 > 29 (Rejected)
3rd Iteration S = {a, e, d} a b C D E 1 5 3 7 2 9 4 6 8 10 11 12 13 Switch Cost Total cost = 29 – 3 - 1 + 3 = 28 < 29 (Accepted)
4th Iteration S = {a, e, d, b} a b C D E 1 5 3 7 2 9 4 6 8 10 11 12 13 Switch Cost Total cost = 28 – 1 + 8 = 35 > 28 (Rejected)
4th Iteration S = {a, e, d, c} a b C D E 1 5 3 7 2 9 4 6 8 10 11 12 13 Switch Cost Total cost = 28 – 1 + 4 = 33 > 28 (Rejected) The best solution is installing switches a, e and d
Genetics Algorithm
Genetics Algorithm Consider the following channel allocation problem shown in the figure on the right. The objective of the problem is to allocate 4 channels to 2 users. Each user on the left hand side can transmit on any of the channels indicated on the right hand side. If a user 𝒊 uses channel 𝒋 he/she will be able to transmit at a rate equal to 𝒄 𝒊, 𝒋 . The values of 𝒄 𝒊, 𝒋 are shown on the arrows connecting each user to the channel. It is required to allocate channels to users such as to maximize the total data rate while satisfying the following conditions: Each user can be allocated a maximum of three channels and minimum of 1 channel Each channel can be allocated to a maximum of one user. Write the objective function and the constrains Generate a population of 2 solutions and apply genetic algorithm
Genetics Algorithm 𝜹 𝒊, 𝒋 = 𝟏 𝒊𝒇 𝒖𝒔𝒆𝒓 𝒊 𝒄𝒐𝒏𝒏𝒆𝒄𝒕𝒆𝒅 𝒕𝒐 𝒄𝒉𝒂𝒏𝒏𝒆𝒍 𝒋 𝟎 𝑶𝒕𝒉𝒆𝒓𝒘𝒊𝒔𝒆 𝑴𝒂𝒙 𝒊 𝒋 𝒄 𝒊, 𝒋 𝜹 𝒊, 𝒋 𝒔𝒕 𝒊=𝟏 𝒊=𝟐 𝜹 𝒊, 𝒋 ≤𝟏 ∀𝒋∈ 𝟏, …, 𝟒 𝟏≤ 𝒋=𝟏 𝒋=𝟒 𝜹 𝒊, 𝒋 ≤𝟑 ∀𝒊∈ 𝟏, 𝟐
Genetics Algorithm (Generating random valid solutions) 𝜹 𝟏, 𝟏 , 𝜹 𝟏, 𝟐 , 𝜹 𝟏, 𝟑 , 𝜹 𝟏, 𝟒 , 𝜹 𝟐, 𝟏 , 𝜹 𝟐, 𝟐 , 𝜹 𝟐, 𝟑 , 𝜹 𝟐, 𝟒 𝒊 𝒋 𝒄 𝒊, 𝒋 𝜹 𝒊, 𝒋 Sol 1 𝟏 ,𝟎 ,𝟎 ,𝟎 ,𝟎 ,𝟏 ,𝟎 , 𝟏 𝟕 +𝟑 +𝟑 =𝟏𝟑 Sol 2 𝟎 , 𝟎 ,𝟏 ,𝟎 ,𝟎 ,𝟎 ,𝟎, 𝟏 𝟔 + 𝟑 =𝟗 𝜹 𝒊, 𝒋 = 𝟏 𝒊𝒇 𝒖𝒔𝒆𝒓 𝒊 𝒄𝒐𝒏𝒏𝒆𝒄𝒕𝒆𝒅 𝒕𝒐 𝒄𝒉𝒂𝒏𝒏𝒆𝒍 𝒋 𝟎 𝑶𝒕𝒉𝒆𝒓𝒘𝒊𝒔𝒆 𝑴𝒂𝒙 𝒊 𝒋 𝒄 𝒊, 𝒋 𝜹 𝒊, 𝒋 𝒔𝒕 𝒊=𝟏 𝒊=𝟐 𝜹 𝒊, 𝒋 ≤𝟏 ∀𝒋∈ 𝟏, …, 𝟒 𝟏≤ 𝒋=𝟏 𝒋=𝟒 𝜹 𝒊, 𝒋 ≤𝟑 ∀𝒊∈ 𝟏, 𝟐
Genetics Algorithm (Crossover) 𝜹 𝟏, 𝟏 , 𝜹 𝟏, 𝟐 , 𝜹 𝟏, 𝟑 , 𝜹 𝟏, 𝟒 , 𝜹 𝟐, 𝟏 , 𝜹 𝟐, 𝟐 , 𝜹 𝟐, 𝟑 , 𝜹 𝟐, 𝟒 𝒊 𝒋 𝒄 𝒊, 𝒋 𝜹 𝒊, 𝒋 Sol 1 𝟏 ,𝟎 ,𝟎 ,𝟎 ,𝟎 ,𝟏 ,𝟎 , 𝟏 𝟕 +𝟑 +𝟑 =𝟏𝟑 Sol 2 𝟎 , 𝟎 ,𝟏 ,𝟎 ,𝟎 ,𝟎 ,𝟎, 𝟏 𝟔 + 𝟑 =𝟗 Sol 3 𝟎 , 𝟎 ,𝟏 ,𝟎 ,𝟎 ,𝟏 ,𝟎, 𝟏 𝟔 + 𝟑 + 𝟑 =𝟏𝟐 Sol 4 𝟏 , 𝟎 ,𝟎 ,𝟎 ,𝟎 ,𝟎 ,𝟎, 𝟏 𝟕 + 𝟑 = 𝟏𝟎
Genetics Algorithm (Another Crossover Example) 𝜹 𝟏, 𝟏 , 𝜹 𝟏, 𝟐 , 𝜹 𝟏, 𝟑 , 𝜹 𝟏, 𝟒 , 𝜹 𝟐, 𝟏 , 𝜹 𝟐, 𝟐 , 𝜹 𝟐, 𝟑 , 𝜹 𝟐, 𝟒 𝒊 𝒋 𝒄 𝒊, 𝒋 𝜹 𝒊, 𝒋 Sol 1 𝟏 ,𝟎 ,𝟎 ,𝟎 ,𝟎 ,𝟏 ,𝟎 , 𝟏 𝟕 +𝟑 +𝟑 =𝟏𝟑 Sol 2 𝟎 , 𝟎 ,𝟏 ,𝟎 ,𝟎 ,𝟎 ,𝟎, 𝟏 𝟔 + 𝟑 =𝟗 Sol 3 𝟎 , 𝟎 ,𝟏 ,𝟎 ,𝟎 ,𝟏 ,𝟎, 𝟏 𝟔 + 𝟑 + 𝟑 =𝟏𝟐 Sol 4 𝟏 , 𝟎 ,𝟎 ,𝟎 ,𝟎 ,𝟎 ,𝟎, 𝟏 𝟕 + 𝟑 = 𝟏𝟎 Sol 5 Sol 6 𝟎 ,𝟎 ,𝟏 ,𝟎 ,𝟎 ,𝟏 ,𝟎 , 𝟏 𝟔 + 𝟑 + 𝟑 = 𝟏𝟐
Genetics Algorithm (Another Crossover Example) 𝜹 𝟏, 𝟏 , 𝜹 𝟏, 𝟐 , 𝜹 𝟏, 𝟑 , 𝜹 𝟏, 𝟒 , 𝜹 𝟐, 𝟏 , 𝜹 𝟐, 𝟐 , 𝜹 𝟐, 𝟑 , 𝜹 𝟐, 𝟒 𝒊 𝒋 𝒄 𝒊, 𝒋 𝜹 𝒊, 𝒋 Sol 1 𝟏 ,𝟎 ,𝟎 ,𝟎 ,𝟎 ,𝟏 ,𝟎 , 𝟏 𝟕 +𝟑 +𝟑 =𝟏𝟑 Sol 2 𝟎 , 𝟎 ,𝟏 ,𝟎 ,𝟎 ,𝟎 ,𝟎, 𝟏 𝟔 + 𝟑 =𝟗 Sol 3 𝟎 , 𝟎 ,𝟏 ,𝟎 ,𝟎 ,𝟏 ,𝟎, 𝟏 𝟔 + 𝟑 + 𝟑 =𝟏𝟐 Sol 4 𝟏 , 𝟎 ,𝟎 ,𝟎 ,𝟎 ,𝟎 ,𝟎, 𝟏 𝟕 + 𝟑 = 𝟏𝟎 Sol 5 Sol 6 𝟎 ,𝟎 ,𝟏 ,𝟎 ,𝟎 ,𝟏 ,𝟎 , 𝟏 𝟔 + 𝟑 + 𝟑 = 𝟏𝟐 Sol 7 𝟏 , 𝟎 , 𝟎,𝟏 ,𝟎 ,𝟎 ,𝟎, 𝟏 invalid as 4 channel is allocated to more than one user (users 1 and 2) so, this solution is not valid and discarded Sol 8 𝟎 ,𝟎 ,𝟎 ,𝟎 ,𝟎 ,𝟏 ,𝟎 , 𝟏 invalid as there is no channel allocated to user 1 so, this solution is not valid and discarded
Genetics Algorithm (mutation example) 𝜹 𝟏, 𝟏 , 𝜹 𝟏, 𝟐 , 𝜹 𝟏, 𝟑 , 𝜹 𝟏, 𝟒 , 𝜹 𝟐, 𝟏 , 𝜹 𝟐, 𝟐 , 𝜹 𝟐, 𝟑 , 𝜹 𝟐, 𝟒 𝒊 𝒋 𝒄 𝒊, 𝒋 𝜹 𝒊, 𝒋 Sol 1 𝟏 ,𝟎 ,𝟎 ,𝟎 ,𝟎 ,𝟏 ,𝟎 , 𝟏 𝟕 +𝟑 +𝟑 =𝟏𝟑 Sol 2 𝟎 , 𝟎 ,𝟏 ,𝟎 ,𝟎 ,𝟎 ,𝟎, 𝟏 𝟔 + 𝟑 =𝟗 Sol 3 𝟎 , 𝟎 ,𝟏 ,𝟎 ,𝟎 ,𝟏 ,𝟎, 𝟏 𝟔 + 𝟑 + 𝟑 =𝟏𝟐 Sol 4 𝟏 , 𝟎 ,𝟎 ,𝟎 ,𝟎 ,𝟎 ,𝟎, 𝟏 𝟕 + 𝟑 = 𝟏𝟎 Sol 5 Sol 6 𝟎 ,𝟎 ,𝟏 ,𝟎 ,𝟎 ,𝟏 ,𝟎 , 𝟏 𝟔 + 𝟑 + 𝟑 = 𝟏𝟐 Sol 7 𝟏 , 𝟎 , 𝟎,𝟏 ,𝟎 ,𝟎 ,𝟎, 𝟏 invalid as 4 channel is allocated to more than one user (users 1 and 2) so, this solution is not valid and discarded Sol 8 𝟎 ,𝟎 ,𝟎 ,𝟎 ,𝟎 ,𝟏 ,𝟎 , 𝟏 invalid as there is no channel allocated to user 1 so, this solution is not valid and discarded Sol 9 𝟏 , 𝟏 ,𝟎 ,𝟎 ,𝟎 ,𝟎 ,𝟎, 𝟏 𝟕+ 𝟓 + 𝟑 = 𝟏𝟓 Sol 10 𝟏 ,𝟎 ,𝟏 ,𝟎 ,𝟎 ,𝟏 ,𝟎 , 𝟏 𝟕 + 𝟔 + 𝟑 + 𝟑 = 𝟏𝟗