population Link to heading

ID  Chromosome           Mark
000 33203301211203030213 51
001 01221300031100233201 69
002 20000003222032332201 51
003 00213002313213121102 66
004 23232120303132312133 37
005 11310023120032112133 66
006 00231133123313321221 49
007 10230203322323101313 47
008 33020313001310103312 59
009 03333211323321011332 42
010 12133030202021302200 58
011 33123100202101031233 58
012 11321133032233022301 48
013 22130223110222212300 47
014 03032221032100221312 54
015 12310333302031212112 54
016 02230003113222320121 54
017 12131002031010103110 87
018 30131113003121000320 71
019 31011132130100231133 71
020 22200300003221211213 60
021 22100332122232212300 43
022 23301312132322011312 48
023 31130133011320331300 59
024 02111311201310001033 82
025 03232103220023312110 54
026 33001220133303022231 46
027 00122032220223002111 60
028 21211000011030020032 79
029 03022120313032130110 64
030 00231000003002333032 47
031 11333331122013213232 43
032 01331221310322100203 60
033 12310330313033331210 49
034 00013000323030233200 47
035 31311110131132330221 65
036 32211313102111203033 60
037 33112110332210020220 60
038 13330120330013012223 51
039 31223112320020003120 60
040 23021211102133230301 60
041 23012022312230323221 37
042 21212211320031123310 58
043 03120201300111012003 79
044 23120231231303122303 43
045 30010120300302022123 62
046 23113212333010310313 53
047 11230013022332010011 71
048 02222110100210031002 77
049 33233212000333123022 35
050 23002302220212320323 37
051 31220131231033321333 42
052 33003230122023020122 47
053 23213311122200333223 37
054 10100132200011030321 79
055 01213210002001332210 71
056 20122223020000201021 66
057 03111311210112001022 79
058 12013021023100101120 83
059 03221210033323311202 48
060 31301231222203303210 48
061 00323100311022103220 64
062 10001023211133131312 71
063 13001223231030012333 51
064 33101300030132321222 53
065 22200000211021200220 71
066 12103030231212313011 66
067 10013233001113000210 76
068 23232313100301103231 53
069 23020332132230232212 32
070 11002323021101202020 71
071 31310131123211331101 71
072 13311322322111200130 60
073 31110022331230000112 71
074 00030211102231230331 64
075 20101020303113303020 63
076 01122030121102202102 69
077 33212321003203301033 44
078 10130100032021123021 76
079 00223301211032313012 60
080 13113211332013332112 54
081 12000220110311031002 82
082 30333301201023200103 51
083 13033303220233230130 36
084 33121103020231223212 48
085 20220213032300200313 51
086 12130132231021030201 66
087 13310220212033313130 53
088 11110001210331021110 92
089 12032120211331330103 60
090 03212223111213003110 65
091 32210020332333221310 42
092 31012212223322001310 54
093 10233023302021333101 51
094 13120200210303301023 62
095 31332301203311302131 53
096 11333002102331333003 46
097 22222220333301020323 31
098 02111233303332030020 49
099 11121201113331230200 71

quiz Link to heading

Previous data is refered in an Edunex quiz

Then a multiple choice question is given

Kunjungi https://dudung.github.io/lecture-notes/0074/ untuk melihat populasi yang ada.

Tentukan individu atau kromosom yang bernilai paling besar.

with its choices are as follow (without the marking value)

1,'10111012301230123012',76
2,'21230123011101230123',65
3,'33330123011101230000',63
4,'01230123011101210123',76
5,'23332113011121230000',65
6,'33330110111101230000',76
7,'23330110111101200000',84
8,'03030110111101200100',88
9,'03110110111101200100',94
10,'13110110113101200101',94
11,'10111012301230123012',76
12,'11230123011101230123',71
13,'13330123011101230000',71
14,'11230123011101210123',74
15,'33332113011121230000',64
16,'33330110111101230000',76
17,'23330110111101200000',84
18,'33030110111101200100',87
19,'03110110111101200100',94
20,'13110110113101200101',94
21,'20111012301230123012',71
22,'21230123011101230123',65
23,'23330123011101230000',67
24,'01230123011101210123',76
25,'03332113011121230000',69
26,'03330110111101230000',79
27,'03330110111101200000',82
28,'03030110111101200100',88
29,'13110110111101200100',92
30,'13110110113101200101',94
31,'30111012301230123012',71
32,'01230123011101230123',71
33,'03330123011101230000',68
34,'11230123011101210123',74
35,'03332113011121230000',69
36,'03330110111101230000',79
37,'03330110111101200000',82
38,'33030110111101200100',87
39,'13110110111101200100',92
40,'33110110113101200101',94
41,'03030110110101200100',83
42,'01230123012301230123',60
43,'03330123011101230123',64
44,'03332110111121230000',76
45,'33010110111101200100',94
46,'11110110111301000320',100
47,'03330110111101230000',79
48,'21110100131301000320',84
49,'01310101131300000320',74
50,'03330110111101200000',82
51,'10111012301230123012',76
52,'11230123011101230123',71
53,'13330123011101230000',71
54,'11230123011101210123',74
55,'23332113011121230000',65
56,'23330110111101230000',79
57,'23330110111101200000',84
58,'23030110111101200100',92
59,'03110110111101200100',94
60,'03110110113101200101',100
61,'00111012301230123012',77
62,'01230123011101230123',71
63,'23330123011101230000',67
64,'21230123011101210123',69
65,'23332113011121230000',65
66,'13330110111101230000',84
67,'13330110111101200000',87
68,'03030110111101200100',88
69,'03110110111101200100',94
70,'03110110113101200101',100
71,'00111012301230123012',77
72,'21230123011101230123',65
73,'33330123011101230000',63
74,'21230123011101210123',69
75,'33332113011121230000',64
76,'03330110111101230000',79
77,'13330110111101200000',87
78,'03030110111101200100',88
79,'13110110111101200100',92
80,'03110110113101200101',100
81,'30111012301230123012',71
82,'11230123011101230123',71
83,'03330123011101230000',68
84,'31230123011101210123',71
85,'13332113011121230000',71
86,'03330110111101230000',79
87,'23330110111101200000',84
88,'33030110111101200100',87
89,'23110110111101200100',94
90,'33110110113101200101',94
91,'33030110110101200100',82
92,'21230123012301230123',54
93,'33330123011101230123',58
94,'03332110111121230000',76
95,'13010110111101200100',94
96,'11110110111301000321',94
97,'03330110111101230000',79
98,'11110100131301000320',87
99,'01310101131300000320',74
100,'13330110111101200000',87

