def example3(): player1 = pyopr.Player('足球前锋', strategies=['朝左踢', '右']) player2 = pyopr.Player('守门员', strategies=['朝左扑', '右']) players = [player1, player2] A = np.array([[-1, 1], [1, -1]]) game = pyopr.MatrixGame(A, players) template = '用图解法计算矩阵对策{{game}}的最优混合策略.' parameter = {'game': game} return MatrixGameProblem(template, parameter)
def example2(): player1 = pyopr.Player('受方', strategies=['躲开', '不躲']) player2 = pyopr.Player('攻方', strategies=['不进攻', '进攻', '佯攻']) players = [player1, player2] A = np.array([[-1, 3, -2], [2, -4, 3]]) game = pyopr.MatrixGame(A, players) template = '用图解法计算矩阵对策 (“你攻我受”博弈) {{game}}的最优混合策略.' parameter = {'game': game} return MatrixGameProblem(template, parameter)
def example1(): player1 = pyopr.Player('下属', strategies=['欺瞒', '坦诚']) player2 = pyopr.Player('上司', strategies=['检查', '不检查', '恐吓']) players = [player1, player2] A = np.array([[-5, 2, 3], [2, -1, -2]]) game = pyopr.MatrixGame(A, players) game.fraction = True template = '用图解法计算矩阵对策 (“上有政策下有对策”博弈) {{game}}的最优混合策略.' parameter = {'game': game} return MatrixGameProblem(template, parameter)
def example3(criterion=pyopr.Criterion('maximin')): template = '给定买保险决策表 (数值代表去掉保费后的保险收益) {{table}}, 根据{{criterion}}, 给出最优方案.' decisionMaker = pyopr.Player( '旅客', strategies=['不买保险', '买医疗保险', '买死亡保险', '双保险']) states = ['平安', '伤残', '死亡'] matrix = np.array([[0, -100, -1000], [-10, -1, -1010], [-100, -100, -50], [-110, -1, -60]]) model = pyopr.DecisionModel(matrix, decisionMaker, states) parameter = {'table': model, 'criterion': criterion, 'matrix': matrix} return DecisionProblem(template, parameter)
def example2(criterion=pyopr.Criterion('maximin')): template = '给定炒股决策表 (数值代表股票收益) {{table}}, 根据{{criterion}}, 给出最优方案.' decisionMaker = pyopr.Player('巴菲特', strategies=['重仓', '加仓', '减仓', '全抛']) states = ['大涨', '小涨', '横盘', '小跌', '大跌'] matrix = np.array([[100, 10, 0, -10, -100], [20, 5, 0, -5, 20], [10, 1, 0, -1, -10], [-2, -1, 0, 0, 0]]) model = pyopr.DecisionModel(matrix, decisionMaker, states) parameter = {'table': model, 'criterion': criterion, 'matrix': matrix} return DecisionProblem(template, parameter)
def example(criterion=pyopr.Criterion('maximin')): matrix = np.array([[-100, -50, 0, 100, 200], [-50, -20, 10, 50, 90], [0, 0, -10, -20, -40], [100, 80, 40, 40, 20]]) template = '之江老师在学校附近购买住房后准备装修. 给定决策表 (数值代表收益估计) {{table}}, 根据{{criterion}}, 给出最优方案.' decisionMaker = pyopr.Player('之江老师', strategies=['精装', '简装', '不装', '卖房']) states = ['只工作一年', '两年', '三年', '四年', '五年'] model = pyopr.DecisionModel(matrix, decisionMaker, states) parameter = {'table': model, 'criterion': criterion, 'matrix': matrix} return DecisionProblem(template, parameter)