import csv import operator import os import random import sys import time import timeit import datetime # import networkx as nx from datetime import datetime from dateutil.parser import parse from math import sqrt, pow, sin, cos, atan2, pi try: import simplejson as json except: import json from gurobipy import * # import config getTeamsOfPot = { p: [ p+str(i) for i in range(1,10) ] for p in ["A","B","C","D"] } allTeams = getTeamsOfPot['A']+getTeamsOfPot['B']+getTeamsOfPot['C']+getTeamsOfPot['D'] activeTeams= allTeams pots = getTeamsOfPot.keys() # print (pots) gamesAgainst = { (p1,p2) : 2 for p1 in pots for p2 in pots} # for p in pots: # gamesAgainst[(p,p)]=2 # for (p1,p2) in [('A','D'), ('D','A'), ('B','C'), ('C','B') ]: # gamesAgainst[(p1,p2)]=2 nMatchDays=8 # for p1 in pots: # for p2 in pots: # print (p1,p2,gamesAgainst[(p1,p2)]) # print() # print (allTeams) cntr=0 mbus = Model("Draw") possAssigns= [ (t1,t2) for t1 in allTeams for t2 in allTeams if t1!=t2] # print (possAssigns) plays = mbus.addVars(possAssigns, vtype=GRB.BINARY) for (t1,t2) in possAssigns: if t11: nSims=int(sys.argv[1]) solutions =[] solution_strings =[] for i in range(nSims): if i%10==0: print(i) cntr+=1 mbus.setObjective(quicksum([ int(100*random.random()) * plays[pa] for pa in possAssigns ])) # mbus.setObjective(quicksum([ max(0,int(pa[0][1]) - int(pa[1][1] )) * plays[pa] for pa in possAssigns ])) # print ("DRAWING !!!!") mbus.optimize() sol= [ pa for pa in possAssigns if plays[pa].x>0.9] solutions.append(sol.copy()) if debug: print ("Solution") # exit(0) print ("INPOT") for p in pots: print ("") print ("POT",p) for (t1,t2) in [(t1,t2) for (t1,t2) in sol if t1= int(0.5*gamesAgainst[(p,p2)]) ) else: for (t1,t2) in sol : if t10.9 ] # print( cal_sol) # for pa in cal_sol : # print (pa) # # print (cal.status) # print(cal.objVal) if cal.status!=2 or cal.objVal>-288: sol= [ (t1,t2) for (t1,t2) in sol if t10.9] # print (pas2_sol) showSolution= False showSolution= True if showSolution and debug: for md in mds: print (md,":") for (t1,t2,md2) in pas2_sol: # if md2==md and t11 and showSolution: newGm = [ gg for gg in solutions[-1] if gg not in solutions[-2]] # print (oldGm) # print (newGm) # print (solution_strings) print (len(set(solution_strings)) ) f = open("draw_feasibility/log_"+datetime.now().strftime("%Y%m%d_%H%M%S")+"_"+str(nSims)+".txt", "a") for s in solutions: for s2 in s: f.write(s2[0]+s2[1]) f.write("\n") f.close() print ("done" , datetime.now()-now )