It can be solved with cooperation of all class members.

code 1 Link to heading

def direction(g):
  if g == 0: dx = 1; dy = 0
  elif g == 1: dx = 0; dy = 1
  elif g == 2: dx = -1; dy = 0
  else: dx = 0; dy = -1
  return (dx, dy)

xi = 0; yi = 0
xf = 6; yf = 8

def evaluate(c):
  x = xi; y = yi
  for g in c:
    dx, dy = direction(g)
    x += dx;
    y += dy;

  r = math.sqrt((x - xf)**2 + (y - yf)**2)
  rs = int(100 - 4*r)
  return rs

def list2str(c):
  cs = ''.join([str(i) for i in c])
  return cs

import random as rnd
import math

print("ID  Chromosome           Mark")

M = 100
for j in range(M):
  x = xi; y = yi
  c = []
  
  N = 20
  for i in range(N):
    g = rnd.randint(0, 3)
    c.append(g)
    
    dx, dy = direction(g)
    x += dx
    y += dy
  
  js = f'{j:03d}'
  cs = list2str(c)
  rs = evaluate(c)
  print(js, cs, rs)

It also available at https://onecompiler.com/python/3znx6rtdg.

code 2 Link to heading

def direction(g):
  if g == 0: dx = 1; dy = 0
  elif g == 1: dx = 0; dy = 1
  elif g == 2: dx = -1; dy = 0
  else: dx = 0; dy = -1
  return (dx, dy)

xi = 0; yi = 0
xf = 6; yf = 8

def evaluate(c):
  x = xi; y = yi
  for g in c:
    dx, dy = direction(g)
    x += dx;
    y += dy;

  r = math.sqrt((x - xf)**2 + (y - yf)**2)
  rs = int(100 - 4*r)
  return rs

def list2str(c):
  cs = ''.join([str(i) for i in c])
  return cs

import random as rnd
import math


p = [
  [1, 0, 1, 1, 1, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2],
  [2, 1, 2, 3, 0, 1, 2, 3, 0, 1, 1, 1, 0, 1, 2, 3, 0, 1, 2, 3],
  [3, 3, 3, 3, 0, 1, 2, 3, 0, 1, 1, 1, 0, 1, 2, 3, 0, 0, 0, 0],
  [0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 1, 1, 0, 1, 2, 1, 0, 1, 2, 3],
  [2, 3, 3, 3, 2, 1, 1, 3, 0, 1, 1, 1, 2, 1, 2, 3, 0, 0, 0, 0],
  [3, 3, 3, 3, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 2, 3, 0, 0, 0, 0],
  [2, 3, 3, 3, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 2, 0, 0, 0, 0, 0],
  [0, 3, 0, 3, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 2, 0, 0, 1, 0, 0],
  [0, 3, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 2, 0, 0, 1, 0, 0],
  [1, 3, 1, 1, 0, 1, 1, 0, 1, 1, 3, 1, 0, 1, 2, 0, 0, 1, 0, 1],
  [1, 0, 1, 1, 1, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2],
  [1, 1, 2, 3, 0, 1, 2, 3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],
  [1, 3, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 2, 0, 0, 1, 0, 0],
  [1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 3, 0, 1, 0, 0, 0, 3, 2, 1],
  [0, 3, 3, 3, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 2, 3, 0, 0, 0, 0],
  [1, 1, 1, 1, 0, 1, 0, 0, 1, 3, 1, 3, 0, 1, 0, 0, 0, 3, 2, 0],
  [0, 1, 3, 1, 0, 1, 0, 1, 1, 3, 1, 3, 0, 0, 0, 0, 0, 3, 2, 0],
  [1, 3, 3, 3, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 2, 0, 0, 0, 0, 0],
]

#print("ID Chromosome           Mark")
j = 1
for c in p:
  js = f'{j:d}'
  cs = list2str(c)
  rs = evaluate(c)
  print(js, ",'", cs, "',", rs, sep="")
  j += 1

It also available at https://onecompiler.com/python/3znxfm7gc.

notes Link to heading

  • It is a random walk with 0, 1, 2, 3 directions related to N, W, S, E, the four cardinal directions.
  • Each allele is related to pair of $(\alpha, \beta)$ in the form of $(1, 0)$, $(0, 1)$, $(-1, 0)$, $(0, -1)$.
  • Current position is obtained after $N$ steps as $$\tag{1} x = x_i + \sum_{n = 1}^N \alpha_n $$ and $$\tag{2} y = y_i + \sum_{n = 1}^N \beta_n, $$ started from initial position $(x_i, y_i)$.
  • The traveled distance is simply $$\tag{3} d = \sqrt{(x - x_f)^2 + (y - y_f)^2}, $$ where the target desination position is $(x_f, y_f)$.
  • The marking point is defined as $$\tag{4} {\rm MP} = 100 - 4d. $$
  • Quiz results are not analyzed (per 1840 on 29 Sep 2023).