【发布时间】:2021-11-09 13:26:09
【问题描述】:
提前道歉,我刚开始学习 Gekko,看看我是否可以将它用于项目。我正在尝试在玩游戏状态非常有限(50 ^ 2)和每回合选项(包括 0-10)的游戏时优化胜率。
据我了解,我可以使用m.solve() Gekko 函数来最小化我在这里设置的对手的胜率:
PLAYER_MAX_SCORE = 50 #Score player needs to win
OPPONENT_MAX_SCORE = 50 #Score opponent needs to win
#The opponent's current strategy: always roll 4 dice per turn
OPPONENT_MOVE = 4
m = GEKKO()
m.options.SOLVER = 1
"""
player_moves is a 2-d array where:
- the row represents player's current score
- the column represents opponent's current score
- the element represents the optimal move for the above game state
Thus the player's move for a game is player_moves[pScore, oScore].value.value
"""
player_moves = m.Array(m.Var, (PLAYER_MAX_SCORE, OPPONENT_MAX_SCORE), value=3, lb=0, ub=10, integer=True)
m.Obj(objective(player_moves, OPPONENT_MOVE, PLAYER_MAX_SCORE, OPPONENT_MAX_SCORE, 100))
m.solve(disp=False)
作为参考,objective 是一个函数,它根据当前玩家的行为(以player_moves 表示)返回对手的胜率。
唯一的问题是 m.solve() 只调用一次目标函数,然后立即返回 player_moves 数组中的“已解决”值(当定义 player_moves 时,这只是初始值)。我想让 m.solve() 多次调用目标函数来判断新对手的胜率是下降还是上升。
Gekko 可以做到这一点吗?或者对于这类问题我应该使用不同的库吗?
【问题讨论】:
标签: optimization gekko