@@ -0,0 +1,2665 @@
+// Copyright 2010-2021 Google LLC%0A// Licensed under the Apache License, Version 2.0 (the %22License%22);%0A// you may not use this file except in compliance with the License.%0A// You may obtain a copy of the License at%0A//%0A//     http://www.apache.org/licenses/LICENSE-2.0%0A//%0A// Unless required by applicable law or agreed to in writing, software%0A// distributed under the License is distributed on an %22AS IS%22 BASIS,%0A// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A// See the License for the specific language governing permissions and%0A// limitations under the License.%0A%0A// %5BSTART program%5D%0Apackage com.google.ortools.graph.samples;%0A// %5BSTART import%5D%0Aimport com.google.ortools.Loader;%0Aimport com.google.ortools.graph.MaxFlow;%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0A// %5BEND import%5D%0A%0A/** Minimal MaxFlow program.*/%0Apublic final class SimpleMaxFlowProgram %7B%0A  public static void main(String%5B%5D args) throws Exception %7B%0A    Loader.loadNativeLibraries();%0A    // %5BSTART solver%5D%0A    // Instantiate a SimpleMaxFlow solver.%0A    MaxFlow maxFlow = new MaxFlow();%0A    // %5BEND solver%5D%0A%0A    // %5BSTART data%5D%0A    // Define three parallel arrays: start_nodes, end_nodes, and the capacities%0A    // between each pair. For instance, the arc from node 0 to node 1 has a%0A    // capacity of 20.%0A    // From Taha's 'Introduction to Operations Research',%0A    // example 6.4-2.%0A    int%5B%5D startNodes = new int%5B%5D %7B0, 0, 0, 1, 1, 2, 2, 3, 3%7D;%0A    int%5B%5D endNodes = new int%5B%5D %7B1, 2, 3, 2, 4, 3, 4, 2, 4%7D;%0A    int%5B%5D capacities = new int%5B%5D %7B20, 30, 10, 40, 30, 10, 20, 5, 20%7D;%0A    // %5BEND data%5D%0A%0A    // %5BSTART constraints%5D%0A    // Add each arc.%0A    for (int i = 0; i %3C startNodes.length; ++i) %7B%0A      int arc = maxFlow.addArcWithCapacity(startNodes%5Bi%5D, endNodes%5Bi%5D, capacities%5Bi%5D);%0A      if (arc != i)%0A        throw new Exception(%22Internal error%22);%0A    %7D%0A    // %5BEND constraints%5D%0A%0A    // %5BSTART solve%5D%0A    // Find the maximum flow between node 0 and node 4.%0A    MaxFlow.Status status = maxFlow.solve(0, 4);%0A    // %5BEND solve%5D%0A%0A    // %5BSTART print_solution%5D%0A    if (status == MaxFlow.Status.OPTIMAL) %7B%0A      System.out.println(%22Max. flow: %22 + maxFlow.getOptimalFlow());%0A      System.out.println(%22%22);%0A      System.out.println(%22  Arc     Flow / Capacity%22);%0A      for (int i = 0; i %3C maxFlow.getNumArcs(); ++i) %7B%0A        System.out.println(maxFlow.getTail(i) + %22 -%3E %22 + maxFlow.getHead(i) + %22    %22%0A            + maxFlow.getFlow(i) + %22  /  %22 + maxFlow.getCapacity(i));%0A      %7D%0A    %7D else %7B%0A      System.out.println(%22Solving the max flow problem failed. Solver status: %22 + status);%0A    %7D%0A    // %5BEND print_solution%5D%0A  %7D%0A%0A  private SimpleMaxFlowProgram() %7B%7D%0A%7D%0A// %5BEND program%5D%0A

Add Java SimpleMaxFlow