title: Bipartite Matching with a constraint
body: <p>I am trying to get a matching between two sets of vertices, one represents meets between two teams and the other time slots when the meets could happen. The adjacency map represents both teams' availability to meet at any given time slot. This would be bipartite matching. The problem is that I want to constraint this so that any team will not be assigned to consecutive time slots, more specifically to time slots in two consecutive days.</p>
  <p>So, I've tried adding a check right before adding an edge to the match, at the end of the augmenting path, that checks the previous day's and following day's time slots, if they have been matched to a meet with any of the teams in the meet about to match. I tried it with Hopcroft-Karp and with DFS. It didn't work.</p>
  <p>Is this not bipartite matching anymore?</p>
  <p>Any help will be greatly appreciated.</p>
  <p>EDIT:</p>
  <p>As suggested in the answer below, I am trying to implement this as an integer linear program. The following code is heavily based on the example <a href="https://developers.google.com/optimization/assignment/assignment_example#java_8" rel="nofollow noreferrer">from Google OR-tools on assignment matching</a>
  As it is, it seems to work correctly for matching, but without my specified constraint.</p>
  <pre><code>// [START program]
  // [START import]
  import com.google.ortools.linearsolver.MPConstraint;
  import com.google.ortools.linearsolver.MPObjective;
  import com.google.ortools.linearsolver.MPSolver;
  import com.google.ortools.linearsolver.MPVariable;
  // [END import]
  
  /** MIP example that solves an assignment problem. */
  public class GameMatching {
      static {
          System.loadLibrary(&quot;jniortools&quot;);
      }
  
      public static void main(String[] args) {
          // Data
          // [START data_model]
          // Adjacency matrix represents which games can happen on which dates
          int[][] adj = {
            {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
            {1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0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 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
            {0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
            {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
            {0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
          };
  
          int numGames = adj.length;
          int numDates = adj[0].length;
  
          //represents which game time slots are on a given day (4 games on sundays, 2 on weekdays)
          int[][] days = {
                {0, 1, 2, 3},
                {4, 5},
                {6, 7},
                {8, 9, 10, 11},
                {12, 13},
                {14, 15},
                {16, 17},
                {18, 19},
                {20, 21, 22, 23},
                {24, 25},
                {26, 27},
                {28, 29},
                {30, 31},
                {32, 33, 34, 35},
                {36, 37},
                {38, 39},
                {40, 41},
                {42, 43},
                {44, 45, 46, 47},
                {48, 49},
                {50, 51},
                {52, 53, 54, 55},
                {56, 57},
                {58, 59},
                {60, 61},
                {62, 63},
                {64, 65, 66, 67},
                {68, 69},
                {70, 71},
                {72, 73},
                {74, 75},
                {76, 77, 78, 79}
          };
          //represents what day of the week is a day, a team can play thursday and sunday, but not sunday and monday 0 is sunday, 1 is monday...
          int[] weekDays = {0, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0};
  
          // teamToGames[i][j] represents a team i's, games j
          int[][] teamToGames = {
                {1, 3, 9, 16, 18, 26},
                {0, 8, 12, 16, 23, 28},
                {1, 5, 7, 13, 21, 27},
                {2, 5, 14, 17, 22, 26},
                {7, 15, 19, 21, 24, 28},
                {3, 10, 14, 20, 27, 29},
                {2, 6, 9, 13, 23, 29},
                {6, 8, 11, 18, 19, 25},
                {8, 4, 10, 11, 17, 24},
                {4, 12, 15, 20, 22, 25},
          };
         
          // [END data_model]
  
          // Solver
          // [START solver]
          // Create the linear solver with the CBC backend.
          MPSolver solver = new MPSolver(&quot;AssignmentMip&quot;, MPSolver.OptimizationProblemType.CBC_MIXED_INTEGER_PROGRAMMING);
          // [END solver]
  
          // Variables
          // [START variables]
          // x[i][j] is an array of 0-1 variables, which will be 1
          // if a game i is assigned to date j.
          MPVariable[][] match = new MPVariable[numGames][numDates];
          for (int i = 0; i &lt; numGames; ++i) {
              for (int j = 0; j &lt; numDates; ++j) {
                  match[i][j] = solver.makeIntVar(0, 1, &quot;&quot;);
              }
          }
  
          // [END variables]
  
          // Constraints
          // [START constraints]
          // Each game is assigned to at most one date.
          for (int i = 0; i &lt; numGames; ++i) {
              MPConstraint constraint = solver.makeConstraint(0, 1, &quot;&quot;);
              for (int j = 0; j &lt; numDates; ++j) {
                  constraint.setCoefficient(match[i][j], 1);
              }
          }
          // Each date is assigned to at most one game.
          for (int j = 0; j &lt; numDates; ++j) {
              MPConstraint constraint = solver.makeConstraint(0, 1, &quot;&quot;);
              for (int i = 0; i &lt; numGames; ++i) {
                  constraint.setCoefficient(match[i][j], 1);
              }
          }
          // Can only assign respecting adj matrix
          for (int i = 0; i &lt; numGames; ++i) {
              for (int j = 0; j &lt; numDates; ++j) {
                  MPConstraint constraint = solver.makeConstraint(0, adj[i][j], &quot;&quot;);
                  constraint.setCoefficient(match[i][j], 1);
              }
          }
  
          // Cannot assign team to consecutive dates
          for (int i = 0; i &lt; teamToGames.length; ++i) {
              for (int j = 0; j &lt; days.length - 1; ++j) {
                  if (weekDays[j] != 4) {
                      MPConstraint constraint = solver.makeConstraint(0, 1, &quot;&quot;);
                      for (int k = 0; k &lt; teamToGames[i].length; ++k) {
                          for (int l = 0; l &lt; days[j].length; ++l) {
                              constraint.setCoefficient(match[teamToGames[i][k]][l], 1);
                          }
                          for (int l = 0; l &lt; days[j+1].length; ++l) {
                              constraint.setCoefficient(match[teamToGames[i][k]][l], 1);
                          }
                      }
                  }
              }
          }
  
          // [END constraints]
  
          // Objective
          // [START objective]
          MPObjective objective = solver.objective();
          for (int i = 0; i &lt; numGames; ++i) {
              for (int j = 0; j &lt; numDates; ++j) {
                  objective.setCoefficient(match[i][j], 1);
              }
          }
  
          objective.setMaximization();
          // [END objective]
  
          // Solve
          // [START solve]
          MPSolver.ResultStatus resultStatus = solver.solve();
          // [END solve]
  
          // Print solution.
          // [START print_solution]
          // Check that the problem has a feasible solution.
          if (resultStatus == MPSolver.ResultStatus.OPTIMAL || resultStatus == MPSolver.ResultStatus.FEASIBLE) {
              System.out.println(&quot;Total matches: &quot; + objective.value() + &quot;\n&quot;);
              for (int i = 0; i &lt; numGames; ++i) {
                  for (int j = 0; j &lt; numDates; ++j) {
                      // Test if x[i][j] is 0 or 1 (with tolerance for floating point
                      // arithmetic).
                      if (match[i][j].solutionValue() &gt; 0.5) {
                          System.out.println(&quot;Game &quot; + i + &quot; assigned to date &quot; + j);
                      }
                  }
              }
          } else {
              System.err.println(&quot;No solution found.&quot;);
          }
          // [END print_solution]
      }
  
      // private GameMatching() {
      // }
  }
  // [END program]
  </code></pre>
  <p>EDIT
  This is the apparently working code. There is one last thing I need this to do. It is preferable to have two games on one same day (if other constraints allow) rather than one game in each of two separate days. My first thought was finding a way to constrain the games per day to either 0 or 2 (or more on a Sunday), but that may not always be possible. So any help on how I could do this will be appreciated.</p>
  <p>Thank you in advance.</p>