Comments (2)
In the following script, we restrict each team to play in each stadium at most once every 3 rounds. Thats comes pretty close to what you want. Exactly matching your requirements is probably not possible at the moment.
import sys
sys.path.append('../src')
from pyschedule import Scenario, solvers, plotters, alt
n_teams = 8
n_stadiums = n_teams
n_slots = n_teams-1
S = Scenario('sports_scheduline',horizon=n_slots)
Stadiums = S.Resources('S',num=n_stadiums)
Teams = S.Resources('T',num=n_teams)
Games = list()
for T1 in Teams:
count = 1
for T2 in Teams:
if str(T1) >= str(T2):
continue
Game = S.Task('%s%s'%(T1,T2),completion_time_cost=2**count)
Game['team_%s'%str(T1)] = 1
Game['team_%s'%str(T2)] = 1
Games.append(Game)
count += 1
Game += T1, T2
Game += alt(Stadiums)
for Stadium in Stadiums:
for T in Teams:
S += Stadium['team_%s'%T][0:n_slots:3] <= 1
print(S)
#print(S)
solvers.mip.solve(S,time_limit=600,msg=1)
plotters.matplotlib.plot(S,show_task_labels=True,img_filename='tmp.png')
from pyschedule.
Here might be a better solution for 10 teams:
- each team plays at least 4 times at home (in the Stadium with the same number)
- in at most 3 consecutive rounds it doesnt play at home (this includes not playing at all, which is not exactly your requirement, but its pretty close). This is the minimum such that still a solution exists. I also allow a game only happening in one of the two stadiums of the participating teams. This makes finding a solution much easier and is probably also a requirement.
from pyschedule import Scenario, solvers, plotters, alt
n_teams = 10
n_stadiums = n_teams
n_slots = n_teams-1
n_plays_at_home = 4
max_n_not_at_home_periods = 3
S = Scenario('sports_scheduline',horizon=n_slots)
Stadiums = S.Resources('Stadium',num=n_stadiums)
Teams = S.Resources('T',num=n_teams)
Team2Stadium = dict(zip(Teams,Stadiums))
Games = list()
for Team0 in Teams:
count = 1
for Team1 in Teams:
if Team0.name >= Team1.name:
continue
Game = S.Task('%s%s'%(Team0,Team1),completion_time_cost=2**count)
Game[Team0.name] = 1
Game[Team1.name] = 1
Games.append(Game)
Game += Team0, Team1
Game += Team2Stadium[Team0] | Team2Stadium[Team1]
count += 1
for Team in Team2Stadium:
Stadium = Team2Stadium[Team]
S += Stadium[Team.name] >= n_plays_at_home
S += Stadium[Team.name][0:n_slots:max_n_not_at_home_periods] >= 1
print(S)
solvers.mip.solve(S,time_limit=600,msg=1)
plotters.matplotlib.plot(S,show_task_labels=True,hide_resources=Teams)
Note that i am hiding the Team resources in the following plot, the Stadiums are the interesting ones:
from pyschedule.
Related Issues (20)
- Assign task length depending on the resource HOT 1
- Annoucement: ProcessScheduler
- TypeError: unsupported operand type(s) for %: 'Task' and 'Resource'
- Py
- Assign Task to any couple of Resources HOT 1
- Python 3.8 : ImportError: cannot import name 'clock' from 'time' HOT 1
- += to Assign Task to Resource Not Working HOT 1
- Optimal solution HOT 3
- Assign any of 2 resources to a task HOT 1
- Restrict resources end time HOT 1
- plans for pyschedule HOT 4
- ImportError: cannot import name 'clock' from 'time' HOT 1
- Flexible Resources
- Different resource cost for different time periods?
- "length cost" by resource / task
- maintenance tasks in industry - BREAK
- Bug when using .diff together with blocking a ressource
- Theres any way to do the Inverse Problem?
- No module named 'pulp.solvers' HOT 2
- pyschedule only works with PuLP 2.0
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pyschedule.