def graphReduction(matrix, simAnneal=True, startSolution=None, printFlag=True):
    matrix = resolveMatrix(matrix)
    if startSolution == None:
        startSolution = getRandom(matrix.vertices)
    if simAnneal:
        solution, fScore = simulatedannealing.simulateanneal(matrix, startSolution, printFlag)
    else:
        solution, fScore, tries = hillclimb.climbhill(matrix, strartSolution)
    return solution, fScore
Exemple #2
0
def graphReduction(matrix, simAnneal=True, startSolution=None, printFlag=True):
    matrix = resolveMatrix(matrix)
    if startSolution == None:
        startSolution = getRandom(matrix.vertices)
    if simAnneal:
        solution, fScore = simulatedannealing.simulateanneal(
            matrix, startSolution, printFlag)
    else:
        solution, fScore, tries = hillclimb.climbhill(matrix, strartSolution)
    return solution, fScore
# matrix = matrix26
# matrix = matrix8
# matrix = matrix21
# matrix = matrix4
# matrix = matrix34
# matrix = matrixBin
# matrix = matrixStar
matrix = matrixWeb
# matrix = matrix12
# matrix = matrixNoEdge # Doesn't work. Division by Zero error

randSolution = getRandom(matrix.vertices)

# STEP TWO - PICK YOUR METHOD (pick one and uncomment it)
#   METHOD ONE - SIMULATED ANNEALING
solution, fScore = simulatedannealing.simulateanneal(matrix, randSolution)

#   METHOD TWO - HILL CLIMBING
# solution, score, tries = hillclimb.climbhill(matrix, randSolution)

#   METHOD THREE - SIMULATED ANNEALING + HILL CLIMBING (uncomment both lines)
# annealSolution, fScore = simulatedannealing.simulateanneal(matrix, randSolution)
# solution, score, tries = hillclimb.climbhill(matrix, annealSolution)


print "Random Solution"
diagnose(matrix, randSolution)

print "Final Solution"
diagnose(matrix, solution)
Exemple #4
0
# matrix = matrix26
# matrix = matrix8
# matrix = matrix21
# matrix = matrix4
# matrix = matrix34
# matrix = matrixBin
# matrix = matrixStar
matrix = matrixWeb
# matrix = matrix12
# matrix = matrixNoEdge # Doesn't work. Division by Zero error

randSolution = getRandom(matrix.vertices)

# STEP TWO - PICK YOUR METHOD (pick one and uncomment it)
#   METHOD ONE - SIMULATED ANNEALING
solution, fScore = simulatedannealing.simulateanneal(matrix, randSolution)

#   METHOD TWO - HILL CLIMBING
# solution, score, tries = hillclimb.climbhill(matrix, randSolution)

#   METHOD THREE - SIMULATED ANNEALING + HILL CLIMBING (uncomment both lines)
# annealSolution, fScore = simulatedannealing.simulateanneal(matrix, randSolution)
# solution, score, tries = hillclimb.climbhill(matrix, annealSolution)

print "Random Solution"
diagnose(matrix, randSolution)

print "Final Solution"
diagnose(matrix, solution)

viz.display(matrix, randSolution)