March | infeasibilities

This commit is contained in:
martin 2024-03-13 09:35:38 +01:00
parent e32e3f707e
commit 75d686188d
8 changed files with 569 additions and 68 deletions

View File

@ -1023,6 +1023,7 @@ class Draw_Simulator:
travel = defaultdict(lambda:0)
coefficients = defaultdict(lambda:0)
visited_countries = defaultdict(lambda:set({}))
visited_finland = defaultdict(lambda:0)
if not infeasible:
for g in self.groups:
for p in self.pots:
@ -1037,6 +1038,8 @@ class Draw_Simulator:
else:
coefficients[t1['id']] += abs(t1['coeff']-t2['coeff'])
visited_countries[t1['id']].add(t2['country'])
if t2['country'] == 'FIN':
visited_finland[t1['id']] += 1
# blockings, breaks = self.create_schedule(sol_dict, n)
@ -1057,6 +1060,7 @@ class Draw_Simulator:
'visited_countries':{t['id']:len(visited_countries[t['id']]) for t in self.teams},
'blockings':blockings,
'breaks':breaks,
'visited_finland':visited_finland,
}
with open(f'json/{self.opponent_func.__name__}_{n}.json', 'w') as f:
@ -1108,6 +1112,16 @@ class Draw_Simulator:
'mean': round(np.mean([visited_countries[t['id']]['mean'] for t in self.teams]),2),
}
visited_finland = {
t['id']: {
'sum': np.sum([1 for s in tmp_stats.values() if s['visited_finland'][t['id']] >= 4]),
}
for t in self.teams
}
visited_finland['total'] = {
'sum': np.sum([visited_finland[t['id']]['sum'] for t in self.teams]),
}
blockings = {
t['id']: {
'mean': round(np.mean([s['blockings'][t['id']] for s in tmp_stats.values()]),3),
@ -1118,7 +1132,6 @@ class Draw_Simulator:
'sum': round(np.sum([blockings[t['id']]['mean'] for t in self.teams]),3),
}
breaks = {
t['id']: {
'mean': round(np.mean([s['breaks'][t['id']] for s in tmp_stats.values()])*0.5,3),
@ -1139,6 +1152,7 @@ class Draw_Simulator:
'travel_stats':travel_stats,
'coefficient_stats':coefficient_stats,
'visited_countries':visited_countries,
'visited_finland':visited_finland,
'blockings':blockings,
'breaks':breaks,
}
@ -1163,7 +1177,7 @@ class Draw_Simulator:
base_scenario = Scenario.objects.get(id=base_scenario_id)
scenario = copy_scenario(base_scenario,f" - {self.opponent_func.__name__} - {nSim}")
scenario.base_scenario = base_scenario
# scenario.base_scenario = base_scenario
scenario.save()
@ -1286,13 +1300,13 @@ funcs = [
scenario_id = 9529
scenario = Scenario.objects.get(id=scenario_id)
Scenario.objects.filter(base_scenario=scenario).delete()
# Scenario.objects.filter(base_scenario=scenario).delete()
stats = {}
for func in funcs:
simulator = Draw_Simulator(algorithm='XP', opponent_func = func, html_output=True,use_db=True)
nSim = 5
nSim = 1000
stats[func.__name__] = simulator.simulate(nSim)
@ -1314,14 +1328,14 @@ sol += "<table style='border:1px solid black'>\n"
sol += "<thead>\n"
sol += f"<tr><td rowspan='4'>n={nSim}</td>"
sol += f"<td colspan='{len(simulator.pots)}'>Conflicts</td>"
sol += f"<td colspan='8' rowspan='2'>Total</td>"
sol += f"<td colspan='{5*len(simulator.teams)}'>Teams</td>"
sol += f"<td colspan='9' rowspan='2'>Total</td>"
sol += f"<td colspan='{7*len(simulator.teams)}'>Teams</td>"
sol += "</tr>"
sol += "<tr>"
for p in simulator.pots:
sol += f"<td rowspan='3'>{p}</td>"
for t in simulator.teams:
sol+= f"<td colspan='7'>{t['name']}</td>"
sol+= f"<td colspan='8'>{t['name']} ({t['country']})</td>"
sol += "</tr>"
sol += "<tr>"
sol += "<td colspan='1' rowspan='2'>Cfl.</td>"
@ -1330,12 +1344,14 @@ sol += "<td colspan='2'>Coe.</td>"
sol += "<td colspan='1' rowspan='2'>Block</td>"
sol += "<td colspan='1' rowspan='2'>No Travel</td>"
sol += "<td colspan='1' rowspan='2'>Countr.</td>"
sol += "<td colspan='1' rowspan='2'>Finland.</td>"
for t in simulator.teams:
sol += "<td colspan='2' rowspan='1'>Trav.</td>"
sol += "<td colspan='2' rowspan='1'>Coe.</td>"
sol += "<td colspan='1' rowspan='2'>Block</td>"
sol += "<td colspan='1' rowspan='2'>No Travel</td>"
sol += "<td colspan='1' rowspan='2'>Countr.</td>"
sol += "<td colspan='1' rowspan='2'>Finland.</td>"
sol += "</tr>"
sol += "<tr>"
sol += "<td>M</td>"
@ -1367,6 +1383,7 @@ for func in funcs:
sol += f"<td>{stats[func.__name__]['blockings']['total']['sum']}</td>"
sol += f"<td>{stats[func.__name__]['breaks']['total']['sum']}</td>"
sol += f"<td>{stats[func.__name__]['visited_countries']['total']['mean']}</td>"
sol += f"<td>{stats[func.__name__]['visited_finland']['total']['sum']}</td>"
for t in simulator.teams:
tmean = stats[func.__name__]['travel_stats'][t['id']]['mean']
tstd = stats[func.__name__]['travel_stats'][t['id']]['std']
@ -1375,6 +1392,7 @@ for func in funcs:
blmean = stats[func.__name__]['blockings'][t['id']]['mean']
brmean = stats[func.__name__]['breaks'][t['id']]['mean']
visited = stats[func.__name__]['visited_countries'][t['id']]['mean']
visited_finland = stats[func.__name__]['visited_finland'][t['id']]['sum']
color = Draw_Simulator.heatmap_color_for(abs(tmean-ttmean)/ttmean)
sol += f"<td style='background-color:{color}'>{tmean}</td>"
color = Draw_Simulator.heatmap_color_for(abs(tstd-ttstd)/ttstd)
@ -1386,6 +1404,7 @@ for func in funcs:
sol += f"<td >{blmean}</td>"
sol += f"<td >{brmean}</td>"
sol += f"<td >{visited}</td>"
sol += f"<td >{visited_finland}</td>"
sol += "</tr>"
sol += "</tbody>\n"

View File

@ -124,7 +124,7 @@ if badExample:
mbus.addConstraint( xp.Sum(plays[( p1+str(i),p2+str(j))] for j in [4,5,6] ) ==2)
# mbus.Params.OutputFlag = 0
mbus.setControl ('outputlog', 0)
mbus.setControl ('outputlog', 1)
debug=False
@ -140,6 +140,7 @@ report_time = 0
solutions =[]
solution_strings =[]
nSims = 1
for i in range(nSims):
if i%10==0:
print(i)
@ -151,16 +152,34 @@ for i in range(nSims):
# mbus.setObjective(quicksum([ max(0,int(pa[0][1]) - int(pa[1][1] )) * plays[pa] for pa in possAssigns ]))
# print ("DRAWING !!!!")
sol = [('A1', 'A7'), ('A1', 'A9'), ('A1', 'B2'), ('A1', 'B3'), ('A1', 'C1'), ('A1', 'C2'), ('A1', 'D1'), ('A1', 'D2'), ('A2', 'A3'), ('A2', 'A4'), ('A2', 'B1'), ('A2', 'B4'), ('A2', 'C2'), ('A2', 'C3'), ('A2', 'D1'), ('A2', 'D4'), ('A3', 'A4'), ('A3', 'B3'), ('A3', 'B4'), ('A3', 'C3'), ('A3', 'C4'), ('A3', 'D2'), ('A3', 'D3'), ('A4', 'B1'), ('A4', 'B2'), ('A4', 'C1'), ('A4', 'C4'), ('A4', 'D3'), ('A4', 'D4'), ('A5', 'A8'), ('A5', 'A9'), ('A5', 'B5'), ('A5', 'B9'), ('A5', 'C8'), ('A5', 'C9'), ('A5', 'D6'), ('A5', 'D9'), ('A6', 'A7'), ('A6', 'A8'), ('A6', 'B6'), ('A6', 'B8'), ('A6', 'C5'), ('A6', 'C6'), ('A6', 'D5'), ('A6', 'D6'), ('A7', 'B5'), ('A7', 'B6'), ('A7', 'C5'), ('A7', 'C7'), ('A7', 'D7'), ('A7', 'D8'), ('A8', 'B7'), ('A8', 'B9'), ('A8', 'C8'), ('A8', 'C9'), ('A8', 'D5'), ('A8', 'D7'), ('A9', 'B7'), ('A9', 'B8'), ('A9', 'C6'), ('A9', 'C7'), ('A9', 'D8'), ('A9', 'D9'), ('B1', 'B2'), ('B1', 'B4'), ('B1', 'C2'), ('B1', 'C3'), ('B1', 'D3'), ('B1', 'D4'), ('B2', 'B3'), ('B2', 'C3'), ('B2', 'C4'), ('B2', 'D1'), ('B2', 'D3'), ('B3', 'B4'), ('B3', 'C1'), ('B3', 'C2'), ('B3', 'D2'), ('B3', 'D4'), ('B4', 'C1'), ('B4', 'C4'), ('B4', 'D1'), ('B4', 'D2'), ('B5', 'B8'), ('B5', 'B9'), ('B5', 'C6'), ('B5', 'C7'), ('B5', 'D7'), ('B5', 'D9'), ('B6', 'B7'), ('B6', 'B9'), ('B6', 'C5'), ('B6', 'C8'), ('B6', 'D5'), ('B6', 'D9'), ('B7', 'B8'), ('B7', 'C6'), ('B7', 'C8'), ('B7', 'D6'), ('B7', 'D7'), ('B8', 'C5'), ('B8', 'C9'), ('B8', 'D6'), ('B8', 'D8'), ('B9', 'C7'), ('B9', 'C9'), ('B9', 'D5'), ('B9', 'D8'), ('C1', 'C2'), ('C1', 'C4'), ('C1', 'D3'), ('C1', 'D4'), ('C2', 'C3'), ('C2', 'D1'), ('C2', 'D2'), ('C3', 'C4'), ('C3', 'D1'), ('C3', 'D3'), ('C4', 'D2'), ('C4', 'D4'), ('C5', 'C6'), ('C5', 'C8'), ('C5', 'D5'), ('C5', 'D6'), ('C6', 'C9'), ('C6', 'D7'), ('C6', 'D8'), ('C7', 'C8'), ('C7', 'C9'), ('C7', 'D7'), ('C7', 'D8'), ('C8', 'D6'), ('C8', 'D9'), ('C9', 'D5'), ('C9', 'D9'), ('D1', 'D2'), ('D1', 'D3'), ('D2', 'D4'), ('D3', 'D4'), ('D5', 'D6'), ('D5', 'D8'), ('D6', 'D9'), ('D7', 'D8'), ('D7', 'D9')]
sol2 = []
for (g1,g2) in sol:
mbus.addConstraint(plays[(g1,g2)] == 1)
mbus.addConstraint(plays[(g2,g1)] == 1)
sol2.append((g1,g2))
sol2.append((g2,g1))
# mbus.optimize()
mbus.solve()
checker_sol = mbus.getSolution(plays)
ttt = time.time()
sol= [ pa for pa in possAssigns if checker_sol[pa]>0.9]
solutions.append(sol.copy())
sol= [ pa for pa in possAssigns if checker_sol[pa]>0.9]
print(sorted(sol)==sorted(sol2))
exit()
sol = []
for (a,b) in sol2:
sol.append((a,b))
sol.append((b,a))
solutions.append(sol.copy())
report_time += time.time()-ttt
ttt = time.time()
@ -271,10 +290,11 @@ for i in range(nSims):
cal.setObjective(xp.Sum( -x[pa] for pa in x.keys() ))
# cal.Params.OutputFlag = 0
cal.setControl ('outputlog', 0)
cal.setControl ('outputlog', 1)
# cal.setControl ('presolveops', 131583)
# print ("SCHEDULING !!!!")
print ("SCHEDULING !!!!")
# cal.optimize()
cal.solve()
# cal_sol= [pa for pa in x.keys() if x[pa].x>0.9 ]

View File

@ -116,7 +116,7 @@ debug=False
now = datetime.now()
nSims=10
nSims=1
if len(sys.argv)>1:
nSims=int(sys.argv[1])
@ -153,6 +153,13 @@ for i in range(nSims):
mbus_time += time.time()-ttt
ttt = time.time()
sol= [ pa for pa in possAssigns if plays[pa].x>0.9]
sol2 = [('A1', 'A7'), ('A1', 'A9'), ('A1', 'B2'), ('A1', 'B3'), ('A1', 'C1'), ('A1', 'C2'), ('A1', 'D1'), ('A1', 'D2'), ('A2', 'A3'), ('A2', 'A4'), ('A2', 'B1'), ('A2', 'B4'), ('A2', 'C2'), ('A2', 'C3'), ('A2', 'D1'), ('A2', 'D4'), ('A3', 'A4'), ('A3', 'B3'), ('A3', 'B4'), ('A3', 'C3'), ('A3', 'C4'), ('A3', 'D2'), ('A3', 'D3'), ('A4', 'B1'), ('A4', 'B2'), ('A4', 'C1'), ('A4', 'C4'), ('A4', 'D3'), ('A4', 'D4'), ('A5', 'A8'), ('A5', 'A9'), ('A5', 'B5'), ('A5', 'B9'), ('A5', 'C8'), ('A5', 'C9'), ('A5', 'D6'), ('A5', 'D9'), ('A6', 'A7'), ('A6', 'A8'), ('A6', 'B6'), ('A6', 'B8'), ('A6', 'C5'), ('A6', 'C6'), ('A6', 'D5'), ('A6', 'D6'), ('A7', 'B5'), ('A7', 'B6'), ('A7', 'C5'), ('A7', 'C7'), ('A7', 'D7'), ('A7', 'D8'), ('A8', 'B7'), ('A8', 'B9'), ('A8', 'C8'), ('A8', 'C9'), ('A8', 'D5'), ('A8', 'D7'), ('A9', 'B7'), ('A9', 'B8'), ('A9', 'C6'), ('A9', 'C7'), ('A9', 'D8'), ('A9', 'D9'), ('B1', 'B2'), ('B1', 'B4'), ('B1', 'C2'), ('B1', 'C3'), ('B1', 'D3'), ('B1', 'D4'), ('B2', 'B3'), ('B2', 'C3'), ('B2', 'C4'), ('B2', 'D1'), ('B2', 'D3'), ('B3', 'B4'), ('B3', 'C1'), ('B3', 'C2'), ('B3', 'D2'), ('B3', 'D4'), ('B4', 'C1'), ('B4', 'C4'), ('B4', 'D1'), ('B4', 'D2'), ('B5', 'B8'), ('B5', 'B9'), ('B5', 'C6'), ('B5', 'C7'), ('B5', 'D7'), ('B5', 'D9'), ('B6', 'B7'), ('B6', 'B9'), ('B6', 'C5'), ('B6', 'C8'), ('B6', 'D5'), ('B6', 'D9'), ('B7', 'B8'), ('B7', 'C6'), ('B7', 'C8'), ('B7', 'D6'), ('B7', 'D7'), ('B8', 'C5'), ('B8', 'C9'), ('B8', 'D6'), ('B8', 'D8'), ('B9', 'C7'), ('B9', 'C9'), ('B9', 'D5'), ('B9', 'D8'), ('C1', 'C2'), ('C1', 'C4'), ('C1', 'D3'), ('C1', 'D4'), ('C2', 'C3'), ('C2', 'D1'), ('C2', 'D2'), ('C3', 'C4'), ('C3', 'D1'), ('C3', 'D3'), ('C4', 'D2'), ('C4', 'D4'), ('C5', 'C6'), ('C5', 'C8'), ('C5', 'D5'), ('C5', 'D6'), ('C6', 'C9'), ('C6', 'D7'), ('C6', 'D8'), ('C7', 'C8'), ('C7', 'C9'), ('C7', 'D7'), ('C7', 'D8'), ('C8', 'D6'), ('C8', 'D9'), ('C9', 'D5'), ('C9', 'D9'), ('D1', 'D2'), ('D1', 'D3'), ('D2', 'D4'), ('D3', 'D4'), ('D5', 'D6'), ('D5', 'D8'), ('D6', 'D9'), ('D7', 'D8'), ('D7', 'D9')]
sol = []
for (g1,g2) in sol:
sol.append((g1,g2))
sol.append((g2,g1))
solutions.append(sol.copy())
report_time += time.time()-ttt
@ -251,7 +258,7 @@ for i in range(nSims):
cal.setObjective(quicksum( -x[pa] for pa in x.keys() ))
cal.Params.OutputFlag = 0
cal.Params.OutputFlag = 1
# print ("SCHEDULING !!!!")
cal_time1 += time.time()-ttt

View File

@ -179,6 +179,13 @@ def simulate_craw_and_calendar(thread, nSimulations):
ttt = time.time()
sol= [ pa for pa in possAssigns if checker_sol[pa]>0.9]
sol2 = [('A1', 'A7'), ('A1', 'A9'), ('A1', 'B2'), ('A1', 'B3'), ('A1', 'C1'), ('A1', 'C2'), ('A1', 'D1'), ('A1', 'D2'), ('A2', 'A3'), ('A2', 'A4'), ('A2', 'B1'), ('A2', 'B4'), ('A2', 'C2'), ('A2', 'C3'), ('A2', 'D1'), ('A2', 'D4'), ('A3', 'A4'), ('A3', 'B3'), ('A3', 'B4'), ('A3', 'C3'), ('A3', 'C4'), ('A3', 'D2'), ('A3', 'D3'), ('A4', 'B1'), ('A4', 'B2'), ('A4', 'C1'), ('A4', 'C4'), ('A4', 'D3'), ('A4', 'D4'), ('A5', 'A8'), ('A5', 'A9'), ('A5', 'B5'), ('A5', 'B9'), ('A5', 'C8'), ('A5', 'C9'), ('A5', 'D6'), ('A5', 'D9'), ('A6', 'A7'), ('A6', 'A8'), ('A6', 'B6'), ('A6', 'B8'), ('A6', 'C5'), ('A6', 'C6'), ('A6', 'D5'), ('A6', 'D6'), ('A7', 'B5'), ('A7', 'B6'), ('A7', 'C5'), ('A7', 'C7'), ('A7', 'D7'), ('A7', 'D8'), ('A8', 'B7'), ('A8', 'B9'), ('A8', 'C8'), ('A8', 'C9'), ('A8', 'D5'), ('A8', 'D7'), ('A9', 'B7'), ('A9', 'B8'), ('A9', 'C6'), ('A9', 'C7'), ('A9', 'D8'), ('A9', 'D9'), ('B1', 'B2'), ('B1', 'B4'), ('B1', 'C2'), ('B1', 'C3'), ('B1', 'D3'), ('B1', 'D4'), ('B2', 'B3'), ('B2', 'C3'), ('B2', 'C4'), ('B2', 'D1'), ('B2', 'D3'), ('B3', 'B4'), ('B3', 'C1'), ('B3', 'C2'), ('B3', 'D2'), ('B3', 'D4'), ('B4', 'C1'), ('B4', 'C4'), ('B4', 'D1'), ('B4', 'D2'), ('B5', 'B8'), ('B5', 'B9'), ('B5', 'C6'), ('B5', 'C7'), ('B5', 'D7'), ('B5', 'D9'), ('B6', 'B7'), ('B6', 'B9'), ('B6', 'C5'), ('B6', 'C8'), ('B6', 'D5'), ('B6', 'D9'), ('B7', 'B8'), ('B7', 'C6'), ('B7', 'C8'), ('B7', 'D6'), ('B7', 'D7'), ('B8', 'C5'), ('B8', 'C9'), ('B8', 'D6'), ('B8', 'D8'), ('B9', 'C7'), ('B9', 'C9'), ('B9', 'D5'), ('B9', 'D8'), ('C1', 'C2'), ('C1', 'C4'), ('C1', 'D3'), ('C1', 'D4'), ('C2', 'C3'), ('C2', 'D1'), ('C2', 'D2'), ('C3', 'C4'), ('C3', 'D1'), ('C3', 'D3'), ('C4', 'D2'), ('C4', 'D4'), ('C5', 'C6'), ('C5', 'C8'), ('C5', 'D5'), ('C5', 'D6'), ('C6', 'C9'), ('C6', 'D7'), ('C6', 'D8'), ('C7', 'C8'), ('C7', 'C9'), ('C7', 'D7'), ('C7', 'D8'), ('C8', 'D6'), ('C8', 'D9'), ('C9', 'D5'), ('C9', 'D9'), ('D1', 'D2'), ('D1', 'D3'), ('D2', 'D4'), ('D3', 'D4'), ('D5', 'D6'), ('D5', 'D8'), ('D6', 'D9'), ('D7', 'D8'), ('D7', 'D9')]
sol = []
for (g1,g2) in sol:
sol.append((g1,g2))
sol.append((g2,g1))
solutions.append(sol.copy())
report_time += time.time()-ttt
@ -294,7 +301,7 @@ def simulate_craw_and_calendar(thread, nSimulations):
cal.setObjective(xp.Sum( -x[pa] for pa in x.keys() ))
# cal.Params.OutputFlag = 0
cal.setControl ('outputlog', 0)
cal.setControl ('outputlog', 1)
cal.setControl ('presolve', 0)
# print ("SCHEDULING !!!!")
@ -322,6 +329,7 @@ def simulate_craw_and_calendar(thread, nSimulations):
print ("Tested " , str(i+1) , " calendars" )
print("Status",cal.getProbStatus(),f"{cal.getProbStatus()}")
print("Solution",cal.getObjVal())
exit()
# pas2_sol= [ pas for pas in pas2 if cal.getSolution(x[pas])>0.9]
# print (pas2_sol)
@ -346,6 +354,7 @@ def simulate_craw_and_calendar(thread, nSimulations):
print ("Tested " , str(i+1) , " calendars" )
print("Status",cal.getProbStatus(),f"{cal.getProbStatus()}")
print("Solution",cal.getObjVal())
exit()
# print (solutions)
# oldGm = [ gg for gg in solutions[1] if gg not in solutions[0]]
@ -362,12 +371,13 @@ def simulate_craw_and_calendar(thread, nSimulations):
n = sys.maxsize
# n = 1000
n = 1
pool = Pool()
result = {}
answer = {}
# threads = cpu_count()//2
threads = 10
threads = 1
for cpu in range(threads):
result[cpu] = pool.apply_async(simulate_craw_and_calendar, args=(f'thread_{cpu}', n,))

View File

@ -0,0 +1,396 @@
import os, sys
from dotenv import load_dotenv
load_dotenv()
# %%
if os.environ.get('SERVER', None):
PROJECT_PATH = '/home/django/leagues/'
else:
PROJECT_PATH = '/home/md/Work/ligalytics/leagues_stable/'
import os, sys
import json
from numpyencoder import NumpyEncoder
sys.path.insert(0, PROJECT_PATH)
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "leagues.settings")
os.environ["DJANGO_ALLOW_ASYNC_UNSAFE"] = "true"
from leagues import settings
# settings.DATABASES['default']['NAME'] = PROJECT_PATH+'/db.sqlite3'
if os.environ.get('SERVER', None):
settings.DATABASES['default']['ENGINE'] = 'django.db.backends.postgresql'
settings.DATABASES['default']['HOST'] = '0.0.0.0'
settings.DATABASES['default']['PORT'] = '5433'
settings.DATABASES['default']['USER'] = 'leagues_user'
settings.DATABASES['default']['PASSWORD'] = 'ligalytics'
settings.DATABASES['default']['NAME'] = 'prod_16'
else:
settings.DATABASES['default']['NAME'] = PROJECT_PATH+'/db.sqlite3'
settings.DATABASES['default']['ENGINE'] = 'django.db.backends.postgresql'
settings.DATABASES['default']['HOST'] = '0.0.0.0'
settings.DATABASES['default']['PORT'] = '5432'
settings.DATABASES['default']['USER'] = 'postgres'
settings.DATABASES['default']['PASSWORD'] = 'secret123'
settings.DATABASES['default']['NAME'] = 'mypgsqldb'
settings.DATABASES['default']['ATOMIC_REQUESTS'] = False
settings.DATABASES['default']['AUTOCOMMIT'] = True
settings.DATABASES['default']['CONN_MAX_AGE'] = 0
settings.DATABASES['default']['CONN_HEALTH_CHECKS'] = False
settings.DATABASES['default']['OPTIONS'] = {}
os.environ["XPRESSDIR"] = "/opt/xpressmp"
os.environ["XPRESS"] = "/opt/xpressmp/bin"
os.environ["LD_LIBRARY_PATH"] = os.environ["XPRESSDIR"] + "/lib"
os.environ["DYLD_LIBRARY_PATH"] = os.environ["XPRESSDIR"] + "/lib"
os.environ["SHLIB_PATH"] = os.environ["XPRESSDIR"] + "/lib"
os.environ["LIBPATH"] = os.environ["XPRESSDIR"] + "/lib"
os.environ["PYTHONPATH"] = os.environ["XPRESSDIR"] + "/lib"
os.environ["CLASSPATH"] = os.environ["XPRESSDIR"] + "/lib/xprs.jar"
os.environ["CLASSPATH"] = os.environ["XPRESSDIR"] + "/lib/xprb.jar" + os.pathsep + os.environ["CLASSPATH"]
os.environ["CLASSPATH"] = os.environ["XPRESSDIR"] + "/lib/xprm.jar" + os.pathsep + os.environ["CLASSPATH"]
os.environ["PATH"] = os.environ["XPRESSDIR"] + "/bin" + os.pathsep + os.environ["PATH"]
import django
django.setup()
from scheduler.models import *
import pulp
from pulp import lpSum, value, XPRESS_PY, GUROBI, PULP_CBC_CMD, XPRESS_PY
from django.db.models import Q
from django.template.loader import render_to_string
from qualifiers.models import *
from common.models import GlobalTeam, GlobalCountry
from scheduler.models import Season, Scenario, Team, DayObj, CountryClash, Country
from qualifiers.draws import groupTeams, optimize_inversions4
from scheduler.solver.tasks.optimize import optimize
from scheduler.solver.tasks.optimize_submodels import ueluecl24_basicmodell_v2
from scheduler.solver.tasks.optimize_specialmodels import uefa24_conflicts
import random
import time
import json
import csv
import networkx as nx
import matplotlib.pyplot as plt
from datetime import timedelta
from collections import defaultdict
from django.contrib.sessions.models import Session
import xpress as xp
scenario = Scenario.objects.get(id=9704)
season = scenario.season
s2 = scenario.id
user_name = 'md'
user_is_staff = True
runMode = 'New'
localsearch_time = 0
# runMode = "Improve"
# localsearch_time = 60
RUN_ENV = 'local'
SOLVER = 'xpress'
partial_solution = []
scenario_id = s2
solver = SOLVER
# partial_solution = optimize(task=None, s2=s2, user_name=user_name, user_is_staff=user_is_staff,
# runMode=runMode, localsearch_time=localsearch_time, RUN_ENV=RUN_ENV, solver=SOLVER)
# ucl_home, ucl_away, uel_team_ids, uecl_team_ids, all_rounds, ucl_rounds, uel_rounds, uecl_rounds, getDateByIso, home_dict, away_dict, viol_dict, team_pairing, team_pairing_ids = uefa24_conflicts(scenario.id)
# class Struct:
# def __init__(self, **entries):
# self.__dict__.update(entries)
# games= [
# "A1 Sevilla FC (ESP) ESP A9 FC Internazionale Milano (ITA) ITA",
# "A1 Sevilla FC (ESP) ESP B5 Borussia Dortmund (GER) GER",
# "A1 Sevilla FC (ESP) ESP C8 Atalanta BC (ITA) ITA",
# "A1 Sevilla FC (ESP) ESP D7 Newcastle United FC (ENG) ENG",
# "A2 FC Barcelona (ESP) ESP A3 Manchester United (ENG) ENG",
# "A2 FC Barcelona (ESP) ESP B1 Arsenal FC (ENG) ENG",
# "A2 FC Barcelona (ESP) ESP C1 GNK Dinamo (CRO) CRO",
# "A2 FC Barcelona (ESP) ESP D3 Royal Antwerp FC (BEL) BEL",
# "A3 Manchester United (ENG) ENG A4 FC Bayern München (GER) GER",
# "A3 Manchester United (ENG) ENG B4 RB Leipzig (GER) GER",
# "A3 Manchester United (ENG) ENG C3 Rangers FC (SCO) SCO",
# "A3 Manchester United (ENG) ENG D4 Molde FK (NOR) NOR",
# "A4 FC Bayern München (GER) GER A2 FC Barcelona (ESP) ESP",
# "A4 FC Bayern München (GER) GER B2 FC Porto (POR) POR",
# "A4 FC Bayern München (GER) GER C2 S.S. Lazio (ITA) ITA",
# "A4 FC Bayern München (GER) GER D1 Real Sociedad de Fútbol (ESP) ESP",
# "A5 Real Madrid CF (ESP) ESP A6 Liverpool FC (ENG) ENG",
# "A5 Real Madrid CF (ESP) ESP B8 SL Benfica (POR) POR",
# "A5 Real Madrid CF (ESP) ESP C9 Stade Rennais FC (FRA) FRA",
# "A5 Real Madrid CF (ESP) ESP D2 RC Lens (FRA) FRA",
# "A6 Liverpool FC (ENG) ENG A7 Paris Saint-Germain (FRA) FRA",
# "A6 Liverpool FC (ENG) ENG B6 FC Shakhtar Donetsk (UKR) UKR",
# "A6 Liverpool FC (ENG) ENG C7 Feyenoord (NED) NED",
# "A6 Liverpool FC (ENG) ENG D6 Celtic FC (SCO) SCO",
# "A7 Paris Saint-Germain (FRA) FRA A5 Real Madrid CF (ESP) ESP",
# "A7 Paris Saint-Germain (FRA) FRA B7 Club Atlético de Madrid (ESP) ESP",
# "A7 Paris Saint-Germain (FRA) FRA C4 AC Milan (ITA) ITA",
# "A7 Paris Saint-Germain (FRA) FRA D5 PFC Ludogorets 1945 (BUL) BUL",
# "A8 Manchester City (ENG) ENG A1 Sevilla FC (ESP) ESP",
# "A8 Manchester City (ENG) ENG B3 SSC Napoli (ITA) ITA",
# "A8 Manchester City (ENG) ENG C5 F.C. Copenhagen (DEN) DEN",
# "A8 Manchester City (ENG) ENG D9 1. FC Union Berlin (GER) GER",
# "A9 FC Internazionale Milano (ITA) ITA A8 Manchester City (ENG) ENG",
# "A9 FC Internazionale Milano (ITA) ITA B9 FC Salzburg (AUT) AUT",
# "A9 FC Internazionale Milano (ITA) ITA C6 FK Crvena zvezda (SRB) SRB",
# "A9 FC Internazionale Milano (ITA) ITA D8 Olympique de Marseille (FRA) FRA",
# "B1 Arsenal FC (ENG) ENG A4 FC Bayern München (GER) GER",
# "B1 Arsenal FC (ENG) ENG B3 SSC Napoli (ITA) ITA",
# "B1 Arsenal FC (ENG) ENG C4 AC Milan (ITA) ITA",
# "B1 Arsenal FC (ENG) ENG D4 Molde FK (NOR) NOR",
# "B2 FC Porto (POR) POR A3 Manchester United (ENG) ENG",
# "B2 FC Porto (POR) POR B1 Arsenal FC (ENG) ENG",
# "B2 FC Porto (POR) POR C3 Rangers FC (SCO) SCO",
# "B2 FC Porto (POR) POR D1 Real Sociedad de Fútbol (ESP) ESP",
# "B3 SSC Napoli (ITA) ITA A1 Sevilla FC (ESP) ESP",
# "B3 SSC Napoli (ITA) ITA B4 RB Leipzig (GER) GER",
# "B3 SSC Napoli (ITA) ITA C1 GNK Dinamo (CRO) CRO",
# "B3 SSC Napoli (ITA) ITA D3 Royal Antwerp FC (BEL) BEL",
# "B4 RB Leipzig (GER) GER A2 FC Barcelona (ESP) ESP",
# "B4 RB Leipzig (GER) GER B2 FC Porto (POR) POR",
# "B4 RB Leipzig (GER) GER C2 S.S. Lazio (ITA) ITA",
# "B4 RB Leipzig (GER) GER D2 RC Lens (FRA) FRA",
# "B5 Borussia Dortmund (GER) GER A6 Liverpool FC (ENG) ENG",
# "B5 Borussia Dortmund (GER) GER B8 SL Benfica (POR) POR",
# "B5 Borussia Dortmund (GER) GER C7 Feyenoord (NED) NED",
# "B5 Borussia Dortmund (GER) GER D6 Celtic FC (SCO) SCO",
# "B6 FC Shakhtar Donetsk (UKR) UKR A5 Real Madrid CF (ESP) ESP",
# "B6 FC Shakhtar Donetsk (UKR) UKR B5 Borussia Dortmund (GER) GER",
# "B6 FC Shakhtar Donetsk (UKR) UKR C9 Stade Rennais FC (FRA) FRA",
# "B6 FC Shakhtar Donetsk (UKR) UKR D8 Olympique de Marseille (FRA) FRA",
# "B7 Club Atlético de Madrid (ESP) ESP A8 Manchester City (ENG) ENG",
# "B7 Club Atlético de Madrid (ESP) ESP B9 FC Salzburg (AUT) AUT",
# "B7 Club Atlético de Madrid (ESP) ESP C8 Atalanta BC (ITA) ITA",
# "B7 Club Atlético de Madrid (ESP) ESP D9 1. FC Union Berlin (GER) GER",
# "B8 SL Benfica (POR) POR A9 FC Internazionale Milano (ITA) ITA",
# "B8 SL Benfica (POR) POR B7 Club Atlético de Madrid (ESP) ESP",
# "B8 SL Benfica (POR) POR C6 FK Crvena zvezda (SRB) SRB",
# "B8 SL Benfica (POR) POR D7 Newcastle United FC (ENG) ENG",
# "B9 FC Salzburg (AUT) AUT A7 Paris Saint-Germain (FRA) FRA",
# "B9 FC Salzburg (AUT) AUT B6 FC Shakhtar Donetsk (UKR) UKR",
# "B9 FC Salzburg (AUT) AUT C5 F.C. Copenhagen (DEN) DEN",
# "B9 FC Salzburg (AUT) AUT D5 PFC Ludogorets 1945 (BUL) BUL",
# "C1 GNK Dinamo (CRO) CRO A1 Sevilla FC (ESP) ESP",
# "C1 GNK Dinamo (CRO) CRO B2 FC Porto (POR) POR",
# "C1 GNK Dinamo (CRO) CRO C2 S.S. Lazio (ITA) ITA",
# "C1 GNK Dinamo (CRO) CRO D4 Molde FK (NOR) NOR",
# "C2 S.S. Lazio (ITA) ITA A3 Manchester United (ENG) ENG",
# "C2 S.S. Lazio (ITA) ITA B1 Arsenal FC (ENG) ENG",
# "C2 S.S. Lazio (ITA) ITA C3 Rangers FC (SCO) SCO",
# "C2 S.S. Lazio (ITA) ITA D2 RC Lens (FRA) FRA",
# "C3 Rangers FC (SCO) SCO A2 FC Barcelona (ESP) ESP",
# "C3 Rangers FC (SCO) SCO B3 SSC Napoli (ITA) ITA",
# "C3 Rangers FC (SCO) SCO C4 AC Milan (ITA) ITA",
# "C3 Rangers FC (SCO) SCO D1 Real Sociedad de Fútbol (ESP) ESP",
# "C4 AC Milan (ITA) ITA A4 FC Bayern München (GER) GER",
# "C4 AC Milan (ITA) ITA B4 RB Leipzig (GER) GER",
# "C4 AC Milan (ITA) ITA C1 GNK Dinamo (CRO) CRO",
# "C4 AC Milan (ITA) ITA D3 Royal Antwerp FC (BEL) BEL",
# "C5 F.C. Copenhagen (DEN) DEN A6 Liverpool FC (ENG) ENG",
# "C5 F.C. Copenhagen (DEN) DEN B7 Club Atlético de Madrid (ESP) ESP",
# "C5 F.C. Copenhagen (DEN) DEN C9 Stade Rennais FC (FRA) FRA",
# "C5 F.C. Copenhagen (DEN) DEN D6 Celtic FC (SCO) SCO",
# "C6 FK Crvena zvezda (SRB) SRB A7 Paris Saint-Germain (FRA) FRA",
# "C6 FK Crvena zvezda (SRB) SRB B5 Borussia Dortmund (GER) GER",
# "C6 FK Crvena zvezda (SRB) SRB C5 F.C. Copenhagen (DEN) DEN",
# "C6 FK Crvena zvezda (SRB) SRB D5 PFC Ludogorets 1945 (BUL) BUL",
# "C7 Feyenoord (NED) NED A8 Manchester City (ENG) ENG",
# "C7 Feyenoord (NED) NED B6 FC Shakhtar Donetsk (UKR) UKR",
# "C7 Feyenoord (NED) NED C6 FK Crvena zvezda (SRB) SRB",
# "C7 Feyenoord (NED) NED D8 Olympique de Marseille (FRA) FRA",
# "C8 Atalanta BC (ITA) ITA A5 Real Madrid CF (ESP) ESP",
# "C8 Atalanta BC (ITA) ITA B8 SL Benfica (POR) POR",
# "C8 Atalanta BC (ITA) ITA C7 Feyenoord (NED) NED",
# "C8 Atalanta BC (ITA) ITA D9 1. FC Union Berlin (GER) GER",
# "C9 Stade Rennais FC (FRA) FRA A9 FC Internazionale Milano (ITA) ITA",
# "C9 Stade Rennais FC (FRA) FRA B9 FC Salzburg (AUT) AUT",
# "C9 Stade Rennais FC (FRA) FRA C8 Atalanta BC (ITA) ITA",
# "C9 Stade Rennais FC (FRA) FRA D7 Newcastle United FC (ENG) ENG",
# "D1 Real Sociedad de Fútbol (ESP) ESP A3 Manchester United (ENG) ENG",
# "D1 Real Sociedad de Fútbol (ESP) ESP B4 RB Leipzig (GER) GER",
# "D1 Real Sociedad de Fútbol (ESP) ESP C1 GNK Dinamo (CRO) CRO",
# "D1 Real Sociedad de Fútbol (ESP) ESP D2 RC Lens (FRA) FRA",
# "D2 RC Lens (FRA) FRA A4 FC Bayern München (GER) GER",
# "D2 RC Lens (FRA) FRA B1 Arsenal FC (ENG) ENG",
# "D2 RC Lens (FRA) FRA C3 Rangers FC (SCO) SCO",
# "D2 RC Lens (FRA) FRA D4 Molde FK (NOR) NOR",
# "D3 Royal Antwerp FC (BEL) BEL A1 Sevilla FC (ESP) ESP",
# "D3 Royal Antwerp FC (BEL) BEL B2 FC Porto (POR) POR",
# "D3 Royal Antwerp FC (BEL) BEL C2 S.S. Lazio (ITA) ITA",
# "D3 Royal Antwerp FC (BEL) BEL D1 Real Sociedad de Fútbol (ESP) ESP",
# "D4 Molde FK (NOR) NOR A2 FC Barcelona (ESP) ESP",
# "D4 Molde FK (NOR) NOR B3 SSC Napoli (ITA) ITA",
# "D4 Molde FK (NOR) NOR C4 AC Milan (ITA) ITA",
# "D4 Molde FK (NOR) NOR D3 Royal Antwerp FC (BEL) BEL",
# "D5 PFC Ludogorets 1945 (BUL) BUL A5 Real Madrid CF (ESP) ESP",
# "D5 PFC Ludogorets 1945 (BUL) BUL B6 FC Shakhtar Donetsk (UKR) UKR",
# "D5 PFC Ludogorets 1945 (BUL) BUL C8 Atalanta BC (ITA) ITA",
# "D5 PFC Ludogorets 1945 (BUL) BUL D7 Newcastle United FC (ENG) ENG",
# "D6 Celtic FC (SCO) SCO A8 Manchester City (ENG) ENG",
# "D6 Celtic FC (SCO) SCO B9 FC Salzburg (AUT) AUT",
# "D6 Celtic FC (SCO) SCO C9 Stade Rennais FC (FRA) FRA",
# "D6 Celtic FC (SCO) SCO D5 PFC Ludogorets 1945 (BUL) BUL",
# "D7 Newcastle United FC (ENG) ENG A9 FC Internazionale Milano (ITA) ITA",
# "D7 Newcastle United FC (ENG) ENG B7 Club Atlético de Madrid (ESP) ESP",
# "D7 Newcastle United FC (ENG) ENG C7 Feyenoord (NED) NED",
# "D7 Newcastle United FC (ENG) ENG D9 1. FC Union Berlin (GER) GER",
# "D8 Olympique de Marseille (FRA) FRA A6 Liverpool FC (ENG) ENG",
# "D8 Olympique de Marseille (FRA) FRA B5 Borussia Dortmund (GER) GER",
# "D8 Olympique de Marseille (FRA) FRA C5 F.C. Copenhagen (DEN) DEN",
# "D8 Olympique de Marseille (FRA) FRA D6 Celtic FC (SCO) SCO",
# "D9 1. FC Union Berlin (GER) GER A7 Paris Saint-Germain (FRA) FRA",
# "D9 1. FC Union Berlin (GER) GER B8 SL Benfica (POR) POR",
# "D9 1. FC Union Berlin (GER) GER C6 FK Crvena zvezda (SRB) SRB",
# "D9 1. FC Union Berlin (GER) GER D8 Olympique de Marseille (FRA) FRA",
# ]
# %%
GameRequirement.objects.filter(scenario=scenario).delete()
teams = Team.objects.filter(season=scenario.season,active=True)
gamereqs = []
team_ids = []
teams_from_pot = {p:teams.filter(pot=p).count() for p in range(1,5)}
home_games_agains_pot = {t:{p:0 for p in range(1,5)} for t in teams}
away_games_agains_pot = {t:{p:0 for p in range(1,5)} for t in teams}
opponents_from_same_country = {t:defaultdict(lambda:0) for t in teams}
teams = Team.objects.filter(season=scenario.season,active=True)
team_ids = []
# for game in games:
# home,away = game.split('\t')
# new_home = home[3:].split('(')[0].strip()
# new_away = away[3:].split('(')[0].strip()
# # print(new_home,new_away)
# h = teams.filter(name__icontains=new_home).first()
# a = teams.filter(name__icontains=new_away).first()
# if not a or not h:
# print(new_home,new_away)
# else:
# team_ids.append(h.id)
# team_ids.append(a.id)
# gamereqs.append((h,a))
# if (a,h) in gamereqs:
# print("DUPLICATE",h,a)
# home_games_agains_pot[h][a.pot] += 1
# away_games_agains_pot[a][h.pot] += 1
# opponents_from_same_country[h][a.country] += 1
# opponents_from_same_country[a][h.country] += 1
# GameRequirement.objects.create(scenario=scenario,team1=h,team2=a,number=1)
for file in os.listdir('counterexample'):
filename = os.fsdecode(file)
if filename.endswith(".txt"):
with open('counterexample/'+filename) as f:
print(filename)
games = f.readlines()
for i, game in enumerate(games):
parsed_game = [x.strip() for x in game.split("\t")]
new_home = parsed_game[1].split('(')[0].strip()
new_away = parsed_game[2].split('(')[0].strip()
h = teams.filter(name__icontains=new_home).first()
a = teams.filter(name__icontains=new_away).first()
if not a or not h:
print(a,h)
else:
team_ids.append(h.id)
team_ids.append(a.id)
gamereqs.append((h,a))
if (a,h) in gamereqs:
print("DUPLICATE",h,a)
home_games_agains_pot[h][a.pot] += 1
away_games_agains_pot[a][h.pot] += 1
opponents_from_same_country[h][a.country] += 1
opponents_from_same_country[a][h.country] += 1
for t in teams:
for p in range(1,5):
if home_games_agains_pot[t][p] != 1:
print("HOME",t,p)
if away_games_agains_pot[t][p] != 1:
print("AWAY",t,p)
for c in opponents_from_same_country[t]:
if opponents_from_same_country[t][c] >= 4:
print(t,c,opponents_from_same_country[t][c])
# MODEL WITH HOME
model = xp.problem(name='HomeAssignments', sense=xp.minimize)
rounds = range(1,9)
x = {}
home = {}
for r in rounds:
for (t1,t2) in gamereqs:
x[r,t1.id,t2.id] = xp.var(vartype=xp.binary, name='x_{}_{}_{}'.format(r,t1.id,t2.id))
model.addVariable(x)
# each game has to be played
for (t1,t2) in gamereqs:
model.addConstraint(xp.Sum([x[r,t1.id,t2.id] for r in rounds]) == 1)
# each team has to play once in each round
for t in teams:
for r in rounds:
model.addConstraint(xp.Sum([x[r,t.id,t2.id] for t2 in teams if (r,t.id,t2.id) in x.keys()])+xp.Sum([x[r,t2.id,t.id] for t2 in teams if (r,t2.id,t.id) in x.keys()]) == 1)
model.solve()
print ("model.getProbStatus() ",model.getProbStatus() )
if model.getProbStatus() != 5:
print("SOLUTION FOUND")
for r in rounds:
for (t1,t2) in gamereqs:
if model.getSolution(x[r,t1.id,t2.id]) > 0.9:
print(r,t1,t2)
if model.getSolution(x[r,t2.id,t1.id]) > 0.9:
print(r,t2,t1)
print("\n\n\n")
# %%

View File

@ -56,7 +56,7 @@ import matplotlib.pyplot as plt
from django.contrib.sessions.models import Session
scenario = Scenario.objects.get(id=9360)
scenario = Scenario.objects.get(id=9704)
@ -71,7 +71,7 @@ localsearch_time = 60
RUN_ENV = 'local'
SOLVER = 'xpress'
teams = Team.objects.filter(season=scenario.season,active=True,conference__name="UECL").distinct()
teams = Team.objects.filter(season=scenario.season,active=True).distinct()
gamereqs = GameRequirement.objects.filter(scenario=scenario)
@ -212,69 +212,69 @@ distance = create_graph()
# comp_time = time.time()-start_time
teams = Team.objects.filter(season=scenario.season,active=True).distinct()
# teams = Team.objects.filter(season=scenario.season,active=True).distinct()
import xpress as xp
# import xpress as xp
xp.controls.outputlog = 1
model = xp.problem(name='Draws', sense=xp.minimize)
model.setControl('maxtime' , 600)
# xp.controls.outputlog = 1
# model = xp.problem(name='Draws', sense=xp.minimize)
# model.setControl('maxtime' , 600)
groups = range(1,5)
# groups = range(1,5)
x = {}
y = {}
for g in groups:
for t in teams:
x[t,g] = xp.var(vartype=xp.binary)
for gr in gamereqs:
y[gr.team1,gr.team2,g] = xp.var(vartype=xp.binary)
# x = {}
# y = {}
# for g in groups:
# for t in teams:
# x[t,g] = xp.var(vartype=xp.binary)
# for gr in gamereqs:
# y[gr.team1,gr.team2,g] = xp.var(vartype=xp.binary)
model.addVariable(x)
model.addVariable(y)
# model.addVariable(x)
# model.addVariable(y)
for t1,t2,g in y.keys():
model.addConstraint(y[t1,t2,g] >= (x[t1,g] - x[t2,g]))
model.addConstraint(y[t1,t2,g] >= (x[t2,g] - x[t1,g]))
# for t1,t2,g in y.keys():
# model.addConstraint(y[t1,t2,g] >= (x[t1,g] - x[t2,g]))
# model.addConstraint(y[t1,t2,g] >= (x[t2,g] - x[t1,g]))
for t in teams:
model.addConstraint(xp.Sum(x[t,g] for g in groups) == 1)
# for t in teams:
# model.addConstraint(xp.Sum(x[t,g] for g in groups) == 1)
for g in groups:
model.addConstraint(xp.Sum(x[t,g] for t in teams) == len(teams)/len(groups))
# for g in groups:
# model.addConstraint(xp.Sum(x[t,g] for t in teams) == len(teams)/len(groups))
model.setObjective(xp.Sum(y[key] for key in y.keys()))
# model.setObjective(xp.Sum(y[key] for key in y.keys()))
start_time = time.time()
model.solve()
comp_time = time.time()-start_time
# start_time = time.time()
# model.solve()
# comp_time = time.time()-start_time
# %%
pot = {}
group_list = {g:[] for g in groups}
for g in groups:
print("GROUP",g)
for t in teams:
if model.getSolution(x[t,g]) > 0:
print("\t",t.id)
group_list[g].append(t.id)
pot[t] = g
print("")
# # %%
# pot = {}
# group_list = {g:[] for g in groups}
# for g in groups:
# print("GROUP",g)
# for t in teams:
# if model.getSolution(x[t,g]) > 0:
# print("\t",t.id)
# group_list[g].append(t.id)
# pot[t] = g
# print("")
# %%
# # %%
# %%
# # %%
print(group_list)
# print(group_list)
# %%
# # %%
create_graph(pot)
# create_graph(pot)

View File

@ -67,7 +67,7 @@ def getVal(v):
return v.value()
scenario = Scenario.objects.get(id=9402)
scenario = Scenario.objects.get(id=9607)
hawishes = HAWish.objects.filter(scenario=scenario,prio__in=['Hard','A'])
@ -549,7 +549,7 @@ model += objective_function #+ 0.001*random_seed
with open ("basicmodel.txt", "w") as f:
f.write(model.__repr__())
model.solve(XPRESS(msg=1,maxSeconds=300, gapRel=0))
model.solve(XPRESS(msg=1,timeLimit=300, gapRel=0))
# FOR DEBUGGING

View File

@ -9,14 +9,63 @@ pre_url = 'https://uefadigitalapipre.developer.azure-api.net'
pre_primary_key = '1decf93425944f8b9e6dc7226a3b8477'
pre_secondary_key = '14771f5c67b74836a59f777cb543cc0f'
# %%
# r=requests.get("https://api.digital.uefa.com/comp/v2/competitions/1/seasons", headers={"Cache-Control":"no-cache","Ocp-Apim-Subscription-Key":"7dfa861240aa40f8a834990c24f1a66d"})
# # %%
# r.json()
# # %%
# r=requests.get("https://api.pre.digital.uefa.com/comp/v2/competitions/1/seasons", headers={"Cache-Control":"no-cache","Ocp-Apim-Subscription-Key":"14771f5c67b74836a59f777cb543cc0f"})
# # %%
# r.json()
# # %%
r=requests.get("https://api.digital.uefa.com/comp/v2/competitions/1/seasons", headers={"Cache-Control":"no-cache","Ocp-Apim-Subscription-Key":"7dfa861240aa40f8a834990c24f1a66d"})
# %%
r.json()
# %%
r=requests.get("https://api.pre.digital.uefa.com/comp/v2/competitions/1/seasons", headers={"Cache-Control":"no-cache","Ocp-Apim-Subscription-Key":"14771f5c67b74836a59f777cb543cc0f"})
data = {
"season": "UCL 24/25",
"games": [
{
"home": 50051,
"away": 52682
},
{
"home": 52747,
"away": 50051
},
{
"home": 50051,
"away": 50030
},
{
"home": 52758,
"away": 50051
},
{
"home": 50051,
"away": 50031
},
{
"home": 52336,
"away": 50051
},
{
"home": 50051,
"away": 50050
},
{
"home": 77977,
"away": 50051
}
]
}
# %%
# r=requests.post("http://localhost:8000/api/uefa/checker/",
r=requests.post("https://compute.asolvo.de/api/uefa/teams/",
headers={"Authorization": "R6v1e9Q5W8aS3b7C4x2KpZqL9yFmXnDz"},
json=data)
# %%
r.json()
# %%