2

I have following pseudocode: http://i.imgur.com/ls6NECn.png?1

7: We create an array with bool values (apparently, this is not explained in the paper). We assign the current value (value = index) "true"

18: At this point, we could have an array, where all values could be "true" and reached the condition of k = len(parents) 19-22: This would create an infinite loop

Am I missing something?

Paper: Multi-parent extension of partially mapped crossover for combinatorial optimization problems. Chuan-Kang Tinga, , , Chien-Hao Sub, , Chung-Nan Leeb,

http://www.sciencedirect.com/science/article/pii/S0957417409006800

//EDIT: HERE GOES MY CODE PYTHON-2.6

def MappingListDetermination(parents):
    mapping_list = []
    startparent = parents[random.sample(xrange(0, len(parents)), 1)[0]]
    ptr = random.sample(xrange(0, len(startparent)), 1)[0]
    temp_value = startparent[ptr]
    boolean = [False] * listSize
    for j in xrange(0,len(startparent)):
        mapping_list.append(temp_value)
        boolean[temp_value-1] = True
        arr = random.sample(xrange(0, n), n)
        if arr[0] == parents.index(startparent):
          arr[0] = arr[random.sample(xrange(1, len(arr)), 1)[0]]
        endparent = parents[arr[0]]
        ptr = endparent.index(temp_value)
        k = 0
        while((boolean[startparent[ptr]-1] is True) and (k is not len(parents)-1)):
            k = k + 1           
            startparent = parents[arr[k]]
        if((boolean[startparent[ptr]-1] is True) and (k is len(parents)-1)):
            while(boolean[startparent[ptr]-1] is True ):
                startparent = parents[random.sample(xrange(0, len(parents)), 1)[0]]
                ptr = startparent[random.sample(xrange(0, len(startparent)), 1)[0]]-1
        temp_value = startparent[ptr]ere
gestalt
  • 61
  • 4

1 Answers1

2

I just downloaded a copy of the paper and skimmed over it. It does look interesting but you are correct that boolean isn't defined. In context, it seems to be an array whose length is the number of parents which keeps track of which parents have been chosen at a particular stage in the algorithm. Thus -- it starts with all entries false and after line 7 in the pseudocode only one entry is true -- thus there is no danger of an infinite loop (given that there are at least three parents).

As pseudocode goes -- this isn't very useful. I would recommend almost ignoring the pseudocode and concentrating instead on the surrounding discussion and diagrams and try to implement it using a language like Python where you should be able to get a working function which is shorter than the article`s pseudocode.

John Coleman
  • 51,337
  • 7
  • 54
  • 119
  • So I posted my python code and spotted one mistake instantly. My 'boolean' array had the size of an individual parent rather than the size of 'parents'. I am still a bit confused. I thought parents[startparent, ptr] is an access of the parents array on one element and on a specific chromosome in that element. Like you would do in a 2D Array e.g array[val1][val2]. So temp_value would be the chromosome value which ranges from 1-9 which could result in an out-of-bound exception at line 7 in some point. – gestalt Dec 31 '15 at 15:35