# first place clinch script for KBO model kbo_models.txt; data kbo_data.txt; problem first_place_clinch; option solver cplexamp12; param pct {TEAMS} default 0; param GB {i in TEAMS} default 0; param r {i in TEAMS} default M - w[i] - l[i] - t[i]; param fpc {TEAMS} default 0; param number_of_teams_with_better_records default 0; param filename symbolic; param debug default 0; param max_wins {i in TEAMS} := w[i] + r[i]; param max_pct {i in TEAMS} := max_wins[i]/(max_wins[i]+l[i]); param threshold; param games_left_in_series default 16; param max_wins_in_scenario; param min_losses symbolic; set UNSORTED within TEAMS; set SORTED within TEAMS ordered; set CONTENDERS ordered; suffix priority IN,integer,>=0,<=9999; let {i in TEAMS, j in 0 .. max_ties} ties[i,j].priority := 2; for {team in TEAMS} { let k := team; printf "\n=================================================================\n"; printf "\nFinding FPC number for %s.\n",k; let max_ties := 1; option cplex_options 'mipdisplay=1 fraccand = 10000 fracpass = 10 mipemphasis=0'; solve; let max_ties := 10; option cplex_options 'mipdisplay=2 fraccand = 10000 fracpass = 10 mipemphasis=3 timelimit=60'; solve; if (solve_result_num < 200 || solve_result = "limit") then { let fpc[k] := total_wins[k] - w[k] + 1; let filename := k & "_fpc.txt"; printf "First Place Clinch Scenario for %s\n\n",k > (filename); if fpc[k] > r[k] then { printf "\nNo First place clinch number. Scenario written to %s\n",filename; let fpc[k] := M; # team k does not have a first-place clinch number printf "%s does not have a first-place clinch number.\n",k >> (filename); printf "Here is a scenario where %s wins all %d of their remaining games (%d total) but does not clinch first place.\n\n",k,r[k],total_wins[k] >> (filename); } else { printf "\nFirst place clinch number = %d. Scenario written to %s\n",fpc[k],filename; printf "%s must win at least %d more games (%d total) to clinch first place.\n",k,fpc[k],total_wins[k]+1 >> (filename); commands verify_kbo_first_place_clinch.txt; let number_of_teams_with_better_records := card({j in TEAMS: wpct[j] > wpct[k]}); printf "Here is a scenario where %s wins %d more games (%d total) but does not finish in first place.\n\n",k,fpc[k]-1,total_wins[k] >> (filename); } commands write_kbo_scenario.txt; } else let fpc[team] := 0; # The problem is infeasible which means that the team has clinched first place printf "\n=================================================================\n"; } printf "param fpc :=\n" >> riot_numbers.txt; printf {i in TEAMS} "%-15s\t%g\n",i,fpc[i] >> riot_numbers.txt; printf ";\n" >> riot_numbers.txt;