Пример #1
0
def evalTSPAdjacentEdges(individual):
    #if individual is not a valid adjacent representation then it is a path representation
    #we change once that individual to path representation
    if not checkIfValidAdjacent(individual):
        raise ValueError("Individual is not valid according to adjacent representation.\n", individual)
    evaluation = evalTSP(fromAdjacentToPath(individual))
    return evaluation
Пример #2
0
def evalTSPAdjacentEdges(individual):
    #if individual is not a valid adjacent representation then it is a path representation
    #we change once that individual to path representation
    if not checkIfValidAdjacent(individual):
        raise ValueError(
            "Individual is not valid according to adjacent representation.\n",
            individual)
    evaluation = evalTSP(fromAdjacentToPath(individual))
    return evaluation
Пример #3
0
def test_validAdjToPath():
    a = array.array('i', [
        19, 59, 99, 90, 92, 54, 100, 66, 9, 55, 5, 111, 112, 39, 36, 89, 23,
        20, 21, 38, 69, 105, 22, 103, 129, 95, 85, 16, 123, 12, 0, 117, 76,
        121, 18, 80, 86, 108, 41, 58, 82, 11, 49, 104, 52, 61, 65, 42, 24, 48,
        83, 27, 67, 28, 37, 57, 87, 84, 47, 96, 60, 63, 88, 94, 34, 32, 98,
        122, 109, 53, 10, 45, 126, 7, 2, 33, 101, 107, 73, 97, 119, 77, 74,
        124, 120, 8, 114, 31, 106, 81, 50, 91, 79, 44, 127, 17, 130, 64, 46,
        25, 40, 1, 78, 6, 56, 3, 128, 26, 29, 113, 62, 70, 110, 30, 75, 43,
        118, 15, 93, 51, 4, 71, 68, 116, 115, 125, 13, 72, 35, 102, 14
    ])

    assert not checkIfValidAdjacent(a)
Пример #4
0
 def wrapped(individual, indpb):
     # print 'mut from:', individual
     if not checkIfValidAdjacent(individual):
         raise ValueError('Invalid individual. Does not comply with adjacent repr.')
     # print 'individual', type(individual), individual
     indi = fromAdjacentToPath(individual)
     # print 'indi', type(indi), indi
     result = function(indi, indpb)
     # print 'result', type(result), result
     individual[:] = fromPathToAdjacent(result[0])
     # print 'individual', type(individual), individual
     # print '\n'*5
     return individual
Пример #5
0
 def wrapped(individual, indpb):
     # print 'mut from:', individual
     if not checkIfValidAdjacent(individual):
         raise ValueError(
             'Invalid individual. Does not comply with adjacent repr.')
     # print 'individual', type(individual), individual
     indi = fromAdjacentToPath(individual)
     # print 'indi', type(indi), indi
     result = function(indi, indpb)
     # print 'result', type(result), result
     individual[:] = fromPathToAdjacent(result[0])
     # print 'individual', type(individual), individual
     # print '\n'*5
     return individual
Пример #6
0
def test_validAdjToPath():
    a = array.array('i', [
        19, 59, 99, 90, 92, 54, 100, 66, 9, 55, 5, 111, 112, 39, 36,
         89, 23, 20, 21, 38, 69, 105, 22, 103, 129, 95, 85, 16, 123,
          12, 0, 117, 76, 121, 18, 80, 86, 108, 41, 58, 82, 11, 49,
          104, 52, 61, 65, 42, 24, 48, 83, 27, 67, 28, 37, 57, 87,
          84, 47, 96, 60, 63, 88, 94, 34, 32, 98, 122, 109, 53, 10,
          45, 126, 7, 2, 33, 101, 107, 73, 97, 119, 77, 74, 124, 120,
          8, 114, 31, 106, 81, 50, 91, 79, 44, 127, 17, 130, 64, 46,
          25, 40, 1, 78, 6, 56, 3, 128, 26, 29, 113, 62, 70, 110, 30,
          75, 43, 118, 15, 93, 51, 4, 71, 68, 116, 115, 125, 13, 72,
          35, 102, 14
          ])

    assert not checkIfValidAdjacent(a)