Decision Optimization

Decision Optimization

Delivers prescriptive analytics capabilities and decision intelligence to improve decision-making.

 View Only
Expand all | Collapse all

Scheduling Problem

  • 1.  Scheduling Problem

    Posted Sun October 29, 2017 02:39 PM

    Originally posted by: umy101


    I am trying to solve a problem where I am supposed to schedule teams in a soccer league to play each other. My two decision variables are HomeTeam[Field][Day] and AwayTeam[Field][Day]. They are allowed to take values of a number that corresponds to a team. For example, if there are 16 teams, they can take values 1..16. I am trying to figure out how I can write a constraint so each team only plays each other team once. It does not matter if they are home or away. Any help would be great!


    #ConstraintProgramming-General
    #DecisionOptimization


  • 2.  Re: Scheduling Problem

    Posted Mon October 30, 2017 04:23 AM

    Hi,

    you could start with

    using CP;

    int nbTeam=16;

    range Field=1..nbTeam;


    range Day=1..100;

    tuple game
    {
    int i;
    int j;
    }

    {game} games= {<i,j> | ordered i,j in Field};

    execute
    {
    games;
    }

    dvar int dayForGame[games] in Day;
    dvar boolean firstPlaysHome[games];

     

    subject to
    {
    forall(f in Field) allDifferent(all(g in games:(g.i==f) || (g.j==f)) dayForGame[g]);

    }

    int HomeTeam[Field][Day];
    int AwayTeam[Field][Day];

    execute
    {
    for(var g in games)
        if (firstPlaysHome[g]==1)
        {
          HomeTeam[g.i][dayForGame[g]]=g.i;    
          AwayTeam[g.i][dayForGame[g]]=g.j;    
        }
        else
        {
          HomeTeam[g.j][dayForGame[g]]=g.j;    
          AwayTeam[g.j][dayForGame[g]]=g.i;    
        }
    }

    regards


    #ConstraintProgramming-General
    #DecisionOptimization