graph: Sync samples
This commit is contained in:
@@ -37,8 +37,9 @@ public class AssignmentMinFlow
|
||||
|
||||
int source = 0;
|
||||
int sink = 9;
|
||||
int tasks = 4;
|
||||
// Define an array of supplies at each node.
|
||||
int[] supplies = { 4, 0, 0, 0, 0, 0, 0, 0, 0, -4 };
|
||||
int[] supplies = { tasks, 0, 0, 0, 0, 0, 0, 0, 0, -tasks };
|
||||
// [END data]
|
||||
|
||||
// [START constraints]
|
||||
|
||||
@@ -42,8 +42,9 @@ public class AssignmentMinFlow {
|
||||
|
||||
int source = 0;
|
||||
int sink = 9;
|
||||
int tasks = 4;
|
||||
// Define an array of supplies at each node.
|
||||
int[] supplies = new int[] {4, 0, 0, 0, 0, 0, 0, 0, 0, -4};
|
||||
int[] supplies = new int[] {tasks, 0, 0, 0, 0, 0, 0, 0, 0, -tasks};
|
||||
// [END data]
|
||||
|
||||
// [START constraints]
|
||||
|
||||
@@ -44,8 +44,9 @@ public class BalanceMinFlow
|
||||
|
||||
int source = 0;
|
||||
int sink = 13;
|
||||
int tasks = 4;
|
||||
// Define an array of supplies at each node.
|
||||
int[] supplies = { 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -4 };
|
||||
int[] supplies = { tasks, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -tasks };
|
||||
// [END data]
|
||||
|
||||
// [START constraints]
|
||||
@@ -78,8 +79,8 @@ public class BalanceMinFlow
|
||||
for (int i = 0; i < minCostFlow.NumArcs(); ++i)
|
||||
{
|
||||
// Can ignore arcs leading out of source or into sink.
|
||||
if (minCostFlow.Tail(i) != 0 && minCostFlow.Tail(i) != 11 && minCostFlow.Tail(i) != 12 &&
|
||||
minCostFlow.Head(i) != 13)
|
||||
if (minCostFlow.Tail(i) != source && minCostFlow.Tail(i) != 11 && minCostFlow.Tail(i) != 12 &&
|
||||
minCostFlow.Head(i) != sink)
|
||||
{
|
||||
// Arcs in the solution have a flow value of 1. Their start and end nodes
|
||||
// give an assignment of worker to task.
|
||||
|
||||
@@ -42,6 +42,8 @@ public class BalanceMinFlow {
|
||||
int[] unitCosts = new int[] {0, 0, 0, 0, 0, 0, 0, 0, 90, 76, 75, 70, 35, 85, 55, 65, 125, 95,
|
||||
90, 105, 45, 110, 95, 115, 60, 105, 80, 75, 45, 65, 110, 95, 0, 0, 0, 0};
|
||||
|
||||
int source = 0;
|
||||
int sink = 13;
|
||||
int tasks = 4;
|
||||
// Define an array of supplies at each node.
|
||||
int[] supplies = new int[] {tasks, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -tasks};
|
||||
@@ -74,8 +76,8 @@ public class BalanceMinFlow {
|
||||
System.out.println();
|
||||
for (int i = 0; i < minCostFlow.getNumArcs(); ++i) {
|
||||
// Can ignore arcs leading out of source or intermediate nodes, or into sink.
|
||||
if (minCostFlow.getTail(i) != 0 && minCostFlow.getTail(i) != 11
|
||||
&& minCostFlow.getTail(i) != 12 && minCostFlow.getHead(i) != 13) {
|
||||
if (minCostFlow.getTail(i) != source && minCostFlow.getTail(i) != 11
|
||||
&& minCostFlow.getTail(i) != 12 && minCostFlow.getHead(i) != sink) {
|
||||
// Arcs in the solution have a flow value of 1. Their start and end nodes
|
||||
// give an assignment of worker to task.
|
||||
if (minCostFlow.getFlow(i) > 0) {
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
// limitations under the License.
|
||||
|
||||
// [START program]
|
||||
// From Bradley, Hax, and Maganti, 'Applied Mathematical Programming', figure 8.1.
|
||||
package com.google.ortools.graph.samples;
|
||||
// [START import]
|
||||
import com.google.ortools.Loader;
|
||||
|
||||
@@ -30,21 +30,21 @@ void AssignmentMinFlow() {
|
||||
// Define four parallel arrays: sources, destinations, capacities,
|
||||
// and unit costs between each pair. For instance, the arc from node 0
|
||||
// to node 1 has a capacity of 15.
|
||||
std::vector<int64_t> start_nodes = {0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
|
||||
3, 3, 3, 3, 4, 4, 4, 4, 5, 6, 7, 8};
|
||||
std::vector<int64_t> end_nodes = {1, 2, 3, 4, 5, 6, 7, 8, 5, 6, 7, 8,
|
||||
5, 6, 7, 8, 5, 6, 7, 8, 9, 9, 9, 9};
|
||||
std::vector<int64_t> capacities = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
|
||||
std::vector<int64_t> unit_costs = {0, 0, 0, 0, 90, 76, 75, 70,
|
||||
35, 85, 55, 65, 125, 95, 90, 105,
|
||||
45, 110, 95, 115, 0, 0, 0, 0};
|
||||
const std::vector<int64_t> start_nodes = {0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
|
||||
3, 3, 3, 3, 4, 4, 4, 4, 5, 6, 7, 8};
|
||||
const std::vector<int64_t> end_nodes = {1, 2, 3, 4, 5, 6, 7, 8, 5, 6, 7, 8,
|
||||
5, 6, 7, 8, 5, 6, 7, 8, 9, 9, 9, 9};
|
||||
const std::vector<int64_t> capacities = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
|
||||
const std::vector<int64_t> unit_costs = {0, 0, 0, 0, 90, 76, 75, 70,
|
||||
35, 85, 55, 65, 125, 95, 90, 105,
|
||||
45, 110, 95, 115, 0, 0, 0, 0};
|
||||
|
||||
int64_t source = 0;
|
||||
int64_t sink = 9;
|
||||
int64_t tasks = 4;
|
||||
const int64_t source = 0;
|
||||
const int64_t sink = 9;
|
||||
const int64_t tasks = 4;
|
||||
// Define an array of supplies at each node.
|
||||
std::vector<int64_t> supplies = {tasks, 0, 0, 0, 0, 0, 0, 0, 0, -tasks};
|
||||
const std::vector<int64_t> supplies = {tasks, 0, 0, 0, 0, 0, 0, 0, 0, -tasks};
|
||||
// [END data]
|
||||
|
||||
// [START constraints]
|
||||
|
||||
@@ -39,6 +39,7 @@ def main():
|
||||
[0, 0, 0, 0] +
|
||||
[90, 76, 75, 70, 35, 85, 55, 65, 125, 95, 90, 105, 45, 110, 95, 115] +
|
||||
[0, 0, 0, 0])
|
||||
|
||||
source = 0
|
||||
sink = 9
|
||||
tasks = 4
|
||||
|
||||
@@ -28,25 +28,29 @@ void BalanceMinFlow() {
|
||||
|
||||
// [START data]
|
||||
// Define the directed graph for the flow.
|
||||
std::vector<int64_t> team_A = {1, 3, 5};
|
||||
std::vector<int64_t> team_B = {2, 4, 6};
|
||||
const std::vector<int64_t> team_A = {1, 3, 5};
|
||||
const std::vector<int64_t> team_B = {2, 4, 6};
|
||||
|
||||
std::vector<int64_t> start_nodes = {
|
||||
const std::vector<int64_t> start_nodes = {
|
||||
0, 0, 11, 11, 11, 12, 12, 12, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3,
|
||||
3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 8, 9, 10};
|
||||
std::vector<int64_t> end_nodes = {11, 12, 1, 3, 5, 2, 4, 6, 7, 8, 9, 10,
|
||||
7, 8, 9, 10, 7, 8, 9, 10, 7, 8, 9, 10,
|
||||
7, 8, 9, 10, 7, 8, 9, 10, 13, 13, 13, 13};
|
||||
std::vector<int64_t> capacities = {2, 2, 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};
|
||||
std::vector<int64_t> unit_costs = {0, 0, 0, 0, 0, 0, 0, 0, 90,
|
||||
76, 75, 70, 35, 85, 55, 65, 125, 95,
|
||||
90, 105, 45, 110, 95, 115, 60, 105, 80,
|
||||
75, 45, 65, 110, 95, 0, 0, 0, 0};
|
||||
const std::vector<int64_t> end_nodes = {
|
||||
11, 12, 1, 3, 5, 2, 4, 6, 7, 8, 9, 10, 7, 8, 9, 10, 7, 8,
|
||||
9, 10, 7, 8, 9, 10, 7, 8, 9, 10, 7, 8, 9, 10, 13, 13, 13, 13};
|
||||
const std::vector<int64_t> capacities = {2, 2, 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};
|
||||
const std::vector<int64_t> unit_costs = {
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 90, 76, 75, 70,
|
||||
35, 85, 55, 65, 125, 95, 90, 105, 45, 110, 95, 115,
|
||||
60, 105, 80, 75, 45, 65, 110, 95, 0, 0, 0, 0};
|
||||
|
||||
const int64_t source = 0;
|
||||
const int64_t sink = 13;
|
||||
const int64_t tasks = 4;
|
||||
// Define an array of supplies at each node.
|
||||
std::vector<int64_t> supplies = {4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -4};
|
||||
const std::vector<int64_t> supplies = {tasks, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, -tasks};
|
||||
// [END data]
|
||||
|
||||
// [START constraints]
|
||||
@@ -75,8 +79,8 @@ void BalanceMinFlow() {
|
||||
for (std::size_t i = 0; i < min_cost_flow.NumArcs(); ++i) {
|
||||
// Can ignore arcs leading out of source or intermediate nodes, or into
|
||||
// sink.
|
||||
if (min_cost_flow.Tail(i) != 0 && min_cost_flow.Tail(i) != 11 &&
|
||||
min_cost_flow.Tail(i) != 12 && min_cost_flow.Head(i) != 13) {
|
||||
if (min_cost_flow.Tail(i) != source && min_cost_flow.Tail(i) != 11 &&
|
||||
min_cost_flow.Tail(i) != 12 && min_cost_flow.Head(i) != sink) {
|
||||
// Arcs in the solution have a flow value of 1. Their start and end
|
||||
// nodes give an assignment of worker to task.
|
||||
if (min_cost_flow.Flow(i) > 0) {
|
||||
|
||||
@@ -44,8 +44,11 @@ def main():
|
||||
105, 80, 75, 45, 65, 110, 95
|
||||
] + [0, 0, 0, 0])
|
||||
|
||||
source = 0
|
||||
sink = 13
|
||||
tasks = 4
|
||||
# Define an array of supplies at each node.
|
||||
supplies = [4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -4]
|
||||
supplies = [tasks, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -tasks]
|
||||
# [END data]
|
||||
|
||||
# [START constraints]
|
||||
@@ -72,10 +75,10 @@ def main():
|
||||
print()
|
||||
for arc in range(min_cost_flow.NumArcs()):
|
||||
# Can ignore arcs leading out of source or intermediate, or into sink.
|
||||
if (min_cost_flow.Tail(arc) != 0 and
|
||||
if (min_cost_flow.Tail(arc) != source and
|
||||
min_cost_flow.Tail(arc) != 11 and
|
||||
min_cost_flow.Tail(arc) != 12 and
|
||||
min_cost_flow.Head(arc) != 13):
|
||||
min_cost_flow.Head(arc) != sink):
|
||||
|
||||
# Arcs in the solution will have a flow value of 1.
|
||||
# There start and end nodes give an assignment of worker to task.
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
// limitations under the License.
|
||||
|
||||
// [START program]
|
||||
// From Bradley, H., and M., 'Applied Mathematical Programming', figure 8.1.
|
||||
// From Bradley, Hax and Maganti, 'Applied Mathematical Programming', figure 8.1
|
||||
// [START import]
|
||||
#include <cstdint>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user