Update notebooks...
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "2bf9b567",
|
||||
"id": "18a3f79d",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"##### Copyright 2021 Google LLC."
|
||||
@@ -10,7 +10,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "7be013fd",
|
||||
"id": "7a932855",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Licensed under the Apache License, Version 2.0 (the \"License\");\n",
|
||||
@@ -28,7 +28,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "5557bcfd",
|
||||
"id": "55cdfccb",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# simple_max_flow_program"
|
||||
@@ -36,7 +36,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "8351f994",
|
||||
"id": "b2f3a9e5",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"<table align=\"left\">\n",
|
||||
@@ -51,7 +51,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "9db72a49",
|
||||
"id": "00ac5383",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"First, you must install [ortools](https://pypi.org/project/ortools/) package in this colab."
|
||||
@@ -60,7 +60,7 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "c56ffb9c",
|
||||
"id": "3d88e57a",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@@ -70,7 +70,7 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "4a75ec9d",
|
||||
"id": "8f0c4a47",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@@ -95,20 +95,21 @@
|
||||
"\n",
|
||||
"\n",
|
||||
"\"\"\"MaxFlow simple interface example.\"\"\"\n",
|
||||
"# [START solver]\n",
|
||||
"# Instantiate a SimpleMaxFlow solver.\n",
|
||||
"max_flow = pywrapgraph.SimpleMaxFlow()\n",
|
||||
"# [END solver]\n",
|
||||
"\n",
|
||||
"# [START data]\n",
|
||||
"# Define three parallel arrays: start_nodes, end_nodes, and the capacities\n",
|
||||
"# between each pair. For instance, the arc from node 0 to node 1 has a\n",
|
||||
"# capacity of 20.\n",
|
||||
"\n",
|
||||
"start_nodes = [0, 0, 0, 1, 1, 2, 2, 3, 3]\n",
|
||||
"end_nodes = [1, 2, 3, 2, 4, 3, 4, 2, 4]\n",
|
||||
"capacities = [20, 30, 10, 40, 30, 10, 20, 5, 20]\n",
|
||||
"# [END data]\n",
|
||||
"\n",
|
||||
"# Instantiate a SimpleMaxFlow solver.\n",
|
||||
"# [START constraints]\n",
|
||||
"max_flow = pywrapgraph.SimpleMaxFlow()\n",
|
||||
"# Add each arc.\n",
|
||||
"for arc in zip(start_nodes, end_nodes, capacities):\n",
|
||||
" max_flow.AddArcWithCapacity(arc[0], arc[1], arc[2])\n",
|
||||
@@ -116,19 +117,24 @@
|
||||
"\n",
|
||||
"# [START solve]\n",
|
||||
"# Find the maximum flow between node 0 and node 4.\n",
|
||||
"if max_flow.Solve(0, 4) == max_flow.OPTIMAL:\n",
|
||||
" print('Max flow:', max_flow.OptimalFlow())\n",
|
||||
" print('')\n",
|
||||
" print(' Arc Flow / Capacity')\n",
|
||||
" for i in range(max_flow.NumArcs()):\n",
|
||||
" print('%1s -> %1s %3s / %3s' %\n",
|
||||
" (max_flow.Tail(i), max_flow.Head(i), max_flow.Flow(i),\n",
|
||||
" max_flow.Capacity(i)))\n",
|
||||
" print('Source side min-cut:', max_flow.GetSourceSideMinCut())\n",
|
||||
" print('Sink side min-cut:', max_flow.GetSinkSideMinCut())\n",
|
||||
"else:\n",
|
||||
" print('There was an issue with the max flow input.')\n",
|
||||
"status = max_flow.Solve(0, 4)\n",
|
||||
"# [END solve]\n",
|
||||
"\n",
|
||||
"# [START print_solution]\n",
|
||||
"if status != max_flow.OPTIMAL:\n",
|
||||
" print('There was an issue with the max flow input.')\n",
|
||||
" print(f'Status: {status}')\n",
|
||||
" exit(1)\n",
|
||||
"print('Max flow:', max_flow.OptimalFlow())\n",
|
||||
"print('')\n",
|
||||
"print(' Arc Flow / Capacity')\n",
|
||||
"for i in range(max_flow.NumArcs()):\n",
|
||||
" print('%1s -> %1s %3s / %3s' %\n",
|
||||
" (max_flow.Tail(i), max_flow.Head(i), max_flow.Flow(i),\n",
|
||||
" max_flow.Capacity(i)))\n",
|
||||
"print('Source side min-cut:', max_flow.GetSourceSideMinCut())\n",
|
||||
"print('Sink side min-cut:', max_flow.GetSinkSideMinCut())\n",
|
||||
"# [END print_solution]\n",
|
||||
"\n"
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user