Beispiel #1
0
def main():
    fileName = input('Enter file name : ')
    # Used variables
    pawnAmountBW = {'WHITE': 0, 'BLACK': 0}  # number of pawns for each side
    dataSplitted = []
    readFile(fileName, dataSplitted)  # parse user's input into array

    # Algorithms option
    print("Choose Algorithm By Input The Number :")
    print("1. Hill Climbing")
    print("2. Simulated Annealing")
    print("3. Genetic Algorithm")
    chosenAlgo = int(input("Choose : "))
    while (chosenAlgo > 3 or chosenAlgo < 1):
        print("Choose The Correct Number Please...")
        chosenAlgo = int(input("Choose : "))

    # Execute the chosen algorithm
    if (chosenAlgo == 1):
        state = parseState(dataSplitted,
                           pawnAmountBW)  # generate an initial state
        result = hillClimbing(state, pawnAmountBW)
    elif (chosenAlgo == 2):
        temperature = int(input('Temperature: '))
        decreaseRate = int(input('Decrease Rate: '))
        iteration = int(input('Maximum Iteration: '))
        state = parseState(dataSplitted,
                           pawnAmountBW)  # generate an initial state
        result = simulatedAnnealing(state, pawnAmountBW, temperature,
                                    decreaseRate, iteration)
    elif (chosenAlgo == 3):
        populationAmount = int(input('Number Of Population: '))
        limit = int(input('Maximum generation: '))
        listOfStates = createListOfStates(dataSplitted, pawnAmountBW,
                                          populationAmount)
        result = geneticAlgorithm(listOfStates, pawnAmountBW, populationAmount,
                                  limit)

    # Print the result
    attackNum = countAtack(
        result)  # Get the number of attack from the result state
    printBoard(result)
    print(attackNum['friend'], end='')
    print(' ', end='')
    print(attackNum['enemy'])
Beispiel #2
0
from hillClimbing import hillClimbing  # 引入爬山演算法類別
from solutionVirginia import SolutionNumber  # 引入平方根解答類別

# 執行爬山演算法 (從「解答=0.0」開始尋找, 最多十萬代、失敗一千次就跳出。
hillClimbing(solutionVirginia(0.0), 100000, 1000)
Beispiel #3
0
from hillClimbing import hillClimbing  # 引入爬山演算法類別
from solutionEquation import SolutionEquation  # 引入平方根解答類別

# 執行爬山演算法 (最多十萬代、失敗一千次就跳出)
hillClimbing(SolutionEquation.zero(), 100000, 1000)
Beispiel #4
0
from hillClimbing import hillClimbing  # 引入爬山演算法類別
from solutionVirginia import solutionVirginia  # 引入平方根解答類別

# 執行爬山演算法 (最多十萬代、失敗一千次就跳出)。
hillClimbing(solutionVirginia([1, 1, 1]), 100000, 1000)
from hillClimbing import hillClimbing  # 引入爬山演算法類別
from solutionScheduling import SolutionScheduling  # 引入平方根解答類別

# 執行爬山演算法 (最多3萬代、失敗一千次就跳出)
hillClimbing(SolutionScheduling.init(), 30000, 1000)
from hillClimbing import hillClimbing  # 引入爬山演算法類別
from solutionVirginia import SolutionVirginia  # 引入平方根解答類別
import virginia

plain = "This is a book. That is a cat. I am a boy. One of my boy go to school today."
key = [5, 2, 4]
# key = [9,3,7]
etext = virginia.encrypt(plain, key)
print('etext=', etext)
# 執行爬山演算法
s = hillClimbing(SolutionVirginia.init(etext, [0, 0, 0]), 30000, 1000)
dtext = virginia.decrypt(etext, s.v)
print('dtext=', dtext)
Beispiel #7
0
from hillClimbing import hillClimbing  # 引入爬山演算法類別
from solutionNumber import SolutionNumber  # 引入平方根解答類別

# 執行爬山演算法 (從「解答=0.0」開始尋找, 最多十萬代、失敗一千次就跳出。
hillClimbing(SolutionNumber(0.0), 100000, 1000)
Beispiel #8
0
from hillClimbing import hillClimbing # 引入爬山演算法類別
from solutionArray import SolutionArray # 引入平方根解答類別

# 執行爬山演算法 (最多十萬代、失敗一千次就跳出)。
hillClimbing(SolutionArray([1,1,1]), 100000, 1000)